Page 1 of 1

Easy and efficient way to prevent from going off screen

PostPosted: Sat Jun 08, 2013 2:06 am
by Hblade
Code: Select all
xscreen=min(max(xscreen, 16), view.width-16);
yscreen=min(max(yscreen, 16), view.height-16);


Put this in draw actor :) problem solved, now you wont go off screen :D

Re: Easy and efficient way to prevent from going off screen

PostPosted: Wed Jun 19, 2013 4:03 pm
by Grynde
Could you explain further please? For us that are a wee bit inexperienced?

Thanks in advance.

Re: Easy and efficient way to prevent from going off screen

PostPosted: Thu Jun 20, 2013 2:10 am
by Hblade
Long story short, this makes it so what ever object you put it in (Draw actor, rather it be player, or something else), it makes it so it can't leave the view :) Like, it's always on screen o3o

Re: Easy and efficient way to prevent from going off screen

PostPosted: Thu Jun 20, 2013 12:08 pm
by lcl
Hblade, where you got that 16 from? O_o

Re: Easy and efficient way to prevent from going off screen

PostPosted: Fri Jun 21, 2013 2:07 am
by Hblade
The 16 makes it so it still shows some of the character a little as well (this code was coppied from a little rpg system thingie I was making)

Re: Easy and efficient way to prevent from going off screen

PostPosted: Fri Jun 21, 2013 6:14 am
by lcl
Well, I did understand what it does, but I'm just wondering why not use the actor's width and height and have some multiplier, like ⅓ (0.3333). This way all the actors would have the same limitations in relation to their size. Now some very small won't even get to the edge of the screen, while bigger actors can have almost half of them off screen. So, by finding a nice multiplier and by multiplying the actors width and height with it, one would be able to make it act the same way for all sizes of actors. :D Or you could make it a function and give it a parameter for changing that limit.

But anyway, pretty nice little code you have here! :)