- Tue 7 Aug 2018, 12:29
Did you try to remove the enemies and see if it helps?
If it does, what I would recommend to do is whatever the enemy is doing, moving, attacking player, playing animation..etc do it only if it distance from the player is below a certain amount, in other words update the enemies only if they are on the screen. Otherwise you are only waste resources on them.
If it doesn't help, try the gems too. In case removing the gems does improve performance, then try the same thing and update gems only if they are at certain distance from the player / it on the screen. Otherwise it is useless to update their animation and run the events to check collision with player and what not. Alternative to collision, you can also try checking distance only instead of collision. Collision checking does use more resources than distance checking but many times checking the distance is enough, no need collision checking.
Same goes for physics, easy to make staff move with physics, but in many cases all you want is increase and decrease position. So you also want to consider to simply update position of objects whenever you can instead of using physics to apply a force to make something move.
Also, in case an object doesn't really interact with anything, and you have many next to each other, always consider using the tiled sprite, or a single image with multiple sprites on it to reduce the number of objects in the scene.
You can also reduce the number of objects in the scene by using external layouts. As the player moving forward, you can delete anything that is behind the player and create from external layout everything in-front of the player. This way, you can minimize the number of objects in the scene at any given time regardless how big the level is. It is something I never tried actually, creating and deleting objects constantly can be expensive but in case the number of objects causing the lag, it would be a way to reduce the number of objects without changing between lot of scenes and without need to reduce the size of the levels. It would also allow you to make levels randomly generated, if interested. Though, in case constantly deleting objects behind the player and creating new ones in-front would be too heavy task, then what you could try is do it only once in a while and display a "loading..." message for the player and make it wait until the rest of the level get loaded and last part get deleted sort of like in a sandbox game where you have a loading screen when you enter different areas of the world. Maybe call it "checkpoint" and also save the state of the game there and then the players would more likely accept it if they need to wait a moment once in a while....
Finally, in case what I was suggesting doesn't help at all, the last thing I can recommend is try Cocoon with Canvas+ to package your game. It gives you almost native performance with HTML5.
Regarding the game, looks and apart from the lag it feels good. I think you should share it for desktop too (without the touch controls). I did experienced some weird bug with the touch controls but not sure if it caused by the lag or something else. Once you have the performance improved would try it again.