• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Player look at the top / move the camera

C

cidyuki

Guest
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:
C

cidyuki

Guest
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;
    }
}
 
C

cidyuki

Guest
I found a solution, it was simple.

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