SOLVED Player look at the top / move the camera

cidyuki

Member
I am a novice with GameMaker.
I search to coding a smooth moving of the camera, to represent the view of the player.
When the player press "up" the camera move to top until a limit.
When he release "up" the camera comeback to initial position.

On the code that I wrote the while condition crash the game.

GML:
// look at the top
if (keyboard_check(vk_up))
{
    while(oPlayerView.y < oPlayer.y + 200)
    {
        oPlayerView.y -= 2;
    }
}
else
{
    while(oPlayerView.y == oPlayer.y)
    {
        oPlayerView.y += 2 ;
    }
}
On this code oPlayerView is the object link to my following object on the room's window.
oPlayer is the object for the player.
And 200 is the limit.

Do my while condition is right ?
 

NightFrost

Member
Oops, disregard, I noticed the objects have different names.

What are the starting values of oPlayerView.y and oPlayer.y? When you press arrow up and oPlayerView.y is already less than oPlayer.y + 200, the loop will never exit because 2 is subtracted every pass. On the other hand, if it is greater, the loop will never run.
 
Last edited:

cidyuki

Member
Thanks for your help.
the loop will never exit because 2 is subtracted every pass. On the other hand, if it is greater, the loop will never run.
Yes it is exactly that happening.

On my room oPlayer.y = 611
And on oPlayer create event, I wrote this :
oPlayerView.y = oPlayer.y;

I rewrite the code like following. Now the limit working but there don't have camera travelling. The camera go directly at the limit.

GML:
if (press_up){
    while(oPlayerView.y > (oPlayer.y - 200))
    {
        oPlayerView.y -= 1;
    }
}
 

cidyuki

Member
I found a solution, it was simple.

GML:
if ((press_up)) && ( oPlayerView.y > (oPlayer.y - 100)){
    oPlayerView.y -= 2;
}
 
Top