Staying In The View

Lok_OS

Member
I have a camera that follows two players in a side-scrolling game, I have managed to set it up so that players can't just walk out of the view with no problems, by checking their x and movement speed compared to view_xview.
However, there is a dash button in the game which makes the players cover so much distance that they'll occasionally clip slightly out of the view when using it.
The code for the dash view checking essentially looks like this:

if (x + dashspd < view_xview[0])
{
x += dashspd;
}

dashspd in this case is 30.
So the question is, what's the best way to check for collision with a view when dealing with such big numbers? I used the same code when dealing with the normal walk speed and that seems to work fine.
I also tried using Boundary View "x = xprevious" but that makes the camera jitter when putting the player back to xprevious, I want to be able to smoothly stop against the view.
 

TheouAegis

Member
If x+30 is less than view_xview? Shouldn't it be <view_xview+view_wview?

Unless I'm misunderstanding your question, couldn't you just do x = clamp(x+dashspd, view_xview[0], view_xview[0]+view_wview[0]);? (Or use median() if you're using an older version of GM, it does the same thing as clamp.)
 

Lok_OS

Member
If x+30 is less than view_xview? Shouldn't it be <view_xview+view_wview?

Unless I'm misunderstanding your question, couldn't you just do x = clamp(x+dashspd, view_xview[0], view_xview[0]+view_wview[0]);? (Or use median() if you're using an older version of GM, it does the same thing as clamp.)
I tried with both "<view_xview" and "<view_xview+view_wview" in the past but it didn't seem to make any real difference on it's own.

However, the clamp code you gave paired with that seems to have more or less done the trick, very much appreciated! And apologies if I came off a bit vague.
 
Top