Scaling sprite velocity / co-ordinatesin Android

Posted by user22241 on Game Development See other posts from Game Development or by user22241
Published on 2012-10-24T23:16:58Z Indexed on 2012/10/25 5:21 UTC
Read the original article Hit count: 173

Filed under:
|
|
|
|

I'm trying to find the answer to a question that I've had for a long time, but am having trouble finding it! I hope someone can help :-)

I'm trying to find information on how to scale sprite velocity / movement / co-ordinates.

What I mean by this is how do I get a sprite to move at the same speed relative to the screen size / DPI so that it takes the same amount of real-time to get from one side of the screen to the other?

All of the posts pertaining to sprite scaling that I can find on the various forums relate to the size of the sprite, but this part of it I'm OK with so far, it's just that when I move a sprite, it kind of gets there at different speed depending on the dpi / resolution of the device. I hope I'm making sense.

This is the code I have so far, instead of using explicit amounts, like 1, I'm using something like the following:

platSpeedFloat= (1 * (dpi/160)); //Use '1' so on an MDPI screen, the sprite will move by 1 physical pixel

Then basically what I'm doing is something like this: (all varialble previously declared)

platSpeedSave+=platSpeedFloat; //Add the platSpeedFloat value to the current platSpeedSave value

platSpeed=(int) platSpeedSave; //Cast to int so it can be checked in the following statement

if (platSpeed==platSpeedSave) //Check the casted int value to float value stored previoiusly

{floorY=floorY-platSpeed; //If they match then change the Y value

platSpeedSave=0;} //Reset

Would be grateful if someone could assists - hope I'm making sense. The above doesn't seems to work the sprite moves 'faster' on lower DPI screens.

Thanks

© Game Development or respective owner

Related posts about android

Related posts about sprites