Hi all,
I am making my first game in lua (corona),… and want your help related to movement of my character in game, the issue is that the character is at option 0, 0 and does not move (character is a sprite sheet), here is my code and sprite sheet,… please help me out to solve this problem I tried my best but could not get it right,… please
[lua]function spawnCharacter()
local enemy
local good
local sheetData1 = { width=32, height=32, numFrames=12, sheetContentWidth=96, sheetContentHeight=128 }
local mySheet1 = graphics.newImageSheet( “bad5.png”, sheetData1 )
local sequenceData1 = {
{ name = “front”, frames={ 1,2,3 }, time=1000 },
{ name = “left”, frames={ 4,5,6 }, time=1000 },
{ name = “right”, frames={ 7,8,9 }, time=1000 },
{ name = “back”, frames={ 10,11,12 }, time=1000 }
}
enemy = display.newSprite( mySheet1, sequenceData1 )
enemy.name = “bad”
enemy:setSequence( “right” )
enemy:play()
enemy.moveX = math.random( 2, 5 )
enemy.moveY = math.random( 2, 5 )
timer.performWithDelay( 150, movebad(enemy), 0 )
end
[/lua]
here is the movement function
[lua] local function movebad(obj)
– let’s make him bounce around the screen
if obj.x < 0 or obj.x > display.contentWidth then
obj.moveX = -obj.moveX
end
if obj.y < 0 or obj.y > display.contentHeight then
obj.moveY = -obj.moveY
end
obj.x = obj.x + obj.moveX
obj.y = obj.y + obj.moveY
return obj
end[/lua]