A way of having thousands of objects

0 favourites
  • 13 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • 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?

  • 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

  • - 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

  • 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!

  • 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.

  • This system's effectiveness might be negated though because destroying and creating large numbers of objects can be straining on the C2 engine.

  • 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

  • - 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The canvas is already an array.

    Check out layers render cells.

  • 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... )))

  • newt - I've already tried render cells when it was first introduced and it did nothing for me. I believe to see a difference from that, you'd need 10s of thousands of objects. Also, I'm not quite sure what you mean the canvas is already an array?

    - the problem isn't that they're all on screen simultaneously, it's that they're all in the same layout. And yes, we have over 5000 objects in some layouts and of course it runs 60 fps (I play games, so I have a decent computer), but a lot of "gamers" out there don't have such computers, but still expect to be able to play it as they can play other 2d games with ease.

    corlenbelspar - it does indeed kill cpu due to destroying and creating massive amounts of objects, but as long as it's not done every tick, it seems to be okay (I've found picking 3 sprites per stage and cascading them on an every 1 second event does the trick)

  • Storing x,y,and angle is redundant as you can reference objects directly.

  • ome6a1717 - I figured out a sort of cheater's way of having for example the illusion of thousands of enemies in a single layout. What I do is have them spawn from spawn objects only when the spawn objects come on screen and then when it get up to like 200 or more enemies it begins randomly deleting ones far enough off screen.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)