문제

나는 내 스프리트를 움직 이려고 노력하고 있지만, 그것을 쓸지는 않습니다!메신저 cocos2d v2.1 베타 2 및 iOS6을 사용하여 스프라이트를 이동시키기 위해 사용한 코드입니다. 뭐가 잘못 됐어?

#import "CCTouchDispatcher.h"
 CCSprite *faceeater;

 -(id) init
 {

if( (self=[super init]) ) {
}


CCSprite* faceeater = [CCSprite spriteWithFile:@"fe.png"];
faceeater.position =  ccp( 200, 300 );
[self addChild:faceeater];
[self schedule:@selector(nextFrame:)];

[[CCDirector sharedDirector] touchDispatcher];

self.isTouchEnabled = YES;

  return self;

 }



 - (void) nextFrame:(ccTime)dt {
faceeater.position = ccp( faceeater.position.x + 100*dt, faceeater.position.y );
if (faceeater.position.x > 480+32) {
    faceeater.position = ccp( -32, faceeater.position.y );
}
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return YES;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertTouchToNodeSpace: touch];

[faceeater stopAllActions];
[faceeater runAction: [CCMoveTo actionWithDuration:1 position:location]];
 }
.

나는 스프라이트를 볼 수 있지만 움직이지 않는 것에 상관 없이는 아무리 움직이지 않습니다.고마워.

도움이 되었습니까?

해결책

변경 해야하는 것처럼

CCSprite* faceeater = [CCSprite spriteWithFile:@"fe.png"];
.

~

faceeater = [CCSprite spriteWithFile:@"fe.png"];
.

당신이 두 가지 다른 것처럼 보입니다. CCSPRITE * 여기에, init의 로컬 하나, 귀하의 구현에 정의 된 것. 여기서 하나 :

@implementation HelloWorldLayer
{
CCSprite* faceeater ;
}
.

다른 팁

는 다음 프레임 메소드가 실행 중입니까?중단 점으로 확인하십시오.

ctouchended는 실행됩니까?중단 점으로 확인하십시오.

다른 코드는 스프라이트의 위치를 설정합니까?프레임마다 CCMOVEXX 메소드를 실행하는 것입니까?

참고 : 다음 프레임에서 수동으로 위치를 업데이트하고 동시에 CCMoveTo 액션을 실행하면 결과가 예측할 수 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top