I'm pretty new to programming, and I've recently decided to try my hand at using animated sprites.
All I did was pretty much copy most of the example code
from a bunch of sources.
Edit: I managed to solve this problem and now I've tried to apply a bullet sprite onto my project.
Now I'm getting another problem
Here's what I'm getting now:
anim8.lua.229: attempt to perform arithmetic on local 'dt' (a nil value)
Traceback
main.lua:16: in function 'update'[
It fires the spritesheets and not the actual sprite, and for some reason the animated sprite is at the top-left.
Here's what I've got now (abridged project version)
Code: Select all
local anim8 = require 'anim8'
-- Timers
canShoot = true
canShootTimerMax = 0.09
canShootTimer = canShootTimerMax
player = { x = 224, y = 710, speed = 350, img = nil }
bullet = { spritesheet = spritesheet, x = nil, y = nil, speed = nil }
function love.load()
player.img = love.graphics.newImage('Devfold_Assets/MANLT.png')
spritesheet = love.graphics.newImage('Devfold_Assets/balls.png')
local g = anim8.newGrid(32,32, spritesheet:getWidth(), spritesheet:getHeight() )
asd = anim8.newAnimation(g('1-6',1), 0.1)
bulletAnimation = spritesheet
end
function love.draw(dt)
love.graphics.draw(player.img, player.x, player.y)
asd:draw(spritesheet, bullet.x, bullet.y)
for i, d in ipairs(bullet) do
love.graphics.draw(bulletAnimation, d.x, d.y)
end
end
function love.update(dt)
asd:update(dt)
if love.keyboard.isDown('z') and canShoot then --Shoot!
newBullet = { x = player.x, y = player.y, animation = bulletf }
table.insert(bullet, newBullet)
canShoot = false
canShootTimer = canShootTimerMax
end
canShootTimer = canShootTimer - (1 * dt)
if canShootTimer < 0 then
canShoot = true
end
for i, bullet in ipairs(bullet) do
bullet.y = bullet.y - (1500*dt)
bullet.x = bullet.x - math.random (0,15)
if bullet.y < 0 then
table.remove(bullet, i)
end
end
end
function love.load()
image = love.graphics.newImage('media/balls.png')
local g = anim8.newGrid(32,32, 192,32)
bullets = anim8.newAnimation(g('1-6',1), 0.1)
end
function love.draw()
bullets:draw(image, 100, 200)
end
function love.update()
bullets:update(dt)
end