How do I disable growth function

0 favourites
  • 4 posts
  • Having spent hours looking around the forum for a way to make a tiled Background play a sequence of images, I have been forced to use sprite's. In my game I have designed in such a way that the entire game randomly teraforms itself based on a global randomising number.

    I have flocks of birds, trees, grass with leaves that rustle in the wind. I have lakes of water and mountain ranges that appear from meteorites. I have a day and night, a season system and a wind system with weather effects.

    But my number 1 limitation is having to use many many sprite's. To be able to have a way to use Tiled Backgrounds would be a huge improvement in overall performance.

    My game is being designed purely for the PC as I do not believe that phones will be able to handle such a huge amount of sprite's at any given time.

    I also have some issues as well.

    Each tree has a variable called TargetScale. This is set to 1. When a tree spawns, it's scale is set to 0.1 (sapling) overtime the sapling will grow into a tree. Now when the tree's TargetScale becomes 1, the tree will continue to grow. However I have a compare variable that checks if Greater than or = to 1 set scale to 1. The tree will grow to 1.01 but in a blink resize itself back to 1 and so on. Now I cannot figure out a way of preventing that from happening as disabling the grow function will disable all the other trees from growing.

    Is there a way please?

  • Sprites are best for general purpose stuff. For animation they are a must unless you are willing to hide multiple objects and only show one at a time.

    If you have areas where a texture is repeated then a tiledbackground can be useful because it can render that as one object. If you need it animated that’s not what it’s for.

    If the objects are laid out in a grid you can look at the tilemap object. Again it’s not animated but it is faster than rendering multiple sprites, and collision detection is a bit faster with it.

    The rule of thumb is sprites are general purpose and the other objects are special purpose that are faster in some ways but less flexible.

    Other objects that may be useful:

    Spritesheet - lets you select a subrectangle of a texture to draw instead of the whole thing.

    Paster - lets you draw objects to it so you don’t have to redraw it every frame normally.

    Anyways if the game runs slow, the rendering of that many objects is the main bottleneck. You may just need to scale the amount of objects back.

    For the logic you can do

    Tree: myscale<1

    —- tree: set myscale to min(1, self.myscale+dt)

    Or whatever the variable name is.

    The condition only updates the trees that aren’t full grown, and stops at 1. Is that what you were after?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Even if you are using lots of sprites, there are still ways to optimize them.

    First, read these tutorials:

    https://www.construct.net/au/blogs/cons ... memory-796

    https://www.scirra.com/manual/134/performance-tips

    https://www.construct.net/au/blogs/ashl ... -works-917

    Try to make images (in sprites) as small as possible. Don't create big sprites and then scale them down on the layout.

    Don't create sprites with many animations.

    If you only need pine trees on this layout, a sprite containing 20 different animations for all kinds of trees will consume a lot of memory.

    If you have huge layouts with thousands of background sprites, try to build a system where sprites are created as you progress through the level and destroyed when they are no longer needed.

    Or at least disable animations/events/behaviors for sprites that are off-screen.

    Avoid using effects and behaviors on too many sprites.

    Regarding the issue with the TargetScale - you can do something like this:

    Every 1 second:
    Tree compare instance variable TargetScale<1   -> Add 0.1 to TargetScale
                                                   -> Tree set scale to TargetScale[/code:vut6cbur]
    
    Trees that have reached scale 1 will no longer be picked by this event.
  • Thank you both of you for your replies. I will see if I can fix this annoying issue once I have solved another annoying issue.

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