1
Axe / Re: can someone help me with my physics code?
« on: October 18, 2013, 03:57:49 pm »
Be careful with Pixeltests when you are using acceleration.
I think what happens here is the following:
imagine Y=55*256 + 255
your sprite is displayed with a one-pixel gap between the sprite and the ground line because Y/256=55.996 is truncated to 55 in Axe. The pixeltest returns false.
Now your acceleration is at 257 or more.
In the next loop Y=55*256 + 255 + 257 = 57*256
your sprite is displayed at Y/256 = 57 this is already on the ground line. The pixeltest which tests the row under your sprite returns false because the ball has already crossed the line. Now there is no way to stop your ball from falling further off the screen.
This can not only happen with the values I pointed out above but always if the acceleration is more than 256. The ball can skip certain pixel lines then and the same can be at the vertical walls.
There are three different solutions I can imagine:
A: Draw multiple lines on the ground (I wouldn't do that because the ball may kind of sink into the bottom lines and stay there
B: Keep the acceleration under 256 (this shouldn't be a problem )
C: Don't use pixeltest but check if the ball is lower then the last line (somthing like Y/256>55 be careful then with the negative Y when the ball goes offscreen at the top then you may use Y/256>>55)
In my opinion version C is the best because I think it's the most clean and the fastest solution
I think what happens here is the following:
imagine Y=55*256 + 255
your sprite is displayed with a one-pixel gap between the sprite and the ground line because Y/256=55.996 is truncated to 55 in Axe. The pixeltest returns false.
Now your acceleration is at 257 or more.
In the next loop Y=55*256 + 255 + 257 = 57*256
your sprite is displayed at Y/256 = 57 this is already on the ground line. The pixeltest which tests the row under your sprite returns false because the ball has already crossed the line. Now there is no way to stop your ball from falling further off the screen.
This can not only happen with the values I pointed out above but always if the acceleration is more than 256. The ball can skip certain pixel lines then and the same can be at the vertical walls.
There are three different solutions I can imagine:
A: Draw multiple lines on the ground (I wouldn't do that because the ball may kind of sink into the bottom lines and stay there
B: Keep the acceleration under 256 (this shouldn't be a problem )
C: Don't use pixeltest but check if the ball is lower then the last line (somthing like Y/256>55 be careful then with the negative Y when the ball goes offscreen at the top then you may use Y/256>>55)
In my opinion version C is the best because I think it's the most clean and the fastest solution