Animated PNG sequences on Quad – ShiVa Engine

Animated PNG sequences on Quad

This method uses a PNG sequence over a 3D plane (or HUD). This example was made to run at 25fps, just change the timer speed for other framerates. Why using a timer instead of game frame speed? Your 2D animation is most likely done in a different framerate than your game.

Tutorial

Fzuletademo1

HUD

Create a HUD called HUD_GAME with
– 1 timer: anim2DTimer set to 40, calling action anim2DTimerAction
– 2 actions: anim2DTimerAction SendEventToUser(CurrentUser, “Main_AI”, “onAnimate”) and anim2DTimerStart StartTimer(anim2DTimer)

MainAI

Create an AI Called Main_AI.

--onInit ()
local u = application.getCurrentUser ( )
application.setCurrentUserScene ( "scene_01" )
hud.newTemplateInstance ( u, "HUD_GAME", "HUD_GAME")
hud.callAction ( u, "HUD_GAME.anim2DTimerStart" )
--onAnimate ()
local s = application.getCurrentUserScene ( )
local o = scene.getTaggedObject ( s, "animSprite_01" )
object.sendEvent ( o, "char_AI", "onAnimate" )

CharAI

Create an AI called char_AI with 2 variables: bCanAnimate: true and nAnimCounter: 1
Create a handler: onAnimate()

local u = application.getCurrentUser ( )
        local s = application.getCurrentUserScene ( )
        local str="char_0_walk_0"
        local o = this.getObject ( )
        local curCounter=this.nAnimCounter ( )
        -- edit maxFrames to your max frames
        local maxFrames = 26
        if (this.bCanAnimate ( )==true)then
                    --this is only to
                    local i = curCounter
                    if (i < 10) then
                        str =str .. "00" .. i
                    elseif (i > 9 and i < 100) then
                        str =str .. "0" .. i
                    elseif (i > 99) then
                        str =str  .. i
                    end
                shape.overrideMeshMaterialEffectMap0 ( o, str, shape.kMapTypeTexture)
                -- hud.setComponentBackgroundImage ( hComponent, str ) --to be over HUD
            this.nAnimCounter ( curCounter+1 )
            if (this.nAnimCounter ( ) > maxFrames) then
                this.nAnimCounter ( 1 ) --1 is to loop, if u set it to maxFrames it will stop in the last frame
                --this.bCanAnimate ( false ) -- if u want it to stop then activate this
            end
        end



Need more answers?

  • slackBanner