animation.template.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --[[
  2. The MIT License (MIT)
  3. Copyright (c) 2013 Patrick Rabier
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. the Software, and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. ]]
  19. --
  20. -- LOVE2D ANIMATION
  21. --
  22. --
  23. -- This file will be loaded through love.filesystem.load
  24. -- This file describes the different states and frames of the animation
  25. --
  26. --[[
  27. Each sprite sheet contains one or multiple states
  28. Each states is represented as a line in the image file
  29. The following object describes the different states
  30. Switching between different states can be done through code
  31. members ->
  32. imageSrc : path to the image (png, tga, bmp or jpg)
  33. defaultState : the first state
  34. states : a table containing each state
  35. (State)
  36. Each state contains the following members ->
  37. frameCount : the number of frames in the state
  38. offsetX : starting from the left, the position (in px) of the first frame of the state (aka on the line)
  39. offsetY : starting from the top, the position of the line (px)
  40. framwW : the width of each frame in the state
  41. frameH : the height of each frame in the state
  42. nextState : the state which will follow after the last frame is reached
  43. switchDelay : the time between each frame (seconds as floating point)
  44. ]]
  45. -- the return statement is mandatory
  46. return {
  47. imageSrc = "my_spritesheet.png",
  48. defaultState = "running",
  49. states = {
  50. -- 1st line
  51. running = { -- the name of the state is arbitrary
  52. frameCount = 3,
  53. offsetX = 0,
  54. offsetY = 0,
  55. frameW = 100,
  56. frameH = 100,
  57. nextState = "running", -- we loop the running state
  58. switchDelay = 0.1
  59. },
  60. -- 2nd line
  61. jump = {
  62. frameCount = 3,
  63. offsetX = 0,
  64. offsetY = 100,
  65. frameW = 100,
  66. frameH = 150, -- the frame height can change between states
  67. nextState = "running", -- after the jump is finished, we switch back to running
  68. switchDelay = 0.16
  69. },
  70. -- 3rd line
  71. attack = {
  72. frameCount = 3,
  73. offsetX = 0,
  74. offsetY = 250,
  75. frameW = 100,
  76. frameH = 100,
  77. nextState = "running",
  78. switchDelay = 0.1
  79. }
  80. }
  81. }