fork download
  1. local animations = {}
  2. local currentFrame = 1
  3.  
  4. function love.load()
  5. para =
  6. {
  7. {image = love.graphics.newImage("kirby.png"), x = love.graphics.getWidth () / 2, y = love.graphics.getHeight () / 2 + 175, sx = 0.3, sy = 0.3},
  8. {image = love.graphics.newImage("Kirby running.png"), x = love.graphics.getWidth () / 2, y = love.graphics.getHeight () / 2 + 175, sx=0.15, sy=0.15}
  9. }
  10. end
  11.  
  12. function love.draw()
  13. love.graphics.draw(para[currentFrame].image, para[currentFrame].x, para[currentFrame].y, 0, para[currentFrame].sx, para[currentFrame].sy, para[currentFrame].image:getWidth()/2, para[currentFrame].image: getHeight()/2) --para selects either values 1 or 2 from variable currentFrame, each one representing one of the tables inside the parent table para, then it uses the parameter defined inside that table for a value.
  14. end
  15.  
  16. function love.update(dt)
  17. local elapsedTime = 0
  18. elapsedTime = elapsedTime + dt --one down if elapsedTime > 0.5 every .5 seconds the loop runs and is reset at the end.
  19. if (love.keyboard.isDown("d")) then
  20. currentFrame = 2
  21. for i in pairs(para) do para[i].x = para[i].x + 200 * dt end
  22. --for i in pairs(para) do
  23. --if i in para[i].x > love.graphics.getWidth () + para[currentFrame].image:getWidth () / 9 then para[currentFrame].x = 0 end
  24. else
  25. currentFrame = 1
  26. end
  27. elapsedTime = 0
  28. end
  29.  
  30.  
Runtime error #stdin #stdout #stderr 0s 4376KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
lua5.3: prog.lua:4: attempt to index a nil value (global 'love')
stack traceback:
	prog.lua:4: in main chunk
	[C]: in ?