Advertisement
Guest User

custom animation

a guest
Sep 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. --For usage, check out the encounter Lua's EncounterStarting() and Update() functions.
  2.  
  3. -- First, we can create the torso, legs and head.
  4. sanstorso = CreateSprite("sans/sanstorso")
  5. sanslegs = CreateSprite("sans/sanslegs")
  6. sanshead = CreateSprite("sans/sanshead1")
  7.  
  8. --We parent the torso to the legs, so when you move the legs, the torso moves too.
  9. --We do the same for attaching the head to the torso.
  10. sanstorso.SetParent(sanslegs)
  11. sanshead.SetParent(sanstorso)
  12.  
  13. --Now we adjust the height for the individual parts so they look more like a skeleton and less like a pile of bones.
  14. sanslegs.y = 240
  15. sanslegs.x = 320
  16. sanstorso.y = -5 --The torso's height is relative to the legs they're parented to.
  17. sanshead.y = 40 --The head's height is relative to the torso it's parented to.
  18.  
  19. --We set the torso's pivot point to halfway horizontally, and on the bottom vertically,
  20. --so we can rotate it around the bottom instead of the center.
  21. sanstorso.SetPivot(0.5, 0)
  22.  
  23. --We set the torso's anchor point to the top center. Because the legs are pivoted on the bottom (so rescaling them only makes them move up),
  24. --we want the torso to move along upwards with them.
  25. sanstorso.SetAnchor(0.5, 1)
  26. sanslegs.SetPivot(0.5, 0)
  27.  
  28. --Finally, we do some frame-by-frame animation just to show off the feature. You put in a list of sprites,
  29. --and the time you want a sprite change to take. In this case, it's 1/2 of a second.
  30. sanshead.SetAnimation({"sans/sanshead1", "sans/sanshead2", "sans/sanshead3"}, 1/2)
  31.  
  32. function AnimateSans()
  33. sanslegs.Scale(1, 1+0.1*math.sin(Time.time*2))
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement