Some brief context on the project first: I'm a stop motion animator making a puppet inspired by a gameboy with an on-board Raspberry Pi so I can change it's facial expressions.
Here's an animation test showing my progress so far: https://twitter.com/CapsuleGhost/status ... 19488?s=20
I'm making some custom software to manage the puppets facial features and arrived at Love2d for it's RPi compatibility. My final goal is to have a program where i can control the macro location of the face on the screen, then fine tune the x,y of the individual facial features. Most importantly I need to be able cycle each mouth, eyebrow, and eye through it's respective spritesheet manually with a button input.
So here's my main question: Is there a way to assign each facial feature (with it's own spritesheet) to a different key input, and then have it advance one quad every time that key is pressed?
Here's what I have so far (I'm so sorry for the code gore.. this is literally my first experience coding and, as I'm sure you can tell, this is frankensteined together from a few tutorials and what i could figure out on my own.)
Code: Select all
--HEX FACE--
love.graphics.setDefaultFilter("nearest", "nearest")
le = {}
le_controller = {}
le_controller.le = {}
le_controller.image = love.graphics.newImage("oldHero.png")
function love. load()
animation = newAnimation(love.graphics.newImage("oldHero.png"), 16, 18, 1)
player = {}
player.x = 400
player.y = 400
player.speed = 10
le_controller:spawnLE(player.x - 100, player.y - 50)
end
function le_controller:spawnLE(x, y)
le = {}
le.x = x
le.y = y
table.insert(self.le, le)
end
----------------------------------CONTROLS----------------------------------
function love.update(dt)
animation.currentTime = animation.currentTime + dt
if animation.currentTime >= animation.duration then
animation.currentTime = animation.currentTime - animation.duration
end
if love.keyboard.isDown("right") then
player.x = player.x + player.speed
le.x = le.x + player.speed
elseif love.keyboard.isDown("left") then
player.x = player.x - player.speed
le.x = le.x - player.speed
end
if love.keyboard.isDown("up") then
player.y = player.y - player.speed
le.y = le.y - player.speed
elseif love.keyboard.isDown("down")then
player.y = player.y + player.speed
le.y = le.y + player.speed
end
end
-----------------------------GRAPHICS------------------------------------
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", player.x, player.y, 80, 20)
local spriteNum = math.floor(animation.currentTime / animation.duration * #animation.quads) + 1
love.graphics.draw(animation.spriteSheet, animation.quads[spriteNum], player.x - 100, player.y -100, 0, 4)
end
function newAnimation(image, width, height, duration)
local animation = {}
animation.spriteSheet = image;
animation.quads = {};
for y = 0, image:getHeight() - height, height do
for x = 0, image:getWidth() - width, width do
table.insert(animation.quads, love.graphics.newQuad(x, y, width, height, image:getDimensions()))
end
end
animation.duration = duration or 1
animation.currentTime = 0
return animation
end
Thanks for your time and sorry again if I misread a posting guideline.