Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    physics.addBody( rich, "static", { friction=1, radius = 15 } ) -- needs a better physics body for collision detection.

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

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.

share|improve this question

closed as too localized by Anko, Josh Petrie, Byte56, bummzack, Trevor Powell Apr 12 '13 at 13:41

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Is movePlayerOnLine getting called before spawnPlayerObject? That would explain why rich is nil as it hasn't been assigned a sprite object yet.

share|improve this answer
no spawnPlayerObject is before movePlayerOnLine – andrew McCutchan Oct 28 '11 at 1:05
the error has been fixed but he is still not animating on the line – andrew McCutchan Oct 28 '11 at 4:28
Has the line or ractgangle_hit have a physics body? Do you have something setup so it plays an animation if there is a physics collision? – yaustar Oct 28 '11 at 10:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.