Terraria Style Tree Generation From Saplings?

0 favourites
  • 7 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Whatsup peeps,

    I got a question about trees. How can i make trees that are in parts spawn as a whole trees

    But at the same time having the tree still able to be destroyed?

    I will have it so the player can grow trees at any time. I know how to do this with regular code I just dont understand how to do it in construct 2

  • Anybody have a clue?

    The only anwser I would have is just making it easier but I dont want that. If someone has aclue im all Ears.thanks in advance

  • Let's see...

    You could have something like this :

    globals :

    • treeGrowingTick
    • treeMinHeight
    • treeRandomHeight

    treeBase sprite :

    • isActive (boolean, true on create)
    • currentHeight (int, 1 on create)
    • targetHeight (int)

    treePart sprite :

    • treeBaseID (int)
    • initial frame is the top of the tree

    TreeSpawning :

    • spawn a "treeBase" sprite,
    • set targetHeight to round(random(treeRandomHeight)+treeMinHeight),
    • call "treeActualise"(treeBase.UID)

    on Function treeActualise,

    Pick treeBase by UID,

    if treeBase.currentHeight < treeBase.targetHeight

    Pick TreePart by comparaison (treeBaseID = treeBase.UID):

    • wait (treeGrowingTick)
    • set TreeBase frame to something more suitable
    • set treePart Frame to the middle of the tree
    • Spawn treePart at X=treeBase.X, Y=treeBase.Y+(treePart.PickCount+1)*treePart*height
    • set treePart.treeBaseID to treeBase.ID

    on Function treeDestroy (called with the treeBase UID as a parameter, making the tree base a good candidate for a "HP" variable ^^)

    Pick TreePart by comparaison (treeBaseID = treeBase.UID):

    • spawnLoot
    • treePart.destroy
    • treeBase.destroy

    As you can see TheNewGuy , I've written this directly on the forums, didn't test it. I hope it does the trick :)

  • Guizmus   Thanks bro,

    I was looking for a way to do this.Alot of what you said is foreign to me but I will do some research on alot of what you posted. Thanks for being detailed with the different options I have in front of me.

  • TheNewGuy Here is a capx example.

    Click on the ground to spawn a seed, it will then grow. 5 events. You can change speed and height with the globals.

    capx

  • This is pretty cool.You didnt have to go though all this bro! But I am very grateful to have had the chance to learn from you.Will this samestyle work if I have more tree parts?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • TheNewGuy

    More tree part ?

    If you mean a higher tree, no problem.

    If you are looking for a tree with horizontal branches too, it should, you will have to create a "branch" sprite, and spawn it randomly every 3 successful growth for example.

    There is no need for any more sprite that this for the tree, as the tree can always be separated in 3 parts : the base, the middle and the top (top and middle being the same sprite : "treePart")

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