Bloodbane
Well-known member
I have a trick to share here, I use this oftenly when placing obstacles in levels.
Level Spawn Shifting Trick
Intro: Entities could be spawned in levels anywhere as the modder preferred. However some entities such as decoration and obstacles must be spawned in specific coordinates and scrollpos to match background or to prevent them from being spawned at wrong place when the scrollpos is reached.
This trick will show how to shift spawn coordinate and scrollpos without moving those-to-be-spawned entities from their correct place
Procedure: The trick is different in direction left and right levels.
A. Direction Right
Say, a painting decoration is correctly spawned with this:
If this is run in game, Painting will pop in out of nowhere when scrollpos 2000 is reached since it is spawned onscreen. That is not good (well unless the modder doesn't care
). To prevent that, Painting must be spawned earlier however shifting scrollpos is not enough, coords must be adjusted as well.
To shift it properly, 1st decide the proper x coords for Painting so it is spawned offscreen.
Let's say, 60 pixels offscreen is minimum distance from right screen edge. So in 320x240 resolution, Painting must be spawned with x coords = 320+60 = 380
2nd, calculate the new scrollpos with this logic: Sum of scrollpos and x is same before and after shifting.
Old scrollpos + old x = new x + new scrollpos
2000 + 160 = 380 + new scrollpos
new scrollpos = 2160 - 380 = 1780
So, the new spawn should be like this:
With this, Painting will be spawned earlier and it will retain it's correct position
B. Direction left
Let's say, a table is correctly spawned with this:
In game, at scrollpos 1400, Table will pop in around middle of playing field and it might accidentally block moving player or enemy nearby IOW not good!.
To shift it, 1st decide proper x coords for Table so it's spawned offscreen. Let's say, it should be at least 40 pixels from left screen edge. So Table must be spawned with x coords = -40 (resolution doesn't matter)
2nd, calculate the new scrollpos with this logic: Shifting distance of x is same with shifting distance of scrollpos
new x - old x = new scrollpos - Old scrollpos
-40 - 200 = new scrollpos - 1400
new scrollpos = 1400 - 240 = 1160
So, the new spawn should be like this:
Table will be spawned earlier and will be at same place as designed before
Extra: Both examples show how to shift decoration and obstacle spawn offscreen. Actually, this trick can also be used to set up scrollpos-controlled enemy generator properly in game. However, that won't be described here
.
Level Spawn Shifting Trick
Intro: Entities could be spawned in levels anywhere as the modder preferred. However some entities such as decoration and obstacles must be spawned in specific coordinates and scrollpos to match background or to prevent them from being spawned at wrong place when the scrollpos is reached.
This trick will show how to shift spawn coordinate and scrollpos without moving those-to-be-spawned entities from their correct place
Procedure: The trick is different in direction left and right levels.
A. Direction Right
Say, a painting decoration is correctly spawned with this:
spawn Painting
coords 160 145
at 2000
If this is run in game, Painting will pop in out of nowhere when scrollpos 2000 is reached since it is spawned onscreen. That is not good (well unless the modder doesn't care
To shift it properly, 1st decide the proper x coords for Painting so it is spawned offscreen.
Let's say, 60 pixels offscreen is minimum distance from right screen edge. So in 320x240 resolution, Painting must be spawned with x coords = 320+60 = 380
2nd, calculate the new scrollpos with this logic: Sum of scrollpos and x is same before and after shifting.
Old scrollpos + old x = new x + new scrollpos
2000 + 160 = 380 + new scrollpos
new scrollpos = 2160 - 380 = 1780
So, the new spawn should be like this:
spawn Painting
coords 380 145
at 1780
With this, Painting will be spawned earlier and it will retain it's correct position
B. Direction left
Let's say, a table is correctly spawned with this:
spawn Table
coords 200 200
at 1400
In game, at scrollpos 1400, Table will pop in around middle of playing field and it might accidentally block moving player or enemy nearby IOW not good!.
To shift it, 1st decide proper x coords for Table so it's spawned offscreen. Let's say, it should be at least 40 pixels from left screen edge. So Table must be spawned with x coords = -40 (resolution doesn't matter)
2nd, calculate the new scrollpos with this logic: Shifting distance of x is same with shifting distance of scrollpos
new x - old x = new scrollpos - Old scrollpos
-40 - 200 = new scrollpos - 1400
new scrollpos = 1400 - 240 = 1160
So, the new spawn should be like this:
spawn Table
coords -40 200
at 1160
Table will be spawned earlier and will be at same place as designed before
Extra: Both examples show how to shift decoration and obstacle spawn offscreen. Actually, this trick can also be used to set up scrollpos-controlled enemy generator properly in game. However, that won't be described here