• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Creating trees with slowed birth animation

Status
Not open for further replies.
Level 10
Joined
Jun 6, 2007
Messages
392
I'm making a simple library for creating growing trees. create tree function takes the growth duration as a parameter. The problem is, that when I use long growth times (e.g. 10 seconds), the animation "jumps" to the end. Why, and how could it be fixed? Here's my code:
JASS:
library TreeLib

    private struct Data
        destructable tree
        integer executions
        boolean invul = false
    endstruct

    globals
        constant integer TREE_ASHENVALE = 'ATtr'
        
        private constant real TIMEOUT = 0.04
        private constant real ANIM_SPEED = 3
        
        private timer T = CreateTimer()
        private integer Count = 0
        private Data array TreeList
    endglobals
    
    private function periodic takes nothing returns nothing
        local Data dat
        local integer i = 0
        loop
            exitwhen i >= Count
            
            set dat = TreeList[i]
            set dat.executions = dat.executions - 1
            if dat.executions == 0 then
                call SetDestructableAnimation(dat.tree, "stand")
                if dat.invul then
                    call SetDestructableInvulnerable(dat.tree, false)
                endif
                call dat.destroy()
                set Count = Count - 1
                set TreeList[i] = TreeList[Count]
            endif
            if Count == 0 then
                call PauseTimer(T)
            endif
            set i = i + 1
        endloop
    endfunction
    
    function createTree takes integer treeType, real x, real y, real angle, real growthDuration, boolean invWhenGrowing returns nothing
        local Data dat = Data.create()
        set dat.tree = CreateDestructable(treeType, x, y, angle, 1, 1)
        call SetDestructableAnimation(dat.tree, "birth")
        call SetDestructableAnimationSpeed(dat.tree, ANIM_SPEED/growthDuration)
        if invWhenGrowing then
            call SetDestructableInvulnerable(dat.tree, true)
            set dat.invul = true
        endif
        
        set dat.executions = R2I(growthDuration/TIMEOUT)
        set TreeList[Count] = dat
        set Count = Count + 1
        if Count == 1 then
            call TimerStart(T, TIMEOUT, true, function periodic)
        endif
    endfunction

endlibrary
And a simple test trigger:
[/
JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local real x = GetCameraTargetPositionX() 
    local real y = GetCameraTargetPositionY()
    
    call createTree(TREE_ASHENVALE, x, y, 0, 7.0, true)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Untitled_Trigger_001, Player(0), "tree", true )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
 
It's animation, yo, not really your fault. Just give a new stand animation in queue to refresh the duration in periodic event:

JASS:
if dat.executions == 0 then
    call SetDestructableAnimation(dat.tree, "stand")
    if dat.invul then
        call SetDestructableInvulnerable(dat.tree, false)
    endif
    call dat.destroy()
    set Count = Count - 1
    set TreeList[i] = TreeList[Count]
endif
->
JASS:
if dat.executions == 0 then
    call SetDestructableAnimation(dat.tree, "stand")
    if dat.invul then
        call SetDestructableInvulnerable(dat.tree, false)
    endif
    call dat.destroy()
    set Count = Count - 1
    set TreeList[i] = TreeList[Count]
else
    call QueueDestructableAnimation(dat.tree, "stand")
endif

Moved to Triggers&Scripts.
 
Status
Not open for further replies.
Top