CCMoveTo不工作,节点/场景问题? [英] CCMoveTo not working, node/scene issue?

查看:183
本文介绍了CCMoveTo不工作,节点/场景问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为SuccessLayer的CCLayer类。当级别完成时,它被添加到场景,如下:

  SuccessLayer * successLayer = [SuccessLayer node]; 
[self addChild:successLayer];

在SuccessLayer中,我想要一个摇滚,我试图实现:

   - (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];}

> CCMoveTo 无法正常工作。我看到sprite坐在它的初始坐标,但没有更多。我在这里缺少什么?感谢

解决方案

通过将其转换为CCSprite来解决问题(是正确的说法吗?)

  CCSprite * asteroid = [Asteroid spriteWithFile:@rocks.png]; Asteroid 已经是CCSprite的子类,因此,所以我不知道为什么这个工作,但它允许我现在就对它运行的行动。


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

解决方案

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.

这篇关于CCMoveTo不工作,节点/场景问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆