问题
I have a CCLayer class called SuccessLayer. It gets added to the scene when the level is complete, like so:
SuccessLayer *successLayer = [SuccessLayer node];
[self addChild:successLayer];
In SuccessLayer, I want to have a rock fly by, I'm trying to achieve that with this:
-(void)onEnter{
Asteroid *asteroid = [Asteroid spriteWithFile:@"rocks.png"];
asteroid.position = ccp(0, 500);
[self addChild:asteroid];
CCMoveTo *move = [CCMoveTo actionWithDuration:2.0 position:ccp(1000, 0)];
[asteroid runAction:move];}
However, it seems CCMoveTo
isn't working. I see the sprite sitting at its initial coordinates, but nothing more. What am I missing here? Thanks
回答1:
[super onEnter];
any coco's onSomething, you should super onSomething.
回答2:
Sovled the problem by casting it as a CCSprite (is that the correct way to say it?)
CCSprite *asteroid = [Asteroid spriteWithFile:@"rocks.png"];
Asteroid
is already a subclass of CCSprite, so I have no idea why this works, but it allows me to run actions on it now.
来源:https://stackoverflow.com/questions/14885055/ccmoveto-not-working-node-scene-issue