Spawning Enemies in Platformer Style with Vertical Background without Lagging Gameplay

maxman

Well-known member
In the past, I had created a platformer level which you could spawn enemies without requiring groups, but with a calculation of scrollpos (at) and x coords of enemies to spawn outside of the screen, for them to appear exactly like a platformer without lagging speed. Thanks to @Bloodbane, I got better with the platforming method using math. However, I feel like this is different because of the level's height size I'm using for jumping/moving up until you reach its peak. Also, I keep using at 0 when I spawn many entities without grouping because I worry if I scroll left and right while using direction both and moving up, the performance lags the gameplay experience especially those specific entities that perform actions with given sounds, such as repetitive shooting, looping traps with sounds, etc. I have to use a non-moving animation as a follow animation and place them in a specific position with "position" property to change. For example, you start with a non-moving enemy until you get close to him and a(n) none/enemy/trap-type entity that is far away from and way above the two, but it's actively playing its sound (because it's not grouped in the level).

Code:
spawn    Respawn
@script
void main()
{
    void P1 = getplayerproperty(0, "entity");

    changeopenborvariant("xpos", 580);
    changeopenborvariant("ypos", 2000);
    changeentityproperty(P1,"position", 740, NULL(), 1);
    changeentityproperty(P1,"direction", 0);
}
@end_script
coords 740 2137 1 #740-160=580
flip 1
at 0

spawn trap1
coords 400 2137 500
at 0

spawn trap2
@script
void main(){
void self = getlocalvar("self");
performattack(self, openborconstant("ANI_FOLLOW3"));
changeentityproperty(self, "position", 360, 2137, 800);
}
@end_script
coords 200 2137 800
at 0

spawn enemy1
coords 330 2137 #330-160=170
at 0

I put non-enemies first in the line before I put enemies.

I can use "position" property to set their locations and give follow animations as non-moving motions. But how can I avoid this lag when I have many entities spawned with at 0 (or any value higher than 0) and without grouping on certain altitude positions in one go to look very seamless like the Mega Drive (Genesis) version of X-Men?
 
Last edited:
hey there my inglish is not very good so i am not sure i understand what is you are asking... but i have worked with similar levels and would like to be of help if i can...
if i understand correctly you want to spawn everything from the start but at the same time prevent he lag that cause that many entities been present at the same time?
 
@maxman, platformers do not instantiate every active enemy and trap when the level starts. That's just bad engineering.

What they do is keep a lightweight table of spawn definitions. When the player or camera gets within a chosen distance - commonly one or two screen lengths - the engine creates the entity. When the player moves sufficiently far away, the entity is removed or suspended.

The table also records what happened to each spawn:
  • Never spawned.
  • Currently active.
  • Defeated permanently.
  • Removed because it went out of range and may be spawned again.
Some games intentionally omit the defeated state. The NES Ninja Gaiden games are infamous for doing that, which is why enemies can respawn repeatedly whenever their spawn point leaves and re-enters the activation area.

at 0, different coordinates, and a stationary animation cannot provide this behavior. They merely create the entities immediately and leave them running outside the screen. For a tall, freely scrolling OpenBOR level, you need to build a level-update spawn manager that compares the player or camera position with a table of world coordinates, then spawns and removes entities according to distance.

DC
 
In the past, I had created a platformer level which you could spawn enemies without requiring groups, but with a calculation of scrollpos (at) and x coords of enemies to spawn outside of the screen, for them to appear exactly like a platformer without lagging speed. Thanks to @Bloodbane, I got better with the platforming method using math. However, I feel like this is different because of the level's height size I'm using for jumping/moving up until you reach its peak. Also, I keep using at 0 when I spawn many entities without grouping because I worry if I scroll left and right while using direction both and moving up, the performance lags the gameplay experience especially those specific entities that perform actions with given sounds, such as repetitive shooting, looping traps with sounds, etc. I have to use a non-moving animation as a follow animation and place them in a specific position with "position" property to change. For example, you start with a non-moving enemy until you get close to him and a(n) none/enemy/trap-type entity that is far away from and way above the two, but it's actively playing its sound (because it's not grouped in the level).

Code:
spawn    Respawn
@script
void main()
{
    void P1 = getplayerproperty(0, "entity");

    changeopenborvariant("xpos", 580);
    changeopenborvariant("ypos", 2000);
    changeentityproperty(P1,"position", 740, NULL(), 1);
    changeentityproperty(P1,"direction", 0);
}
@end_script
coords 740 2137 1 #740-160=580
flip 1
at 0

spawn trap1
coords 400 2137 500
at 0

spawn trap2
@script
void main(){
void self = getlocalvar("self");
performattack(self, openborconstant("ANI_FOLLOW3"));
changeentityproperty(self, "position", 360, 2137, 800);
}
@end_script
coords 200 2137 800
at 0

spawn enemy1
coords 330 2137 #330-160=170
at 0

I put non-enemies first in the line before I put enemies.

I can use "position" property to set their locations and give follow animations as non-moving motions. But how can I avoid this lag when I have many entities spawned with at 0 (or any value higher than 0) and without grouping on certain altitude positions in one go to look very seamless like the Mega Drive (Genesis) version of X-Men?
About the lag, as a test I suggest replacing the inline scripts with spawnscripts versions of the same code.
I think that spawnscripts are pre-processed like the @cmd animation scripts. @DCurrent can explain better than me.
 
But how can I avoid this lag when I have many entities spawned with at 0 (or any value higher than 0) and without grouping on certain altitude positions in one go to look very seamless like the Mega Drive (Genesis) version of X-Men?

I'm not sure which stage you are referring from X-Men but if you watched video of Ex-Mutant, there's a skyscraper stage at end of game just before Sluggo. The stage is tall as you'd expect but the spawns are pretty limited.
You should do something similar that is reduce the spawns to reduce the lag. If that isn't enough, alternate way is to redesign the whole stage to spawn enemies per section of the stage instead of spawn all enemies at once at 0.
The former is what I did in vertical stages of Contra Locked 'N' Loaded.
 
Back
Top Bottom