Guest User

Spine&Spritesheet animation comparison

a guest
Nov 23rd, 2018
125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. application:setBackgroundColor(0); require"spine"; local monitor,random=require"monitor",Core.random
  2.  
  3. local function spawnSpineObject()
  4.     local rooster=SpineSprite.new("data/rooster.json","data/rooster.atlas")
  5.     rooster:setAnimation(0,"rooster_run_anim",nil,true)
  6.     rooster:setPosition(random(0,160,570),random(0,160,1100))
  7.     stage:addChild(rooster)
  8. end
  9. for i=1,30 do spawnSpineObject() end
  10.  
  11. local rooster_texturepack = TexturePack.new("data/rooster_spritesheet.txt", "data/rooster_spritesheet.png", false)
  12.  
  13. local function spawnSpriteObject()
  14.     local rooster=MovieClip.new{
  15.         {1, 2, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_00.png"))},
  16.         {2, 4, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_01.png"))},
  17.         {4, 6, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_02.png"))},
  18.         {6, 8, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_03.png"))},
  19.         {8, 10, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_04.png"))},   
  20.         {10, 12, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_05.png"))},
  21.         {12, 14, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_06.png"))},
  22.         {14, 16, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_07.png"))},
  23.         {16, 18, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_08.png"))},
  24.         {18, 20, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_09.png"))},
  25.         {20, 22, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_10.png"))},
  26.         {22, 24, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_11.png"))},
  27.         {24, 26, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_12.png"))},
  28.         {26, 28, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_13.png"))},
  29.         {28, 30, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_14.png"))},
  30.         {30, 32, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_15.png"))},
  31.         {32, 34, Bitmap.new(rooster_texturepack:getTextureRegion("rooster_16.png"))}
  32.     }
  33.     rooster:setGotoAction(34, 1)
  34.     rooster:setPosition(random(0,50,570),random(0,50,1100))
  35.     stage:addChild(rooster)
  36. end
  37.  
  38. stage:addEventListener(Event.TOUCHES_END, function()
  39.     for i = stage:getNumChildren(), 1, -1 do
  40.         stage:removeChildAt(i)
  41.     end
  42.     collectgarbage()
  43.    
  44.     local textInputDialog = TextInputDialog.new("", "Number of sprites to spawn:", "10", "Spritesheet","Spine animation")
  45.     textInputDialog:setInputType(TextInputDialog.PHONE)
  46.    
  47.     textInputDialog:addEventListener(Event.COMPLETE, function(event)
  48.         for i=1,tonumber(event.text) do
  49.             if event.buttonIndex==1 then spawnSpineObject() else spawnSpriteObject() end
  50.         end
  51.     end)
  52.    
  53.     textInputDialog:show()
  54. end)
RAW Paste Data