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.
精彩评论