Hi Dave,
Thanks for the repply.
But how can I make any declared variable a member of the SpriteObject?
I also need to use my declared variable that triggeres an animation (e.g. e:setSequence(“walking”))
local function cowboys (event) local e = Cowboy:new() e.x = 48 e.y = math.random (600,800) e.rotation = 90 physics.addBody (e,"static") local removeE = function () display.remove (e) end transition.to (e,{time = 20000,y = -50,onComplete = removeE}) return e end
And also on the collision function :
local varE = cowboys() local function onCollisionWithCowboy (self,event) if event.phase == "began" then varE:setSequence ("shooting") varE:play() end end
And this is the Cowboy.lua fie.:
Cowboy = {} function Cowboy:new() local self = display.newGroup() local sheetData = {width = 70,height = 107,numFrames = 14,sheetContentWidth = 140,sheetContentHeight = 749} local mySheet = graphics.newImageSheet ("cowboy.png",sheetData) local sequenceData ={ {name = "shooting",frames = {9,10,11,12,13,14},time = 1000,loppcount = 1}, {name = "cowboyWalking", start = 1,count = 8,time = 1200,loopcount = 0} } local cowboy = display.newSprite (mySheet,sequenceData) self:insert(cowboy) return self end return Cowboy
Thanks!