【发布时间】:2012-09-29 18:28:23
【问题描述】:
我一直试图让我的精神动起来,但它不会让步!我使用 cocos2d v2.1 beta 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]];
}
我可以看到精灵,但无论我做什么它都不会移动。谢谢。
【问题讨论】:
标签: cocos2d-iphone ios6