hey im new to lua corona but i have used lua before.
My issue is simple but i have no idea how to get my function for buttons to oporate my animaton function.
revised and working but still having animation problem
local roundOutTickLimit = 15 -- 5min local roundOutTick = 0 local gameState = "game" local physics = require( "physics" ) physics.start() physics.setGravity( 0, 9.8 ) physics.setScale( 30 ) physics.setDrawMode( "normal" ) local background = display.newImage("BG.png") local ROI = display.newImage("UI/ROI.png") ROI.isVisible = false -- spawning locations (all maps have same locations) local spawnLocationFlagA = { Ax = 200, Bx = 240, Cx = 280 } local spawnLocationFlagB = { Ax = 1200, Bx = 1240, Cx = 1280 } local spawnLocationFlagC = { Ax = 2200, Bx = 2240, Cx = 2280 } local FlagAInfo = {x = 100, y = 300, mode = "Blue"} local FlagBInfo = {x = 1000, y = 300, mode = "Neutral"} local FlagBInfo = {x = 2000, y = 300, mode = "Red"} local clockSheetData = {width = 36,height = 35, numFrames = 5,sheetContentWidth= 180, sheetContentHeight= 35 } local clockSheet = graphics.newImageSheet( "UI/SPCS.png", clockSheetData ) local clockData = { name = "running", start=1, count=5, time= 4000 } local clockAnimation = display.newSprite( clockSheet, clockData ) clockAnimation.x = 250--center the sprite horizontally clockAnimation.y = 30 clockAnimation:setSequence("running") clockAnimation.isvisible = false local playerSheetData = {width = 43,height = 36, numFrames = 10,sheetContentWidth= 430, sheetContentHeight= 36 } local playerSheet = graphics.newImageSheet( "Player Data/ps.png", playerSheetData ) local sequenceData = { { name = "RunR", start=1, count=4, time= 250 }, { name = "CrouchR", start = 5,count = 1, time = 1 }, { name = "StandR", start = 1,count = 1, time = 1 }, { name = "RunL", frames = {10,9,8,7}, time= 250 }, { name = "CrouchL", start = 6,count = 1, time = 1 }, { name = "StandL", start = 10,count = 1, time = 1 } } local animation = display.newSprite( playerSheet, sequenceData ) animation.x = spawnLocationFlagA.Bx --center the sprite horizontally animation.y = display.contentHeight - animation.height animation.isVisible = false -- grouping guns = display.newGroup() objects = display.newGroup() -- player Info/ Ai info (contains some usefull information on game states and teams) local playerInfo = {currentWep = 2, score = 0, flags = 0, mode = "spawning", info = "ground", team = "Blue",direction = "r", ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400, pressingR = "false", pressingL = "false", pressingD = "false"} local AIAInfo = {currentWep = 2, score = 0, flags = 0, mode = "game", info = "ground", team = "Blue", direction = "r", ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400} local AIBInfo = {currentWep = 2, score = 0, flags = 0, mode = "game", info = "ground", team = "Blue", direction = "r",ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400 } local AIEAInfo = {currentWep = 2, score = 0, flags = 0, mode = "game", info = "ground", team = "Red", direction = "l", ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400} local AIEBInfo = {currentWep = 2, score = 0, flags = 0, mode = "game", info = "ground", team = "Red", direction = "l", ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400} local AIECInfo = {currentWep = 2, score = 0, flags = 0, mode = "game", info = "ground", team = "Red", direction = "l", ammo = 30, clip = 2, perk = "Mech", SPTimer = 0, dethCount = 0, health = 400} -- primary weps local GunSheetData = {width = 36,height = 12, numFrames = 6,sheetContentWidth= 216, sheetContentHeight= 12 } local GunSheet = graphics.newImageSheet( "Guns/gunsheet.png", GunSheetData ) local sequenceBData = { { name = "AKR", start=1, count=1, time= 1 }, { name = "AKL", start = 2,count = 1, time = 1 }, { name = "MPR", start = 3,count = 1, time = 1 }, { name = "MPL", start = 4,count = 1, time= 1 }, { name = "M4R", start = 5,count = 1, time = 1 }, { name = "M4L", start = 6,count = 1, time = 1 } } gunorintation = 0 local gunAnimation = display.newSprite( GunSheet, sequenceBData ) gunAnimation.x = display.contentWidth/2 --center the sprite horizontally gunAnimation.y = display.contentHeight - 30 guns:insert( gunAnimation ) physics.addBody( gunAnimation, "kinematic", { friction=0.0, bounce=0.0 } ) gunAnimation.rotation = gunorintation gunAnimation.isVisible = false local buttonR = display.newImage( "UI/buttonR.png" ) buttonR.x = 90 buttonR.y = 60 local buttonL = display.newImage( "UI/buttonL.png" ) buttonL.x = 30 buttonL.y = 60 local buttonUP = display.newImage( "UI/buttonUP.png" ) buttonUP.x = 60 buttonUP.y = 30 local buttonDN = display.newImage( "UI/buttonDN.png" ) buttonDN.x = 60 buttonDN.y = 90 local buttonSQ = display.newImage( "UI/bar.png" ) buttonSQ.x = 420 buttonSQ.y = 60 local scrollbar = display.newImage("UI/scroll.png") scrollbar.x = 420 scrollbar.y = 60 ------------------------------------- --- Animation button binding ------------------------------------- function buttonR:touch( event ) if gameState == "game" then if playerInfo.mode == "game" then if event.phase == "began" then display.getCurrentStage():setFocus(event.target) playerInfo.pressingR = "true" playerInfo.direction = "r" elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) --setting focus to 'nil' removes the focus playerInfo.pressingR = "false" end return true end end end buttonR:addEventListener( "touch", buttonR ) function buttonL:touch( event ) if gameState == "game" then if playerInfo.mode == "game" then if event.phase == "began" then display.getCurrentStage():setFocus(event.target) playerInfo.pressingL = "true" playerInfo.direction = "l" elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) --setting focus to 'nil' removes the focus playerInfo.pressingL = "false" end return true end end end buttonL:addEventListener( "touch", buttonL ) function buttonDN:touch( event ) if gameState == "game" then if event.phase == "began" then playerInfo.pressingD = "true" elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) --setting focus to 'nil' removes the focus playerInfo.pressingD = "false" end return true end end buttonDN:addEventListener( "touch", buttonDN ) local function movementBinding() if playerInfo.pressingL == "true" then if playerInfo.direction == "l" then print("run left") animation:setSequence("RunL") animation:play() end end if playerInfo.pressingR == "true" then if playerInfo.direction == "r" then print("run right") animation:setSequence("RunR") animation:play() end end if playerInfo.pressingR == "false" then if playerInfo.pressingL == "false" then if playerInfo.pressingD == "false" then if playerInfo.direction == "r" then print("stand Right") animation:setSequence("StandR") animation:play() end end end end if playerInfo.pressingR == "false" then if playerInfo.pressingL == "false" then if playerInfo.pressingD == "false" then if playerInfo.direction == "l" then print("stand Left") animation:setSequence("StandL") animation:play() end end end end if playerInfo.pressingD == "true" then if playerInfo.direction == "r" then animation:setSequence("CrouchR") animation:play() end end if playerInfo.pressingD == "true" then if playerInfo.direction == "l" then animation:setSequence("CrouchL") animation:play() end end if playerInfo.direction == "r" then if playerInfo.currentWep == 1 then gunAnimation:setSequence("AKR") gunAnimation:play() end if playerInfo.currentWep == 2 then gunAnimation:setSequence("MPR") gunAnimation:play() end if playerInfo.currentWep == 3 then gunAnimation:setSequence("M4R") gunAnimation:play() end end if playerInfo.direction == "l" then if playerInfo.currentWep == 1 then gunAnimation:setSequence("AKL") gunAnimation:play() end if playerInfo.currentWep == 2 then gunAnimation:setSequence("MPL") gunAnimation:play() end if playerInfo.currentWep == 3 then gunAnimation:setSequence("M4L") gunAnimation:play() end end end Runtime:addEventListener("enterFrame",movementBinding) -- player functions local function playerSpawning() if playerInfo.mode == "dead" then animation.isVisible = false playerInfo.deathCount = playerInfo.deathCount +1 playerInfo.mode = "spawning" end if playerInfo.mode == "spawning" then playerInfo.SPTimer = playerInfo.SPTimer +1 animation.isVisible = false gunAnimation.isVisible = false clockAnimation.isvisible = true clockAnimation:play() end if playerInfo.SPTimer \>= 5 then playerInfo.mode = "game" playerInfo.SPTimer = 0 print("player spawned") -- move world to position clockAnimation.isvisible = false end if playerInfo.mode == "game" then clockAnimation.isVisible = false display.remove( clockAnimation ) gunAnimation.isVisible = true animation.isVisible = true end end timer.performWithDelay(1000,playerSpawning,playerInfo.SPTimer) local function roundOut() if gameState == "game" then roundOutTick = roundOutTick + 1 if (roundOutTick \>= roundOutTickLimit) then print("Round Out") gameState = "round out" end end if gameState == "round out" then ROI.isVisible = true end end timer.performWithDelay(1000,roundOut,roundOutTick)
new issue: problem with running the animation because of the run time. when i press Right trigger player just stand and when i press L trigger the animation is still in stand left. it should jump into run animation. but i think there is an issue with Runtime