cocos 2dx getPosition(),始终返回初始位置而不是当前位置 [英] cocos 2dx getPosition() , always returns initial position instead of current position

查看:47
本文介绍了cocos 2dx getPosition(),始终返回初始位置而不是当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个精灵,它有一个动作,通过它,它会向右侧移动.

I have a sprite with having an action through which, it moves towards right side.

 CCSprite *spaceShip1=CCSprite::create("ufo_1.png");
 spaceShip1->setPosition(ccp(visibleSize.width/8,visibleSize.height/2));
 this->addChild(spaceShip1, 3);
 CCMoveBy* moveleft1 = CCMoveBy::create(3, ccp(visibleSize.width, 0));
 spaceShip1->runAction(moveleft1);

我想获取sprite的当前视觉位置,由于其由于runAction而移动,因此它应该返回其更新的位置.

I want to get the current visual position of sprite, as it is moving due to runAction, it should return its updated position.

我正在使用:

spaceShip1->getPosition();

这个位置在这里被利用:

and this position is utilizing here:

CCParticleSystemQuad* _spaceShip1 = new CCParticleSystemQuad();
_spaceShip1 = CCParticleSystemQuad::create("growingFlare.plist");
_spaceShip1->setPosition(spaceShip1->getPosition());
_spaceShip1->setAngle(180);
_spaceShip1->setScale(5);
_spaceShip1->stopSystem();
this->addChild(_spaceShip1, 4);

该粒子效应必须在宇宙飞船的当前位置发生,但始终在宇宙飞船的初始位置发生.

That particle effect must take place at the current position of spaceship, but it always took effect at initial position of spaceship.

我正在尝试获取子画面的当前位置.但它总是返回初始位置,而不是其当前移动位置.

I'm trying to get the current position of sprite. but it always returns the initial position instead of its current moving position.

要获得当前职位我该怎么做?

推荐答案

该粒子初始化发生在init()期间.那时动画不是实时的,因此将始终处于初始位置.

That particle initialization happens during init(). Animation is not live then, hence will always give initial position.

您有2个选择.

  1. 在您的更新方法中.每帧的粒子系统的SetPosition()到更新的太空飞船getPostion.
  2. 使粒子系统成为宇宙飞船的子代.如果是"this-> addChild()",请执行"_firstSpaceShip-> addChild(_particleSystem)",并给它一个初始的x位置(如-10),因此它始终跟在您的飞船后面.

这篇关于cocos 2dx getPosition(),始终返回初始位置而不是当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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