• 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!

Legacy GM [Solved] Swapping between foreground and background?

N

Nixio

Guest
Hello guys!

This is my first time posting here and I wanted to ask you for help.

I watched tutorial for advanced platformer from LewisClark and on the end of last episode he showed how he made swapping between foreground and background! I saw this few months ago and I really like it but because I am beginner (making some project for few months and learning) I have no idea how to make it..

It looks like he is swapping between two worlds where platforms are on different places so when you can not get to something in one world you will get to it on the other.

Any ideas how to make it?
Any help would be nice! Hope you guys replay!
 
M

maratae

Guest
One way could be making your collision code set to a variable that holds either one or other type of block, then whenever you trigger the passing from one type to another, the variable would change from one block object to another.
Exemple:
Code:
//Some trigger to swap blocks:
if (keyboard_check_pressed(vk_space))
{
    if (myBlock == obj_block_1)
    {
        myBlock = obj_block_2;
    }
    else
    {
        myBlock = obj_block_1;
    }
}

//Standard pixel-perfect collision check from tutorials;
//my point being to use the "myBlock" variable instead of the object name, regardless of collision code.
if (place_meeting(x,y+verticalSpeed,myBlock))
{
    while !place_meeting(x,y+sign(verticalSpeed),myBlock)
    {
        y += sign(verticalSpeed)
    }
    verticalSpeed = 0;
}

//Also the blocks can have themselves a check to change sprite depending on the player's block variable.
{
    if (instance_exists(obj_player))
    {
        if (obj_player.myBlock == obj_block_1)
        {
            sprite_index = spr_normal_block;
        }
        else
        {
            sprite_index = spr_innactive_block;
        }
    }
}

//And the block type 2 would have the opposite:
{
    if (instance_exists(obj_player))
    {
        if (obj_player.myBlock == obj_block_2)
        {
            sprite_index = spr_normal_block;
        }
        else
        {
            sprite_index = spr_innactive_block;
        }
    }
}
Note that if you're using tile based collisions, the solution would have to be different.
(Also, I'm sure someone else can do this with fewer lines of code.)

EDIT: You might as well make "myBlock" global instead, just in case..
 
Top