Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Animation Test
- --Cant find who the original code was from
- --Zombie sprite from West
- -- Modified by Briarfox
- --sprite download http://db.tt/eMJa1tsS
- function setup()
- print("Simple Animation")
- displayMode(FULLSCREEN)
- img = readImage("Dropbox:ZombieSpriteSheet") --set the sprite sheet here
- zombie = SimpleSprite(img,5,5) --instance of the class that holds all the animations
- --loads individual animations loadAnimation(the name,vec2 of position on screen,vec2 of size,speed,column of
- --spritesheet, row of spritesheet
- zombie:loadAnimation("test",vec2(WIDTH/2,HEIGHT/2),vec2(150,150),5,0,4)
- zombie:loadAnimation("test1",vec2(100,600),vec2(50,50),16,0,3)
- zombie:loadAnimation("test2",vec2(400,300),vec2(100,100),5,0,2)
- zombie:loadAnimation("test3",vec2(800,400),vec2(200,200),3,0,3)
- zombie:loadAnimation("test4",vec2(175,175),vec2(175,175),30,0,4)
- zombie:loadAnimation("test5",vec2(485,700),vec2(125,125),7,0,4)
- zombie:loadAnimation("test6",vec2(950,100),vec2(100,100),10,0,3)
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(255, 255, 255, 255)
- zombie:draw()
- -- This sets the line thickness
- strokeWidth(5)
- -- Do your drawing here
- end
- --# SimpleSprite
- --This was from someone else's work on the forums, his original code did not have his name and I cant find the post.
- --This will load one sprite sheet and allow you to create animations for each row on the sheet
- SimpleSprite = class()
- function SimpleSprite:init(img,cols,rows) --img of the sprite sheet, cols = columns on sheet, rows = rows on sheeet
- -- you can accept and set parameters here
- self. m = mesh()
- self.m.texture = img --sprite sheet
- self.animation = {} --animation table to hold the different animations
- self.numacross = rows -- number of sprite rows
- self.numdown = cols -- number of sprite columns
- -- animdelay=0
- end
- function SimpleSprite:draw()
- -- Codea does not automatically call this method
- --background(40, 40, 50)
- self.m:clear()
- noSmooth()
- for u,v in pairs(self.animation) do
- local idx = self.m:addRect(self.animation[u].coords.x,self.animation[u].coords.y,self.animation[u].size.x,self.animation[u].size.y)
- self.m:setRectTex(idx,self.animation[u].xanim*(1/self.numacross), self.animation[u].yanim*(1/self.numdown),(1/self.numacross),(1/self.numdown))
- if self.animation[u].animdelay>self.animation[u].animspeed then
- self.animation[u].xanim = self.animation[u].xanim + 1
- self.animation[u].animdelay=0
- end
- if self.animation[u].xanim>self.numacross-1 then
- self.animation[u].xanim=0
- end
- self.animation[u].animdelay = self.animation[u].animdelay + 1
- self.m:draw()
- end
- end
- function SimpleSprite:touched(touch)
- -- Codea does not automatically call this method
- end
- function SimpleSprite:loadAnimation(name,screenCoords,sSize,speed,row,col)
- self.animation[name] = {
- animspeed = speed,
- xanim = row,
- yanim = col,
- coords = screenCoords,
- size = sSize,
- animdelay = 0
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement