Easy and efficient way to prevent from going off screen

Learn how to make certain types of games and use gameEditor.

Easy and efficient way to prevent from going off screen

Postby Hblade » Sat Jun 08, 2013 2:06 am

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby Grynde » Wed Jun 19, 2013 4:03 pm

Could you explain further please? For us that are a wee bit inexperienced?

Thanks in advance.
Playing a game is the voluntary attempt to overcome unnecessary obstacles.
-Bernard Suits
User avatar
Grynde
 
Posts: 21
Joined: Fri Apr 26, 2013 12:41 pm
Location: Virginia
Score: 1 Give a positive score

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

Postby Hblade » Thu Jun 20, 2013 2:10 am

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby lcl » Thu Jun 20, 2013 12:08 pm

Hblade, where you got that 16 from? O_o
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

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

Postby Hblade » Fri Jun 21, 2013 2:07 am

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)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby lcl » Fri Jun 21, 2013 6:14 am

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! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest