mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Changed spaces to tabs, Fixed a potential bug, Removed debug stuff
This commit is contained in:
parent
a4a6e09d74
commit
e8471ce6e6
1 changed files with 18 additions and 19 deletions
|
|
@ -4,31 +4,30 @@ local mod = {}
|
||||||
|
|
||||||
-- Module functions
|
-- Module functions
|
||||||
local function getBox(tx, ty, i, sx, sy)
|
local function getBox(tx, ty, i, sx, sy)
|
||||||
--i = i - 1
|
x = (i%tx)
|
||||||
x = (i%tx)
|
y = math.floor(i/tx)
|
||||||
y = math.floor(i/tx)
|
|
||||||
|
|
||||||
return (x*sx), (y*sy)
|
return (x*sx), (y*sy)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sprite object methods
|
-- Sprite object methods
|
||||||
local function draw(self, x, y, rad)
|
local function draw(self, x, y, rad)
|
||||||
if not self.animations[self.currentAnimation] then return 0 end
|
if not self.animations[self.currentAnimation] then return 0 end
|
||||||
local frame = self.animations[self.currentAnimation].animation[self.currentFrame]
|
|
||||||
local tsx, tsy = self.texture:getSize()
|
|
||||||
|
|
||||||
local sx, sy = getBox(tsx, tsy, frame, self.frameSizeX, self.frameSizeY)
|
|
||||||
gfx.text(200, 200, sx.."/"..sy)
|
|
||||||
self.texture:drawPart(x, y, sx, sy, self.frameSizeX, self.frameSizeY, rad)
|
|
||||||
|
|
||||||
if (ctr.time()-self.frameTimer) >= self.animations[self.currentAnimation].delay then
|
if (ctr.time()-self.frameTimer) >= self.animations[self.currentAnimation].delay then
|
||||||
self.currentFrame = (self.currentFrame+1)
|
self.currentFrame = (self.currentFrame+1)
|
||||||
self.frameTimer = ctr.time()
|
self.frameTimer = ctr.time()
|
||||||
if self.currentFrame > #self.animations[self.currentAnimation].animation then
|
if self.currentFrame > #self.animations[self.currentAnimation].animation then
|
||||||
self.currentFrame = 1
|
self.currentFrame = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local frame = self.animations[self.currentAnimation].animation[self.currentFrame]
|
||||||
|
local tsx, tsy = self.texture:getSize()
|
||||||
|
|
||||||
|
local sx, sy = getBox(tsx, tsy, frame, self.frameSizeX, self.frameSizeY)
|
||||||
|
self.texture:drawPart(x, y, sx, sy, self.frameSizeX, self.frameSizeY, rad)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -61,7 +60,7 @@ function mod.new(texture, fsx, fsy)
|
||||||
currentAnimation = 0,
|
currentAnimation = 0,
|
||||||
currentFrame = 1,
|
currentFrame = 1,
|
||||||
frameTimer = 0,
|
frameTimer = 0,
|
||||||
|
|
||||||
draw = draw,
|
draw = draw,
|
||||||
addAnimation = addAnimation,
|
addAnimation = addAnimation,
|
||||||
setAnimation = setAnimation,
|
setAnimation = setAnimation,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue