Handling many (200+) static objects.

Discuss game development design and post your game ideas

Post » Tue Oct 04, 2016 2:07 am

tl;dr Do objects outside the view area have less performance impact or the same as objects you can see?

I created an array of objects IDs and locations and am writing events to spawn or destroy objects from the list based on distance from the player. This is so I can have 200+ scenery objects in a map without actually having them all placed on the map at the same time.
I wonder however, does C2 do this internally already?
Will it be better for CPU cycles to iterate through a list of 200 and only create them when needed then destroy them when the player moves away or should I just place all of the objects in the layout from the beginning?
These objects will not be moving. They are just foliage and rocks and the like.

Thanks!
B
18
S
7
G
2
Posts: 77
Reputation: 2,005

Post » Tue Oct 04, 2016 3:20 am

if the objects will be static, you can use them as tilemap with a solid behavior..

in my experiments on mobile devices, the amount of objects affects the perfomance. in one android device with less than a 100 objects I get 60 FPS; in the other android I will get 60 FPS only with 80 objects.
B
64
S
32
G
69
Posts: 217
Reputation: 39,983

Post » Tue Oct 04, 2016 3:24 am

in this small tutorial game that I made, all the solids is one tilemap (just one object), then I "cover" it with another tilemap. so, with 2 objects, I get all the static solids of the game. you can download the source code of the game and see how I made it. ;)

https://www.scirra.com/arcade/tutorial- ... game-10855
B
64
S
32
G
69
Posts: 217
Reputation: 39,983

Post » Tue Oct 04, 2016 4:40 am

nemezes wrote:if the objects will be static, you can use them as tilemap with a solid behavior..

in my experiments on mobile devices, the amount of objects affects the perfomance. in one android device with less than a 100 objects I get 60 FPS; in the other android I will get 60 FPS only with 80 objects.


Thanks for the reply. Unfortunately it can't be a tilemap for this because of the Z-sorting. The player and enemies have to be able to walk behind the bushes.

http://www.cargocultgaming.com/CoA/ WASD to move and mouse to shoot. Or use a touch screen for both.
B
18
S
7
G
2
Posts: 77
Reputation: 2,005

Post » Thu Oct 06, 2016 1:59 am

nemezes wrote:in this small tutorial game that I made, all the solids is one tilemap (just one object), then I "cover" it with another tilemap. so, with 2 objects, I get all the static solids of the game. you can download the source code of the game and see how I made it. ;)

https://www.scirra.com/arcade/tutorial- ... game-10855


Not bad! I like the music and visual style. What happens if you want to remove a brick? Can you edit the tilemap during runtime? When the brick shows cracks are you just spawning a sprite on top of the tilemap?
B
18
S
7
G
2
Posts: 77
Reputation: 2,005

Post » Thu Oct 06, 2016 3:55 am

@roguecore, thanks. I dont know if the tilemap can be edited during the runtime.

The bricks that cracks are not tilemap, they are regular sprites, when the player hits it, it changes the animation. Tilemaps are static in the animations, I think you can not change the animation.

To spawn a sprite over a specific tilemap is a good idea, but I dont know if it is possible.
B
64
S
32
G
69
Posts: 217
Reputation: 39,983

Post » Sat Oct 08, 2016 2:39 pm

nemezes wrote:if the objects will be static, you can use them as tilemap with a solid behavior..

in my experiments on mobile devices, the amount of objects affects the perfomance. in one android device with less than a 100 objects I get 60 FPS; in the other android I will get 60 FPS only with 80 objects.


I think I solved it here https://www.scirra.com/forum/test-of-many-scenery-objects_p1072801?#p1072801

What kind of performance do you get?
B
18
S
7
G
2
Posts: 77
Reputation: 2,005

Post » Sun Oct 09, 2016 3:04 pm

@roguecore, in my experiments, I mean, I made an android apk exporting to cordova and using intel xdk.

I noticed that in my game Zuper Alien World running on my old cellphone (from 2014), it gets an average of 40 FPS and 80-90% of CPU usage if the game has more than 100 objects, sometimes it gets 100% of CPU and the FPS goes down to 20 FPS. when I start to get coins, and destroy some enemies and blocks, the object counting goes to less than 100 objects, then the CPU goes to about 70% and I get 50-60 FPS.

In the same game, on my older tablet (from 2013), the perfomance only gets better when the amount of objects go less than 80.

the game that I mention is this one: http://www.scirra.com/arcade/adventure- ... orld-10560
but running the game on the web, the performance is better, different when I run it as an android APK as I mentioned.

that's it.
B
64
S
32
G
69
Posts: 217
Reputation: 39,983

Post » Sun Oct 09, 2016 8:24 pm

roguecore wrote:
nemezes wrote:in this small tutorial game that I made, all the solids is one tilemap (just one object), then I "cover" it with another tilemap. so, with 2 objects, I get all the static solids of the game. you can download the source code of the game and see how I made it. ;)

https://www.scirra.com/arcade/tutorial- ... game-10855


Not bad! I like the music and visual style. What happens if you want to remove a brick? Can you edit the tilemap during runtime? When the brick shows cracks are you just spawning a sprite on top of the tilemap?


Yes, you can destroy it. You need to do a few things before anything:
1- Solid tilemap and the respective Tilemap with all the graphics must have the same size.
2- The same for the array. (e.g an array with 50 width and 20 height correspond to a tilemap of 1600 by 640 if tiles measure 32px (50*32 = 1600 and 32*20 = 640)
3- once done it all your map will be manageable because you now can use your array since every cell of the array correspond to a tile on the screen.
4-If you want to destroy some foliage on the map with your bullet... on destroy get the bullet's position, convert the x and y coordinate into tiles and now you know which tile to destroy.

Let me know if an example in capx is needed.
Last edited by kossglobal on Sun Oct 09, 2016 9:55 pm, edited 1 time in total.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sun Oct 09, 2016 9:13 pm

I use "proxy object" in my example to call big images when it will about to appear on screen. You won't notice what's happening till using debug mode.

https://dl.dropboxusercontent.com/u/659 ... latfo.capx
ImageImage
B
102
S
45
G
22
Posts: 772
Reputation: 21,493

Next

Return to Game Development, Design & Ideas

Who is online

Users browsing this forum: No registered users and 4 guests