Hey this is my first time making a game in corona for a school project. I have a working code for player movement so when the left or right arrow is pressed, the player on the screen will move left or right. However, i put my sprite in a table (as there are two different costumes for the sprite) and now the movement will not work. Here is my code:
[lua]-- Function for the player table
local function playerLook()
for i=1,2 do
playerCostume = display.newImageRect( mainGroup, objectSheet, i, 30, 50 )
table.insert( player, playerCostume )
physics.addBody( playerCostume, { radius=30, isSensor=true } )
playerCostume.x = display.contentCenterX
playerCostume.y = display.contentHeight - 95
playerCostume.myName = “costume”
playerCostume.isVisible = false
end
costume = 1
player[costume].isVisible = true
end
–When left arrow is touched, move character left
local function leftTouch()
motionx = -speed;
end
left:addEventListener(“touch”, leftTouch)
–When right arrow is touched, move character right
local function rightTouch()
motionx = speed;
end
right:addEventListener(“touch”, rightTouch)
–Move character
local function movePlayer( event )
playerCostume.x = playerCostume.x + motionx;
end
Runtime:addEventListener( “enterFrame”, movePlayer)
–Stop character movement when no arrow is pushed
local function stop( event )
if event.phase == “ended” then
motionx = 0;
end
end
Runtime:addEventListener(“touch”, stop )[/lua]
