S
Storm1208
Guest
Hey All! I'm currently working on a recreation of the popular platformer "VVVVVV" and started using the view system in GameMaker to make small, 640x480 levels in my project. These levels are all contained within one room, and when the player walks far enough out of one view it switches to another to go to the next "level".
Here's the code I typed up to test out this system:
The system was working perfectly until I noticed a small bug. For some reason, if my player object encounters a corner (i.e. they are standing on the ground and also colliding with a "wall" in front of them) the view switching no longer works. I've been able to recreate the bug consistently and here's some pictures of my player encountering corners for reference:
After the player collides with the floor and wall in a way like shown in the images, the views will no longer switch to show you which levels you're in. I concluded that this must have had something to do with how my collision code was affecting my player's x or y values but I can't seem to spot anything wrong with them.
Horizontal Collision:
Vertical Collision:
I used the "show_debug_message()" code to track my player's x value and everything seems normal even after contacting the corner. I'm not entirely sure what's causing the bug but I appreciate any and all help anyone can give me!
Here's the code I typed up to test out this system:
Code:
if((obj_player.x = room_width/2))/*one level is 640x480 and room is 1280x960,
so the player being at half the width of the room means it's time to "switch levels"*/
{
if(view_visible[0])
{
view_visible[0] = false;//turning off camera for first level
view_visible[1] = true;//turning on camera for second level
obj_titlecards.image_index = 1;//showing level name
}
else if(view_visible[1])//vice versa if going from level 1 to 0
{
view_visible[1] = false;
view_visible[0] = true;
obj_titlecards.image_index = 0;
}
}
After the player collides with the floor and wall in a way like shown in the images, the views will no longer switch to show you which levels you're in. I concluded that this must have had something to do with how my collision code was affecting my player's x or y values but I can't seem to spot anything wrong with them.
Horizontal Collision:
Code:
//Horizontal Collision
if(place_meeting(x+hsp,y,obj_ground)) //if we're about to collide with a ground tile
{
while(!place_meeting(x+sign(hsp),y,obj_ground))//keep moving until...
{
x += sign(hsp);
}
hsp = 0; //BAM - stop moving
}
x += hsp;
Code:
//Vertical Collision
if(place_meeting(x,y+vsp,obj_ground)) //if we're about to collide with a ground tile
{
while(!place_meeting(x,y+sign(vsp),obj_ground))//keep moving until...
{
y += sign(vsp);
}
vsp = 0; //BAM - stop moving
flip = 1;
}
y += vsp;
if(vsp != 0)
{
flip = 0;
}