invisible squirrel
invisible squirrel

Reputation: 3008

Cocos2d: Why double-speed on retina display?

In the update method: of a layer, I'm moving a plane like this:

-(void) update:(ccTime)delta
{
    ...

    pos.x += vVelocity.x;
    pos.y += vVelocity.y;
    plane.position = pos;
}

Testing as a universal app on iPad it works as expected but when I test on the iPhone 4 the plane moves twice as fast! I am using a -hd image for the retina display version. Am I missing something or must I half the velocity in the above code when the retina display is used?

Upvotes: 0

Views: 475

Answers (2)

Felix
Felix

Reputation: 35384

I couldn't reproduce this behaviour. You should multiply the velocity (given in points per second) by delta. This behaves as it should (tested in iOS simulator with and without retina display):

-(void) update:(ccTime)delta
{
    // ...
    CGPoint pos = plane.position;
    pos.x += vVelocity.x*delta;
    pos.y += vVelocity.y*delta;
    plane.position = pos;
}

Upvotes: 1

Graham Perks
Graham Perks

Reputation: 23390

Cocos2d uses points to measure, so treat screen positions as 480x320 even with retina. It sounds like vVelocity is being based off pixels, so it's double what it should be. The bug is where velocity is being calculated. See http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2d for more information.

Upvotes: 1

Related Questions