• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Intersect Boundary Event

V

Valerio

Guest
I create a sprite 2x2 pixel that moves up and down in a room.
I set the steps to 1 and the speed of the sprite to 1 pixel per step.
When the event Intersect Boundary occurs, the sprite invert the direction of movement.
The problem is this:
on the top side of the room, the sprite leaves the room of 1 pixel before reversing the direction (I think it's ok)
but on the down side of the room, the sprite leaves the room of 2 pixel before reversing the direction.

Why this difference ?
 
V

Valerio

Guest
Origin in the default position and Precise Collision Checking
 

johnwo

Member
I did some testing, and experienced the same issue.

Simply using:
Code:
if ((y <= 0) or (x <= 0)) or
  ((y + sprite_height >= room_height) or (x + sprite_width >= room_width)) then {
    // Change direction
}
Gave a better result.

The behaviour of "Intersect Boundary" looked more like this:
Code:
if ((y < 0) or (x < 0)) or
  ((y + sprite_height > room_height) or (x + sprite_width > room_width))
This code is just a rough example, but it should work with little to no modification, depending on object speed ect.
Rewriting it for bbox would be a good idea.

Cheers!
 
Top