Gionne Lapuz Gionne Lapuz -3 years ago 222
Android Question

Checking if two objects have the same y-axis

I have been creating a simple android game, but have been encountering some problems in checking if an object falling down has passed another object on the y-axis.

This is my code:

//SKULLY is the object falling down
//USER is the object that SKULLY will have to pass through to add a point

public void checkPassed()
if (skullY == user.getY())
txtScore.setText("SCORE: " + String.valueOf(scoreCount));

What I am trying to do is that, when SKULLY passes through or is equal to the y-axis of the USER then it will add a single point.

When I change the condition to > or < it works perfectly fine no matter what position USER is in. But when I put it in ==== no point is added.

If you have to downvote me, please leave a comment on why was I downvoted. Thanks in advance for any help or insight on this problem! :D

Answer Source

since its sound like a Game equals ("==") almost never happens.. my Suggestion is

if(skullY < user.getY() && skullY > user.getY() + 10) {
   // Do Stuff here.. 


try to lower 10 as much as possible until you will get the desire result..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download