Cocos2Dスプライトは移動しませんか?
-
11-12-2019 - |
質問
私は私のスプリットを動くようにしようとしていましたが、それは繁栄しませんでした!Cocos2D v2.1ベータ2とiOS6を使用しているIMこれは私が私のスプライトを動かすために使用してきたコードです、それは何が間違っていますか?
#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"];
.
2つの異なるものがあるように見えます CCSprite *フェイスファイヤーここでは、initのローカルワン、 そしてあなたの実装で定義されています。 ここに1つ:
@implementation HelloWorldLayer
{
CCSprite* faceeater ;
}
. 他のヒント
NextFrameメソッドの実行は実行されていますか?ブレークポイントで確認してください。
cctouchendendを実行しますか?ブレークポイントで確認してください。
他のコードはスプライトの位置を設定しますか?毎回CCMoveXXメソッドを実行していますか?
注:NEXTFRAMEで手動で位置を更新し、CCMoveToアクションを同時に実行すると、結果は予測不可能です。
所属していません StackOverflow