A way of having thousands of objects

Discussion and feedback on Construct 2

Post » Thu Feb 19, 2015 10:17 pm

I think I've come up with a possible solution to having "too many objects" in a layout, but I wanted to see what people much smarter than me thinks.

My idea is simple: create a blank array, and at the start of a layout set the x, y, angle, frame, etc. of every single static scenery object (you'd have to make an array for each sprite since you can't create sprites by name) to the array. Delete everything that is further than x amounts of pixels from your character (ideally 1.5x the screen width for safety) and then do a check every couple ticks :

For Each X Element (array)
if distance(Player.X, Player.Y, Array.At(Array.CurValue, 0), Array.At(Array.CurValue, 1) < Screenwidth * 1.5 (< this might be the wrong code - I haven't tested it yet, but you get the idea)

ACTION: create object and set x y angle etc. to the array amount.

Else: destroy object.

So my question is this - it would heavily help the object count, but would it not be worth it due to the cpu increase of creating and destroying objects so often?
B
29
S
7
G
1
Posts: 490
Reputation: 3,288

Post » Fri Feb 20, 2015 7:15 am

you should try it and check it out! I'd totally appreciate knowing too, but its something you cant really be 100% sure of until you try it and compare.

https://www.scirra.com/blog/ashley/18/a ... asurements
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Fri Feb 20, 2015 8:07 am

@80bit - So I spent some time, creating arrays, pushing back each X for each sprite on the layout, setting a local number and increasing it to set the x, y, angle, layername, size, etc, deleting every object if the distance is far enough and recreating it based on the x and y position in the array.

Then I accidentally saw a new system event : Recreate Initial Objects.

-_-

So I deleted everything and added 2 events :)

Bottom line, we still need to test on bad computers (since it made no difference to mine). We know one thing - it's not something you can do every tick (obviously), so we check every 1 second. We destroy every object and recreate initial objects based on the viewport +/- a few hundred pixels. It drastically changed the object count (as expected), to where I was able to get a stage which had 2300 objects down to 400 without noticing a difference. I'll know more once I get my friend to test it on a lesser machine, but things are looking up for large layouts :)
B
29
S
7
G
1
Posts: 490
Reputation: 3,288

Post » Fri Feb 20, 2015 5:30 pm

interresttinggg... so how does it work with recreate initial objects? i thought that recreated *everything* that was placed on the layout in the editor?

good work looking into this!
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Fri Feb 20, 2015 7:08 pm

@80bit

It recreates everything with a specific binding. I just set it to create it based on the ViewportLeft-500 to ViewportRight+500, and ViewportTop-500 to ViewportBottom+500. The only key thing you need to do every time is right before it creates it, you have to destroy every object you're recreating, otherwise it will create duplicates.

It doesn't seem to keep the Zorder when created, though. Something to keep in mind.
B
29
S
7
G
1
Posts: 490
Reputation: 3,288

Post » Wed Mar 04, 2015 5:48 pm

This system's effectiveness might be negated though because destroying and creating large numbers of objects can be straining on the C2 engine.
B
42
S
12
G
1
Posts: 229
Reputation: 3,821

Post » Wed Mar 04, 2015 5:54 pm

you could use the characters to be drawn on canvas :) that way its not really a sprite object, but more a pixel drawn that significantly recovers cpu , and increases FPS
Image
B
66
S
19
G
67
Posts: 1,310
Reputation: 42,077

Post » Wed Mar 04, 2015 10:39 pm

@gamecorpstudio - correct me if I'm wrong, but pasting everything on the canvas would add to the image memory, and a file that size (~40,000 x 20,000) would load near gigs worth of memory. Of course I have no idea how this is done or if thats even how it works :)
B
29
S
7
G
1
Posts: 490
Reputation: 3,288

Post » Wed Mar 04, 2015 11:19 pm

The canvas is already an array.
Check out layers render cells.
Image ImageImage
B
165
S
49
G
146
Posts: 8,034
Reputation: 96,058

Post » Thu Mar 05, 2015 12:32 am

why do u even need 800,000 sprites on screen????? Construct itself supports around 10,000 sprites and still keeps 60 fps, if u use Q3DPlugin (you need to buy it) you can use over 40,000 3d objects or sprites and the cpu usage isn't noticeably, even the largest mmorpgs(1 being WoW) isn't using more then 10,000 objects on viewed field ... not sure if ur game will be using more then 500 on screen, that u ofcourse will destroy when is out of screen or time passes... :))))
Image
B
66
S
19
G
67
Posts: 1,310
Reputation: 42,077

Next

Return to Construct 2 General

Who is online

Users browsing this forum: imhotep22, TheRealDannyyy and 4 guests