Silverback Logo
Follow stssupport on Twitter
Silverback Technology Solutions

Constant speed using Cocos2D CCMoveTo action.

12/04/2011 Share/Bookmark

I've been tinkering with my latest game concept and I needed to move my enemy sprites to a given location.  To do this I thought the simplest way to achieve this was by using the the CCMoveTo action class.

Here's the code I used to start with;

[enemySprite runAction:[CCMoveTo actionWithDuration:2.0f  position:CGPointMake(size.width/2,size.height/2)]];

Now this works perfectly well, apart from the fact that the sprites further away move towards the target location at a greater speed, this is because each sprite performs the action over the same time frame (2 seconds) no matter where they appeared.

About Me

My photo
Software developer working on iPhone Apps and Games in spare time. Full time job is working with a corporate IT company supporting and developing various software installations.

© Silverback Technology Solutions