finish up implementing the animation setup, through anim8proxy

This commit is contained in:
Tim Anema 2014-12-04 21:57:54 -05:00
parent 5a60d1f1ca
commit 8e30cacae0
2 changed files with 37 additions and 4 deletions

View File

@ -3,7 +3,7 @@ local LightWorld = require "lib"
local anim8 = require 'lib.anim8'
function love.load()
x, y, scale = 0, 0, 1
x, y, z, scale = 0, 0, 1, 1
-- load images
image = love.graphics.newImage("examples/gfx/scott_pilgrim.png")
image_normal = love.graphics.newImage("examples/gfx/scott_pilgrim_NRM.png")
@ -18,12 +18,14 @@ function love.load()
-- create light
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
lightMouse:setGlowStrength(0.3)
lightMouse.normalInvert = true
-- create shadow bodys
animation = lightWorld:newAnimationGrid(image, 100, 100)
animation:setNormalMap(image_normal)
grid = animation:newGrid(108, 140)
animation:addAnimation('run right', grid('1-8', 1), 0.1)
animation:addAnimation('run left', grid('8-1', 2), 0.1)
local g = anim8.newGrid(108, 140, image:getWidth(), image:getHeight())
animation2 = anim8.newAnimation(g('1-8', 1), 0.1)
@ -50,9 +52,23 @@ function love.update(dt)
scale = scale + 0.01
end
if love.keyboard.isDown("a") then
animation:setAnimation('run left')
elseif love.keyboard.isDown("d") then
animation:setAnimation('run right')
end
animation2:update(dt)
lightWorld:update(dt) --only needed for animation
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale)
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale, z)
end
function love.mousepressed(x, y, c)
if c == "wu" then
z = z + 1
elseif c == "wd" then
z = z - 1
end
end
function love.draw()
@ -63,7 +79,7 @@ function love.draw()
lightWorld:draw(function()
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
animation.animation:draw(image, 100, 100)
animation:drawAnimation()
animation2:draw(image, 200, 100)
end)

View File

@ -153,11 +153,24 @@ function body:newGrid(frameWidth, frameHeight, imageWidth, imageHeight, left, to
end
-- frameWidth, frameHeight, imageWidth, imageHeight, left, top, border
function body:addAnimation(name, frames, durations, onLoop)
self.current_animation_name = self.current_animation or name
self.current_animation_name = self.current_animation_name or name
self.animations[name] = anim8.newAnimation(frames, durations, onLoop)
self.animation = self.animations[self.current_animation_name]
end
function body:setAnimation(name)
self.current_animation_name = name
self.animation = self.animations[self.current_animation_name]
end
function body:gotoFrame(frame) self.animation:gotoFrame(frame) end
function body:pause() self.animation:pause() end
function body:resume() self.animation:resume() end
function body:flipH() self.animation:flipH() end
function body:flipV() self.animation:flipV() end
function body:pauseAtEnd() self.animation:pauseAtEnd() end
function body:pauseAtStart() self.animation:pauseAtStart() end
function body:update(dt)
local frame = self.animation.frames[self.animation.position]
_,_,self.width, self.height = frame:getViewport()
@ -493,6 +506,10 @@ function body:isInRange(l, t, w, h, s)
return self.visible and (bx+bw) > (-l/s) and bx < (-l+w)/s and (by+bh) > (-t/s) and by < (-t+h)/s
end
function body:drawAnimation()
self.animation:draw(self.img, self.x, self.y)
end
function body:drawNormal()
if not self.refraction and not self.reflection and self.normalMesh then
love.graphics.setColor(255, 255, 255)