Trouble with anim8

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Shopdawhoop
Prole
Posts: 2
Joined: Sat Nov 14, 2015 5:02 pm

Trouble with anim8

Post by Shopdawhoop »

I'm at my wits end as far as searching goes (minor differences?), and decided to do myself a favor--and here I am (Hello there).

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 here: https://github.com/kikito/anim8
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:

Error
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
...I tried playing around with it for hours, but the best I'd gotten was "expected drawable and got nil/table"
local anim8 = require 'anim8'
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

...I'm considering trying AnAL out instead since it's probably easier, but this'd still bother me.
Attachments
DevfoldErr.love
(21.87 KiB) Downloaded 79 times
Last edited by Shopdawhoop on Sun Nov 22, 2015 4:59 am, edited 3 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Problem trying out Anim8

Post by bartbes »

You're passing bullets.update a nil value because you forgot to define dt as argument to love.update.
Shopdawhoop
Prole
Posts: 2
Joined: Sat Nov 14, 2015 5:02 pm

Re: Problems Trying Out Anim8 2.1 (Updated 11/21/2015)

Post by Shopdawhoop »

Okay, so after fiddling around I managed to keep it from breaking.
I cleared the bullet table and used animation:draw inside an ipairs thing and it works...almost.

Now the sprite's animated, but it don't think it's drawing every bullet.

Here's the code

Code: Select all

local anim8 = require 'anim8'									
		canShoot = true
		canShootTimerMax = 0.09
		canShootTimer = canShootTimerMax

player = { x = 224, y = 710, speed = 350, img = nil }
bullet = {}

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() )
		boom = anim8.newAnimation(g('1-6',1), 0.04)
end

			function love.draw(dt)
					love.graphics.draw(player.img, player.x, player.y)
				for j, i in ipairs(bullet) do
					boom:draw(spritesheet, bullet.x, bullet.y)
				end
			end
	
function love.update(dt)
 boom:update(dt)
	if love.keyboard.isDown('z') and canShoot then							

		newBullet = { x = player.x, y = player.y }
		table.insert(bullet, newBullet)
		canShoot = false
		canShootTimer = canShootTimerMax
	end
	
		canShootTimer = canShootTimer - (1 * dt)
					if canShootTimer < 0 then
						canShoot = true
					end
	
				for i, d in ipairs(bullet) do
					d.y = d.y - (1500*dt)
					d.x = d.x - math.random(-2.5,2.5)
					bullet.y = d.y
					bullet.x = d.x

					if d.y < 0 then
						table.remove(bullet, i)
					end
				end
		end
Edit: Well, for some reason when I tried applying the code to the main project it worked perfectly. No idea what happened there.
Not a problem anymore I guess, but It'd still be nice to know where I did the stupid.

Edit2: Now I'm trying (to no avail) to get the death animation to stop or pause at the last frame after it plays once.

Mostly relevant code:

Code: Select all


player = { x = 224, y = 710, speed = 350, img = nil }
isAlive = true

function love.load()

		local o = anim8.newGrid(32,32, 32, 672)

                        mad = anim8.newAnimation (m(1,'1-3'), 0.05)
			death = anim8.newAnimation (o(1,'1-21'), 0.07)

		playerdeadImg = love.graphics.newImage ('Devfold_Assets/MANLTAMADead.png')
		playeraliveImg = love.graphics.newImage ('Devfold_Assets/MANLT.png')
end

function love.draw(dt)

	if love.keyboard.isDown('lshift') and isAlive and not love.keyboard.isDown('z') then
			mad:draw(playerdashingImg, player.x, player.y)

	elseif isAlive and not love.keyboard.isDown('z','lshift') then		
				love.graphics.draw(playeraliveImg, player.x, player.y)

	elseif not isAlive then
		death:draw(playerdeadImg, player.x, player.y)
		else 
	end

function love.update(dt)

	mad:update(dt)
	death:update(dt)
			
				if not isAlive then
					player.speed = 150
				end
end
...I also can't seem to wrap my head around the "onLoop" parameter. putting it on the 'death' array doesn't seem to do a thing
and if I put in
'death:pauseAtEnd()'
or
'death:pauseAtStart()'
in 'love.update()' it just skips to the last or first frames without animating.
Attachments
Devfoldnewest.love
Newest Version as of 1:45 AM
(28.27 KiB) Downloaded 71 times
DevfoldErr.love
Less stuff, with current code
(21.83 KiB) Downloaded 59 times
Devfold.love
The working version before anim8
(12.93 KiB) Downloaded 64 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Trouble with anim8

Post by s-ol »

Use "pauseAtEnd" as the third parameter to newAnimation and just play it to let it stay there (see the anim8 readme).

If you want to react to the end of animation (for example to remove a dead enemy) then use a custom onLoop:

Code: Select all

death.onLoop = function (anim)
  anim:pauseAtEnd()
  self.dead = true
end

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest