开发者

CCMoveBy in cocos2d-iphone

hello everyone i use CCMoveBy for keeping a sprite going

if (abs(dff.x) > abs(dff.y)) {
    id action = [CCMoveBy actionWithDuration:1 position:ccp(10,10)];
    [sprite runAction:[CCRepeatForever actionWithAction:action]];
}
else {
    id action = [CCMoveBy actionWithDuration:1 position:ccp(5,5)];
    [sprite runAction:[CCRepeatForever actionWithAction:action]];
}

if i push the sprite left/right,it will go to left/right,but now when i push it,it will go to the diagonal direction,not left or right or up or dow开发者_StackOverflow社区n,so what's the right is?thanks


Are you saying you want to just move on one axis? Then in that case you need to keep one of the values in ccp() at 0.


Move y: ccp(0, 10) // 10 points up y axis

Move x: ccp(10, 0) // 10 points right

And invert axis to - if you want to go opposite way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜