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

Change object sprite based off of background sprite.

N

New_Blerg

Guest
I have two Objects, one is the Player Object and the other is the Background Object. If the players sprite turns blue or grey, I want the background Object to change its sprite to yellow or blue but only if the player is in front of or even touching the Background Object.

In the Players Collission Event with my Object Background this is what I have and it only changes once and stays.

////////////////////////////////////////////////////////////
with (obj_player)
if collision_point( x, y, obj_back_ground+(sprite_index = spr_background_0), false, true)
sprite_index = spr_player_3_red;

else with (obj_player)
if collision_point( x, y, obj_back_ground+(sprite_index = spr_back_ground_8), false, true)
sprite_index = spr_player;
////////////////////////////////////////////////////////////

Thank You for time :)
 

Zechevalier

Member
I'm not sure why you have the +(sprite_index = spr_back_ground_8) part in there. and also i would put the code in the step event, because otherwise what's the point of using the collision_point check?

But if I were to write the code I would use brackets, and the sprite index check would also be separate.

In the step event of the player object I would use this code:

Code:
var_background_object = instance_position(x,y,obj_back_ground)
to assign whatever background object you are currently touching to the var_background_object variable.

then I would have my collision checks and sprite_index checks look like this:

Code:
if var_background_object != noone{
    if var_background_object.sprite_index = spr_background_0{
        sprite_index = spr_player_3_red
    }
    if var_background_object.sprite_index = spr_background_8{
        sprite_index = spr_player
    }
}
}

Basically it first checks to see if the var_background_object variable is not equal to noone, which is asking if the code before it was able to find the object "obj_back_ground" at the players x and y position.

And if it is not equal to noone, then it just checks the sprite index of the "obj_back_ground" and sets the players sprite_index.

so the full code, if you want to copy and paste, would go into the players Step event:

Code:
var_background_object = instance_position(x,y,obj_back_ground)

if var_background_object != noone{
    if var_background_object.sprite_index = spr_background_0{
        sprite_index = spr_player_3_red
    }
    if var_background_object.sprite_index = spr_background_8{
        sprite_index = spr_player
    }
}
I did my best to explain based on what it seems like you are trying to do, I hope I am able to help.
 
N

New_Blerg

Guest
It Worked!!!!!! Thank you for all your help, I truly appreciate it.
 
Top