사용자가 CCButton을 배치해야하는 위치에 CCButton을 드래그 할 수있는 기능을 배치해야합니다.touchMoved 동안 CCButton이 작동하지 않습니다.
사용자 지정 클래스를 만들었지 만 문제는 click
입니다. 사용자가 단추를 클릭 할 때 단추의 메서드가 호출되지 않습니다.
#import "touchyButton.h"
@implementation touchyButton
- (void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
NSLog(@"touchMoved...", nil);
self.touchMoved = YES;
self.anchorPoint = ccp(0.5, 0.5);
CGPoint touchLoc = [touch locationInNode:self.parent];
//CGPoint inTouchLoc = [self convertToNodeSpace:self.anchorPoint];
//CGPoint touchP = ccpAdd(touchLoc, inTouchLoc);
//self.position = [self.parent convertToNodeSpace: touchP];
self.position = touchLoc;
}
- (void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
self.touchMoved = NO;
NSLog(@"touchEnded...", nil);
}
@end
코드의 설명에
touchyButton.m
#import "cocos2d.h"
#import "cocos2d-ui.h"
@interface touchyButton : CCButton { ... }
@property (nonatomic, assign) BOOL touchMoved;
@end
touchyButton.h
표시해야 할 주 코드에서 버튼을 호출하는 중입니다. 사용자가 버튼을 클릭 할 때
touchyButton *btnRight = [touchyButton buttonWithTitle: @"" spriteFrame:[[CCSprite spriteWithImageNamed: @"arrR.png"] spriteFrame]];
[btnRight setBackgroundOpacity:0.5f forState: CCControlStateNormal];
[btnRight setAnchorPoint: ccp(1, 0.5)];
[btnRight setPosition: ccp(viewS.width - 10.f, viewS.height/2)];
[self addChild: btnRight];
[btnRight setTarget:self selector: @selector(performRightJump:)];
이제 버튼이 선택된 상태로 진행하지만 performRightJump
결코 발사하지 않는다. 아무도 대안을 제안 할 수 어떻게 대상 작업을 작동 끌기와 함께 버튼을 구현할 수 있습니다 ..? 어떤 힌트도 감사 할 것입니다.
더 많은 것은 현재 코드에서 버튼의 앵커 포인트를 새 터치 포인트로만 이동할 수 있다는 것입니다. 어떤 방법으로 버튼을 실제 패션으로 옮길 수 있습니까? 현재의 방법은 이동을위한 처음 탭핑 문제를 야기하며, 버튼의 앵커 포인트는 탭 포인트로 점프한다. 당신
이를 ClassA와 ClassB가
이 코드를 추가하여 새로운 클래스를 생성하기위한
이 문제를 해결할 수 없으므로 질문을 종료해야합니다. –
문제를 해결할 수 없으며 개발을 떠났다. –