Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Talk:Developing a 2D game in Java ME - Part 3

From Wiki
Jump to: navigation, search

Featured article, August 24th 2008 (week 35)


Anum Amin - Why need to track old Position?

Can someone tell me why we need to keep track of old position of the Entity? OldX and OldY have been used in Collision detection. Can anyone explain me these lines:

// check if collision resulted from x movement

if ((this.x < (other.x + other.width)) &&

         (this.x + width > other.x) &&
         (this.oldY < (other.y + other.height)) && 
         (this.oldY + height > other.y)
        )
     {
       if (oldX < x) {
         collision |= COLLISION_RIGHT;
       } else {
         collision |= COLLISION_LEFT;
       }
     }
Sorry if it is lame Question... I am going to develop game for first time... Thanks.

Anum Amin 11:53, 21 August 2012 (EEST)

Hamishwillee - Probably best to ask on forums

This article is 4 years old and the author might not be watching it any more, so best to ask on the forums. Without looking deeply, I suspect that if you have two moving objects the collision will occur at some point between the current and last position. If you just calculate the current position, you might miss a collision that already occured between frames.

 

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×