Login | Register

Zoom out

June 30, 2006, 00:22 by Calle
[loading]
-->
Yesterday Aquamarine, at GMC, and I worked out this solution. Aquamarine was the one who brought the question, and he also made the final corrections.

Zooming, out, in this case is not making the visible objects smaller, and in most game that is not a reasonable solution. What we do shall not affect the objects at all, that is not a good solution. We need to work on a method where we move “the eye”, in this case, the view.

If we widen the view we will get the wanted effect, and in a game like the one Aquamarine was doing, this is a pretty good solution. The game has two characters and both of them should be in view. We want a “border” around the view, so both characters can see a few steps forward.

But let’s start with the code for adapting the view width and height to the positions of the characters:

if (distance_to_object(obj_neutral)>320) {
view_wview[0] = distance_to_object(obj_neutral)+160;
view_hview[0] = distance_to_object(obj_neutral)+160;
}


160 is the border, it is divided on both sides, so the actual distance between a character and the border will be 80 pixels. But before this works we also need to focus the view. We cannot focus the view on either of the character, because that will place the other one outside the view. We need to centralise the view. To do this we create an object, which always stays in the middle of the two characters. So in step event of that newly created object, which the view shall follow, we put this:

x = (obj_player.x+obj_neutral.x)/2;
y = (obj_player.y+obj_neutral.y)/2;


Now the last thing that needs to be fixed, thanks Aquamarine for pointing this out, is that we need to set a limit where the view cannot grow anymore. Otherwise it will show grey areas outside the actual room. This is solved by this code, in step event:

if (view_wview[0] > room_width) {
view_wview[0] = room_width;
}

if (view_hview[0] > room_height) {
view_hview[0] = room_height;
}


If you have any questions regarding this tutorial, please ask them by commenting below. You are free to use this solution, but credit to this site is appreciated.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games