• 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!

How to calculate if a position is not inside view?

H

Holy Moly

Guest
I need to make enemies stay in their start position when out of view, and when their start point is not visible; so the player doesen't see enemies "magically" spawning in the same place every time they leave the screen. This is what I already have:

outside view 0 event:

Code:
if  (xstart < view_xview) || (ystart > view_yview) ||
 (xstart > view_xview + view_wview) ||
(ystart > view_yview + view_hview) {

x = xstart;
y = ystart;

}
For some reason, the enemy jumps to start, even when it's start position is inside of view. I need them to do this only if their start position is out of view, so it doesn't look strange...
 

jo-thijs

Member
This:
Code:
ystart > view_yview
should be:
Code:
ystart < view_yview
Also, this only checks if the starting position is outside the view, not if the entire sprite would be outside the view.
Not sure if you want that.
 
H

Holy Moly

Guest
Yay, thanks. It works now :D

At the beginning, I wanted to check for the position only... But now that you mention it, I think it would be better to jump to start when the entire sprite is out of view...
I don't know how to do that...
 

jo-thijs

Member
Well you can either use the bbox_* variables for this or the sprite_* variables.

Using the sprite variables:
Code:
if  (xstart - sprite_xoffset + sprite_width < view_xview
|| ystart - sprite_yoffset + sprite_height < view_yview
|| xstart - sprite_xoffset > view_xview + view_wview
|| ystart - sprite_yoffset > view_yview + view_hview) {
    x = xstart;
    y = ystart;
}
 

TheouAegis

Member
if view_xview+view_wview - bbox_right & $7FFFFFFFFFFFF > view_wview
|| view_yview+view_hview - bbox_bottom & $7FFFFFFFFFFFF > view_hview
{
x = xstart;
y = ystart;
}


Edit: used bbox_top on accident.
 
Last edited:

jo-thijs

Member
@TheouAegis, that doesn't sound as a safe code.
What if the y coordinate of the sprite origin is at the bottom of the sprite?
It would be lower than bbox_bottom.

Also, what really is the purpose of bbox_left and such in your code?
 

jo-thijs

Member
I do understand what you're doing with this one, but it's still not the safest code.
First of all, you seem to assume the instance will never go too far away from the top left corner of the view (which isn't too bad of an assumption).
You do make a serious mistake on this one though: you don't take bbox_left and bbox_bottom into account.
Your code assumes again that the instances are dots rather than rectangles.
 

TheouAegis

Member
Did you test my code?

Actually, i do see the issue on bbox_left. My test ran too fast i think. It looked like it worked. Should be an easy permissible tweak.
 
Last edited:

jo-thijs

Member
No, nor do I need to in this case.
You only provide 1 point of information of the player.
You've got nothing to specify how wide or high the instance is.
As a result, your code just cannot work with the instance as a rectangle,
which is required.

EDIT:
I can also put it like this:
An algorithm is requested that takes 8 arguments as input and gives 1 as output.
Your algorithm only takes 6 arguments though.
 
Last edited:
Top