Best way to code continous/never-ending gameplay?

Hey,
So basically I have a ‘never-ending’ mode in my game. What this essentially does is spawn specified level segments in front of the player, and delete past segments as the player progresses ‘up’ the screen…

It’s an iOS game and I’m trying to establish the best way of getting it working. Currently I’m spawning a pool of the ‘segments’ out of the way of the player on level load and immediatly de-activating them, then as the player hits certain checkpoints/ event triggers i’m activating them and moving them just ahead of the player. Similarly I’m recycling old segments for re-use so that if that segment is ‘call up’ again then all the parts simply re-activate and move into the new position…

This seems to work fairly well in terms of optimization for the majority of the time EXCEPT for when the checkpoint is hit/ the part moved into position, at which point all the physics objects in that segment become enabled (presumably not sleeping) and the spike causes about 1/3 of a second of ‘freeze’ before then resuming to normal fps. All the physics objects are set to isKinematic, but I still get the spike…

I was just wondering if anyone had a better way of doing this/ had any better approaches to this type of gameplay?

Many thanks in advance,

  • Adam G

My advice would be to optimize all of your graphics as in my opinion you seem to be doing everything else right. Just simplify your graphics if you can, atlas build as few materials as possible. An you even combine or lose some textures? Have you considered using x background and just adjusting its color?

an idea I just had is this. I use 2D Sprite Manager, but if 3D the same technique could apply. Have two main background objects. That’s it. Just use one, deactivate the other. When you want to activate the other, in 2D I would just change the animation cell, or uv’s on the background. This seems like a very efficient way of conducting the endless levels.

I build for mobile and turn on off, enable, disable sprites all the time with no spikes.

I’m using EZGUI, everything is in one map…

I dont think it’s the enabling the sprites which is causing it tbh, the profiler shows a spike in physics when they are activated… I figured as they are set to isKinematic they would remain ‘asleep’ even if re-activated, but I’m not sure now…

Also the structure of the game is such that there is just one static background/ no uv scrolling or anything like that*.

How many objects are you setting physics with? I continually set on colliders, and enable rigidbodies, plus renderer’s… All bullets and see no spikes.

Each ‘segment’ has between 25-100 (again all with isKinematic set to true) and with past ones being turned off once the character has passed them).

And what exactly are you turning on and off?

Just a quick suggestion, perhaps turn on the ones you need, wait a half second, turn off the ones you do not.