help animating a player in Corona SDK
- by andrew McCutchan
Working on a game in the Corona SDK with Lua and I need help so the player animates on the line drawn. Right now he animates at the beggining and the end but not on the line.
Here is the player code:
function spawnPlayerObject(xPlayerSpawn,yPlayerSpawn,richTurn) --spawns Rich where we need him.
-- riches sprite sheet and all his inital spirites. We need to adjust this so that animations 3-6 are the only ones that animate when moving horizontally
local richPlayer = sprite.newSpriteSet(richSheet1,1,6)
sprite.add(richPlayer, "rich", 1,6,500,1)
rich = sprite.newSprite(richPlayer)
rich.x = xPlayerSpawn
rich.y = yPlayerSpawn
rich:scale(_W*0.0009, _W*0.0009) -- scale is used to adjust the size of the object.
richDir = richTurn
rich.rotation = richDir
rich:prepare("rich")
rich:play()
physics.addBody( rich, "static", { friction=1, radius = 15 } ) -- needs a better physics body for collision detection.
end
And here is the code for the line:
function movePlayerOnLine(event)
--for the original image replace all rich with player.
if posCount ~= linePart then
richDir = math.atan2(ractgangle_hit[posCount].y-rich.y,ractgangle_hit[posCount].x-rich.x)*180/math.pi
playerSpeed = 5
rich.x = rich.x + math.cos(richDir*math.pi/180)*playerSpeed
rich.y = rich.y + math.sin(richDir*math.pi/180)*playerSpeed
if rich.x < ractgangle_hit[posCount].x+playerSpeed*10 and rich.x > ractgangle_hit[posCount].x-playerSpeed*10 then
if rich.y < ractgangle_hit[posCount].y+playerSpeed*10 and rich.y > ractgangle_hit[posCount].y-playerSpeed*10 then
posCount = posCount + 1
end
end
I don't think anything has changed recently but I have been getting an error when testing of "attempt to upvalue "rich" a nil value" on the second line, richDir = etc.