Cax 內置 Sprite

2018-06-21 11:13 更新

序列幀動畫組件,可以把任意圖片的任意區(qū)域組合成一串動畫。

  1. const sprite = new cax.Sprite({
  2. framerate: 7,
  3. imgs: ['./mario-sheet.png'],
  4. frames: [
  5. // x, y, width, height, originX, originY ,imageIndex
  6. [0, 0, 32, 32],
  7. [32 * 1, 0, 32, 32],
  8. [32 * 2, 0, 32, 32],
  9. [32 * 3, 0, 32, 32],
  10. [32 * 4, 0, 32, 32],
  11. [32 * 5, 0, 32, 32],
  12. [32 * 6, 0, 32, 32],
  13. [32 * 7, 0, 32, 32],
  14. [32 * 8, 0, 32, 32],
  15. [32 * 9, 0, 32, 32],
  16. [32 * 10, 0, 32, 32],
  17. [32 * 11, 0, 32, 32],
  18. [32 * 12, 0, 32, 32],
  19. [32 * 13, 0, 32, 32],
  20. [32 * 14, 0, 32, 32]
  21. ],
  22. animations: {
  23. walk: {
  24. frames: [0, 1]
  25. },
  26. happy: {
  27. frames: [5, 6, 7, 8, 9]
  28. },
  29. win: {
  30. frames: [12]
  31. }
  32. },
  33. playOnce: false,
  34. currentAnimation: "walk",
  35. animationEnd: function () {
  36. }
  37. });
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號