Limit the view?

Non-platform specific questions.

Limit the view?

Postby Hblade » Fri Sep 16, 2011 11:01 pm

How can I limit where the view can be? I know of a way but it doesn't work with Gag's view system he had for mario. I want to make the view stop at 4 points (Prettymuch creating a map). How can I do this?
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: Limit the view?

Postby skydereign » Fri Sep 16, 2011 11:20 pm

What I've done in the past is have variable boundaries (top left and bottom right pixels). In my set_level functions, I would set these to the proper values (though you can use placeholder type actors for that as well). Anyway, you can use this code to contain the view.
Code: Select all
view.x= min(right_x-view.width, max(left_x, view.x));
view.y= min(bot_y+view.height, max(top_y, view.y));

All this does is limit the view within the boundary. You probably have seen this code structure (min(max)), but if you don't understand it feel free to ask.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Limit the view?

Postby Hblade » Fri Sep 16, 2011 11:23 pm

Thank you very much sky! :)
And nah I dont really understand how that works because I never took the time to learn it but now that I see it, it might not be a bad idea.. Please explain ^^
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: Limit the view?

Postby skydereign » Fri Sep 16, 2011 11:34 pm

Well, as you know, min and max are ways of limiting a number. So if you wanted to prevent view.x from getting any lower than 0, you could use this.
Code: Select all
view.x=max(view.x, 0);

So the way of setting a lower bound is to use max, and the way to set the upper bound is to use min. So, preventing view.x from exceeding 100.
Code: Select all
view.x=min(view.x, 100);

This makes sense, as for the lower bound, you are defining a max value of 0, and for the upper bound, you define a max value of 100 (since it is min, it can't get larger than 100).

Now, to combine them, all you need to do is put on in the other. Since either the first one (using max), or the second one (using min), returns a single value, that can be used as the argument of the other (min/max).
Code: Select all
view.x=min(100, max(view.x, 0));

So, the max again will resolve to anything higher than 0, but that gets passed into min, so if it is higher than 100, then the view's x will be set to 100. So, all it does is limit both sides.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Limit the view?

Postby Hblade » Fri Sep 16, 2011 11:47 pm

Thank you so much, that information was incredibly useful! :)
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


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest