Hello! I could use some help making a basic animation in LOVE.

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
User avatar
Paz
Prole
Posts: 11
Joined: Sat Jun 09, 2018 12:13 pm

Hello! I could use some help making a basic animation in LOVE.

Post by Paz »

https://ideone.com/fXJszY


Here is a link to a code viewer with my program in it.

This program overall is still kinda confusing to me. Specifically the activeFrame and currentFrame variables and the love.update(dt) function. Both of which I got from another source on animation in LOVE. But anyhow I'm trying to get the program in LOVE to alternate between the first animation frame and the second animation frame. Both sprites are currently positioned on top of each other when running the program.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Hello! I could use some help making a basic animation in LOVE.

Post by Ref »

I can see what's causing you problems.
I suggest eliminating 'activeFrame' and stick with 'currentFrame'.
Then love.draw only has to contain

Code: Select all

im = animations[currentFrame]
love.graphics.draw(im, love.graphics:getWidth()/2,love.graphics:getHeight()/2, 0, 0.2,0.2 ,im:getWidth()/2,im:getHeight()/2)
Think I've got that right.
Best
User avatar
Paz
Prole
Posts: 11
Joined: Sat Jun 09, 2018 12:13 pm

Re: Hello! I could use some help making a basic animation in LOVE.

Post by Paz »

Ref wrote: Wed Jun 13, 2018 10:48 pm I can see what's causing you problems.
I suggest eliminating 'activeFrame' and stick with 'currentFrame'.
Then love.draw only has to contain

Code: Select all

im = animations[currentFrame]
love.graphics.draw(im, love.graphics:getWidth()/2,love.graphics:getHeight()/2, 0, 0.2,0.2 ,im:getWidth()/2,im:getHeight()/2)
Think I've got that right.
Best
That works thank you! But how would I separate both draw functions? I want to change the individual parameters for each image, for example their respective scaling. Is there a way to modify my existing two draw functions to allow for that? I tried replacing the animations[1] key with the variable im that you listed above but instead of drawing a single image it draws a duplicate for each image per frame.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Hello! I could use some help making a basic animation in LOVE.

Post by Ref »

Tables are what you want.

Code: Select all

ans = {
	{
	image = love.graphics.newImage('somethingOne.png,
	x=100,
	y=100,
	sx = 0.2,
	sy = 0.2
	},
	{
	image=love.graphics.newImage(somethingTwo.png',
	x=300,
	y=100,
	sx=0.3,
	sy=0.3
	}
	}
and then love.draw() contains:

Code: Select all

love.graphics.draw(
	ans[currentFrame].image,
	ans[currentFrame].x,
	ans[currentFrame].y,
	0,
	ans[currentFrame].sx,
	ans[currentFrame].sy,
	ans[currentFrame].image:getWidth()/2,
	ans[currentFrame].image:getHeight()/2
	)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 50 guests