How do I animate 1000s of grass objects .. Insane lag

0 favourites
  • 14 posts
From the Asset Store
Create an awesome world for your RPG top-down game with this Tileset
  • Hi all again,

    I have a map which randomly generates grass around the map depending on the season ingame. However having over 1000 sprites on a layer is insane.

    I've been told to achieve this by using Tiled Backgrounds. However, my grass was made using photoshop and animated and exported as a PNG sequence using After Effects. Now, I have just found out that I cannot animate a Tiled Background.

    Is there a way ? I cannot use Sprites, the game will lag.

    How can I achieve this please ? The grass sways in the wind and has 20 frames, it can be done via Sprites but having over 500 of these as well as having them animate is just absolutely insane. There must be a way, I am smashing my head on my keyboard, please help.

    Thank you all for reading and I hope a solution can be found.

  • Are you seeing all of that 500 (or more) grass sprites on the screen? or are they spread across the big layout and you see only few of them on the viewable screen?

  • Are you seeing all of that 500 (or more) grass sprites on the screen? or are they spread across the big layout and you see only few of them on the viewable screen?

    They are spread across the layout of which is 4096x4096, anything outside of the screen is set to invisible but not sure if setting their opacity to 0 would be better for this and then have their opacity set to 100 when on screen?

    During the summer season there can be 500 animating sprites at any given time on the players screen.

  • Just to clarify one thing first. Bare in mind that objects "Visibility" and "Opacity" are two different things. If objects visibility is set to "invisible" it means that object is not rendered by engine. But if you set objects Opacity to 0, the engine will still render this object on the screen but invisible.

    Second thing, objects outside the visible screen as I remember, are automatically not rendered by the engine.

    Going back to your issue, Could you please show an example of that sprite? Cause If I understand and think correctly there might be a way of using a mix of a sprites and a Tiled Backgrounds or even Tilemap.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dude you can just use the tiled sprite plugin, google it

  • You have only grass in your map? Whats the image size? Both px and kb?

    Can't you make a bigger image and use it as background or this is somekind of survival and the grass can be collected?

  • But if you set objects Opacity to 0, the engine will still render this object on the screen but invisible.

    Second thing, objects outside the visible screen as I remember, are automatically not rendered by the engine.

    It probably depends on the platform, browser or WebGL version.

    Try setting Text object opacity to 0 and then changing its text - TextWidth and TextHeight properties are not updated, because the text is not actually rendered. If you set opacity to 0.01, it starts rendering.

    Off-screen objects are not rendered, but they still consume CPU resources if they have active animations, behaviors, or they are part of different events, collision checks etc.

  • So this is what I’m doing. When landing on the planet, it’s just a Tiled Background of dirt, sand, snow or yellow snow. There are seasons, the seasons affect the GlobalVariable of clock. The clock controls the growth and placement of random shrubs, grass and saplings, as well as the day and night cycle and temperature too, not to mention wind, rain, snow and sun. *cough* Firestorm...

    Per shrub and sapling has 20 frames, they are PNG. They are between 128 - 256px and range from 31kb - 41kb per frame.

    Below I have gone in depth so that I can get the help that, I want to make sure that you all understand exactly what I'm doing so I can get the help that I need.

    Thank you for your help.

    I am making a Rim World clone in Construct2 but with my own very unique style. I am copying certain gameplay aspects of Rim World. Your life on earth in the year 2522 is ripped away from you. As an independent trader vessel, your job was to transport goods to and from Earth & Mars. Unfortunately your warp drive has a 1 in a quadrillion chance of having a fatal malfunction, this bends space and fires you through into unchartered territory. During this time your vessel is being ripped to pieces and you don't feel so good. Surprisingly whilst at the speed of light, you manage to vomit your way into your escape pod and after the whole ordeal you lose consciousness and wake up plummeting to an unknown planet of unknown origin. Oh no you say to yourself, I’m plummeting into a planet full of cyanide gas, but fear not! The escape pod is a cryopod and will not dump the panicking traveller onto a planet of which cannot sustain life. The year is unknown, is it the past, is it the future, how long have you been asleep, how long have I been travelling? ...What’s my name?! in time you will come to know.

    On landing, you and your droid are to survive, build, prosper and launch a spaceship into space of your own design in the later future to try and get back home. You will of course need to learn how to do many things, such as design a warp drive, a propulsion engine, a phaser ect ect … But fear not, located in your escape pod is your phone, it has no signal but it has with it every book to have ever existed. What’s the pin?!” ...erm. So no need for a research table, just sit down whilst snacking on a sandworm in candle light and learn how to make a wheelbarrow to how to make a propulsion engine, it’s all there once you can unlock your phone. Your droid is there to help you too. It will defend you, it will help you build and many more things that I have yet to come up with.

    During endgame, having researched the technology and built a spaceship and having launched into space you will be able to navigate your ship into an endless void, however certain things are bound to go wrong whilst your up there. My plan is to have you live on the actual ship you made for a set amount of days whilst holding off attackers from an unknown AI or life form ?

    Eventually the nasty AI or aliens that are out to get you will unfortunately destroy your ship. Lucky for you, you've always got your droid and escape shuttle in standby ready to fire you off into the next planet of which will have many different aspects from the last. Some good, some most unfortunately bad. The game is designed to get harder as the, I'm just going to call them aliens. The aliens will follow you, hence the game will become harder.

    The first planet will be of course be the easiest planet, much like earth. The 2nd planet and all those after that will be completely different in looks, gravity, time, weather and seasons ect ect…

  • 41kb per frame? So about 1MB (800KB) per sprite? Dunno....

    Try compressing better. Do you show it as 128px/256px? Or do you downscale? If so (for example, 64x64) the best thing to do is export the size u'll be using.

    Also, do you really need 20 frames? Tried already with lesser, to check smoothness?

  • Have you tried running the game in Debug Mode? What are the numbers for FPS, CPU, images memory usage?

    Try removing big portions of these grass sprites from the layout and see if FPS/CPU usage improves. Try deleting the entire grass object, disabling different event groups etc, and see what's affecting the performance the most.

  • 41kb per frame? So about 1MB (800KB) per sprite? Dunno....

    Try compressing better. Do you show it as 128px/256px? Or do you downscale? If so (for example, 64x64) the best thing to do is export the size u'll be using.

    Also, do you really need 20 frames? Tried already with lesser, to check smoothness?

    Will compress better and create size according to what I actually need. Unfortunately I have been resizing these sprites in the editor.

    Have you tried running the game in Debug Mode? What are the numbers for FPS, CPU, images memory usage?

    Try removing big portions of these grass sprites from the layout and see if FPS/CPU usage improves. Try deleting the entire grass object, disabling different event groups etc, and see what's affecting the performance the most.

    Thank you, I will reduce the number of sprites and check the FPS, CPU and image memoery usage.

  • Compressing images on import will have no positive effect on performance as all images are fully decompressed before rendering:

    Quoted here:

    [quote:fmv9y6ia]

    Also note images are fully decompressed before rendering, so the file format (whether you choose PNG-32, PNG-8 or JPEG) will have no effect on runtime memory use - only the download size.

  • zenox98 Invaluable, thank you. Reading now!

  • Compressing images on import will have no positive effect on performance as all images are fully decompressed before rendering:

    Quoted here:

    [quote:sfxhp6vu]

    Also note images are fully decompressed before rendering, so the file format (whether you choose PNG-32, PNG-8 or JPEG) will have no effect on runtime memory use - only the download size.

    nevertheless, i think this is the go-to for developers.

    as time goes by we, more and more commonly, see games reaching insane MB/GB's of size.

    for example i always export jpgs at 75~80 and the exactly size ill be needing.

    strange that in this link Ashley also notices:

    [quote:sfxhp6vu]The combined spritesheets for this single object is a 300kb download and uses 2mb of memory. Without spritesheets the separate images would have been a 460kb download and used about 3mb of memory. So when applied to the entire project the savings can be quite significant.

    I understand that this is about spritesheet VS single images, but still, 300kb x 460kb ~ 1MB memory.

    Edit:

    Will compress better and create size according to what I actually need. Unfortunately I have been resizing these sprites in the editor.

    Btw, to do this easily (if you don't know already), you can export the image accordingly and then, on the sprite, reimport the images. I didn't mean to underestimate, just because once i saw a tuto on youtube and the dude reimported the image as a new sprite and put behaviours, animation, etc, all over again, swapping this whenever needed on event sheet.

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