> on layout change set float chaseDistance to distance(player.x,player.y,enemy.x.enemy.y)
> Every seconds if bool enemyNotSpawned = true subtract enemySpeed from chaseDistance
> if chaseDistance < 0 spawn Enemy
> This should work even with layout changes before the enemy spawned again.
> Or do you want to achive something like this:
> layoutA>layoutB>LayoutA Enemy is still in layoutA running to layoutB?
I studied this example and was able to make the enemy's appearance latency more realistic.
However, the problem of the enemy not staying in the same "room" when I exit and come back is still a headache. I guess I will look into arrays to see if I can find a solution for that. Thanks fedca for helping me out.
If anyone has suggestions for my latter problem, it'd be greatly appreciated.
Yes, you could use an array, especially if you use multiple enemy.
I can see it something like this:
Add a number to the layouts (ex: level_0_0, level_0_1, level_0_2...etc)
Calculate the width layout and store it in an array ( 3000,2500,3000...etc)
On the monster, I think there is a behavior where you can keep the variable as you change the layout. Add that behavior, and make a variable which store in which layout the monster is, same with the distance X player, and a logic global distance.
Now, the logic would be, if monster is on level 0_0 and you are on level 0_2, since you have the total width of the layout, and the last distance captured between the player and the monster, you can calculate the logic distance between the player and the enemy. If the player is in a greater number layout (you can compare it using actual layout name and monster layout using tokenat), you know if you need to add, or substract the distance. Then, knowing each width layout, you are able to understand where the enemy is. For example, while adding the number to the logic distance, if the enemy falls on 4000 distance, you know that is on level_0_1 and you can place the enemy as soon you get in that level in the exact place as soon the enemy was moving.
This would allow you to make a logic which says: if logic global distance is grater than 12000 (let's say, you pass 5 layouts), then stop the enemy. Knowing where the enemy is, and the global distance you can easily spawn the enemy when you get back to that layout. You can also store all of this in the array, where each enemy gets it's own row, or simply store it on the sprite instance. Array is helpful to save the progress and then load it easily.