CCMoveTo not working, node/scene issue?

僤鯓⒐⒋嵵緔 提交于 2019-12-13 06:02:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!