Keeping Character at Correct Depth While Changing Rooms

A

A. DeVivo

Guest
Howdy,

Probably has a simple solution but I can't seem to find it- I generally put my character in a layer below foreground objects to allow for a feeling of depth, but now that I have several rooms that doesn't work after the player has changed rooms because
a) if there is already a player object in the room then both that object and the object entering the room appears, creating two player objects
b) if I delete the player object from the correct layer the player then appears in the room and is automatically placed above all other objects, and therefore just runs over the images that should hide them.

What's to be done here? I'm missing something big, and simple I'm sure. Thank you!
 

Phil Strahl

Member
Sounds like you should make sure first that only one player object exists in all the rooms. Have you set your player object to be persistent? That's how I would go about it. Upon changing rooms, you just need to make sure that the player instance ends up at the right coordinates then, but it should stay on the correct layer. If not, you could create a new player instance on the appropriate layer, transfer all important properies to the new instance and destroy the old one, e.g. like this
Code:
// assuming this code rons from the current player instance
var new_player = instance_create_depth(x, y, "Player Layer") // with your appropriate variables, of course 
new_player.depth = depth
new_player.hitpoints = hitpoints
// etc.
You could also use a with block for the transfer, of course, e.g.
Code:
with (new_player)
{
  depth = other.depth
  hitpoints = other.hitpoints
  // etc.
}
 
A

A. DeVivo

Guest
alright! thanks! where do I put that code? In the player object Step code?
 
A

A. DeVivo

Guest
Sounds like you should make sure first that only one player object exists in all the rooms. Have you set your player object to be persistent? That's how I would go about it. Upon changing rooms, you just need to make sure that the player instance ends up at the right coordinates then, but it should stay on the correct layer. If not, you could create a new player instance on the appropriate layer, transfer all important properies to the new instance and destroy the old one, e.g. like this
Code:
// assuming this code rons from the current player instance
var new_player = instance_create_depth(x, y, "Player Layer") // with your appropriate variables, of course
new_player.depth = depth
new_player.hitpoints = hitpoints
// etc.
You could also use a with block for the transfer, of course, e.g.
Code:
with (new_player)
{
  depth = other.depth
  hitpoints = other.hitpoints
  // etc.
}
should I put it in the code for the player object?
 

Phil Strahl

Member
should I put it in the code for the player object?
Ideally you have some kind of manager object that keeps track of the game state that is responsible to check if all the necessary instances exists in a room when running it and/or keeps track of the rules, lives, score, etc. That's where I put this code.
 
Top