Created
January 19, 2014 13:04
-
-
Save mgussekloo/8504708 to your computer and use it in GitHub Desktop.
Simple animation class for Löve using HUMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Animation = Class { | |
init = function(self, image, pos, steps, frameDelay) | |
self.image = image | |
self.pos = pos | |
self.width = image:getWidth() | |
self.height = image:getHeight() | |
self.frames = {} | |
self.currentFrameNumber = 0 | |
self.cycles = 0 | |
self.frameDelay = frameDelay | |
frameWidth = self.width / steps | |
frameHeight = self.height | |
for x=0, steps-1 do | |
self.frames[x] = love.graphics.newQuad((x*frameWidth), 0, frameWidth, frameHeight, self.width, self.height) | |
end | |
end, | |
update = function(self, dt) | |
self.cycles = self.cycles + dt | |
if (self.cycles > self.frameDelay) then | |
self.currentFrameNumber = self.currentFrameNumber + 1 | |
if (self.currentFrameNumber >= #self.frames) then self.currentFrameNumber = 0 end | |
self.cycles = 0 | |
end | |
end, | |
draw = function(self) | |
love.graphics.draw(self.image, self.frames[self.currentFrameNumber], self.pos.x, self.pos.y, 0, 4, 4) | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment