You can't change position components like x
and y
directly. You have to set a new position instead, by assigning a CGPoint
to the position property. Something like this:
[player setPosition:ccp( acceleration.x * 10, player.position.y )];
If you want to move the sprite constantly in the direcion of acceleration, you should increment the x
value instead.. something like this:
[player setPosition:
ccp( player.position.x + acceleration.x * 10, player.position.y )];
Technical background: You have to use setPosition
or position = ccp(xValue, yValue)
, because Cocos2D keeps a flag internally that indicates if the position has changed and if the sprite should be moved. Setting components like x
or y
directly won't do anything, because the flag only changes when you invoke the position
setter.