Android Cocos2d移动到操作
我对Cocos2D和Java一无所知,所以请原谅我的无知,但我非常渴望学习 通过学习,我正在创建一个简单的应用程序,它显示一组图像(存储在一个数组中),然后让它们全部移动到一个触摸位置 我不能完全理解actions和MoveTo,因为在下面的For循环中,只有数组中的最后一个图像移动Android Cocos2d移动到操作,android,cocos2d-iphone,Android,Cocos2d Iphone,我对Cocos2D和Java一无所知,所以请原谅我的无知,但我非常渴望学习 通过学习,我正在创建一个简单的应用程序,它显示一组图像(存储在一个数组中),然后让它们全部移动到一个触摸位置 我不能完全理解actions和MoveTo,因为在下面的For循环中,只有数组中的最后一个图像移动 public boolean ccTouchesMoved(MotionEvent e){ CGPoint touchLocation = CCDirector.sharedDirector().conve
public boolean ccTouchesMoved(MotionEvent e){
CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(e.getX(), e.getY()));
CCMoveTo imgMove = CCMoveTo.action(2f, touchLocation);
for (int i = 0; i < imgs.length; ++i){
imgs[i].runAction(imgMove);
};
return true;
};
我想我需要添加一些动作结束命令?我也不明白为什么数组中只有最后一个图像移动而其余的图像不移动。当调用
runAction
方法时,要设置动画的对象的引用存储在action对象中,因此如果在每次迭代中运行相同的action对象,则只有最后一个图像将保持存储状态
要解决此问题,只需为阵列中的每个图像创建CCMoveTo
操作。另外,++i
在第一次迭代中使用变量之前,先递增变量i
,因此跳过数组的第一个元素
代码如下所示-
public boolean ccTouchesMoved(MotionEvent e){
CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(e.getX(), e.getY()));
for (int i = 0; i < imgs.length; i++){
CCMoveTo imgMove = CCMoveTo.action(2f, touchLocation);
imgs[i].runAction(imgMove);
};
return true;
};
public boolean ccTouchesMoved(运动事件e){
CGPoint touchLocation=CCDirector.sharedDirector().convertToGL(CGPoint.ccp(e.getX(),e.getY());
对于(int i=0;i
顺便说一句,我相信android的cocos2d已经不再处于开发阶段,如果您正在学习,我建议您选择或。谢谢,这么简单的修复!我不知道Cocos2D已经不再是Android的开发产品了,但这也解释了为什么很难找到指南(我一直在尝试遵循iOS Cocos2D的指南)。很高兴它起到了作用:)我想如果你不尝试任何“与众不同”的东西,你会对Cocos2D Android感到满意,但你可能会错过一些更高级的东西。无论如何,祝你好运!
public boolean ccTouchesMoved(MotionEvent e){
CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(e.getX(), e.getY()));
for (int i = 0; i < imgs.length; i++){
CCMoveTo imgMove = CCMoveTo.action(2f, touchLocation);
imgs[i].runAction(imgMove);
};
return true;
};