Legacy GM Locking camera so player cannot go back beyond border of screen

M

Matt93

Guest
I'm trying to create a camera which locks to the left side of my view, not allowing my player to go back past the border of the screen (just like Super Mario Land).

At the moment, my view is following my player, and I was just planning to put in the player step
Code:
if (x <= obj_camera.x) x = obj_camera.x
I don't know how to lock this to the edge of the view though. I've tried x = view_xview[0], but this moves with the view! I just want it to lock to the left edge of the screen. I feel like there must be a really simple solution to this which I'm overlooking. Cheers!
 
M

Matt93

Guest
Not a dumb question, I didn't explain very well. So I'm actually trying to work out a way of updating obj_camera's x position so it only sits at the left edge of my view. So it just acts as an invisible border which obj_player can't go behind. I originally tried updating its x value using the line
Code:
x = view_xview[0]
but of course this just will move with the view. I want it to lock on the left edge of my view, not allowing my view to move backwards. Does that make sense?
 

Alexx

Member
Can't you just check the player's x position against its limit?

I want it to lock on the left edge of my view, not allowing my view to move backwards. Does that make sense?
Just don't have any code to move the player left.

Perhaps a screenshot or diagram would provide more info.
 

Joe Ellis

Member
you need to make the view only move forwards if the player is past the right border
and not move left
and also in the player object's left button pressed area, add this check before moving left:

Code:
if player.x>view_xview[0]
{

}
so it will not walk left if its at the left edge
 

TheouAegis

Member
if global.scrolling view_xview[0] += 1;
if bbox_left < view_xview[0] { x = sprite_xoffset; hspeed = 0; }
if bbox_right > view_xview[0] + view_yview[0] { x = view_xview[0]+view_wview[0] - sprite_width + sprite_xoffset; hspeed = 0; }
 

ajan-ko

Member
so, you have to make camera object and player object.

Then, on your obj_player step event, put this code below

Code:
if (bbox_left < view_xview[0]) x+=hspeed  // or you can do the x+=10 //whatever you want, but make sure it's stay same with your horizontal speed attribute
if (obj_camera.x < x) obj_camera.x=x //moving the camera
On the map editor, put the obj_camera and make sure your view 0 following your obj_camera.

Viola...
 
Top