another neophyte having animation issues

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
Steak
Prole
Posts: 2
Joined: Sun Jul 08, 2012 10:40 pm
Location: the great white north
Contact:

another neophyte having animation issues

Post by Steak »

greetings, LOVE community. i have just started to use this framework about 4 days ago and i must say it's absolutely splendid so far. now, i hate to be asking for things right off the bat without contributing through one way or another but i have been rewriting the drawing code for this particular project a lot and none of the methods i've tried so far seems to work. i do have the current system that i will explain below the following code block, though.

Code: Select all

function love.load()

	screen = {};
		screen.width = 640;
		screen.height = 480;

	love.graphics.setMode(screen.width, screen.height, false, false, 0);
	
	music = {};
		--music.source = love.audio.newSource("14Confrontation.mp3");
	
	--love.audio.play(music.source);
	
	objects = {};
	
		objects.mario = {};
			objects.mario.graphics = love.graphics.newImage("mario.png");
			objects.mario.graphicsWidth = objects.mario.graphics:getWidth(objects.mario.graphics);
			objects.mario.graphicsHeight = objects.mario.graphics:getHeight(objects.mario.graphics);
			objects.mario.quadStartX = 0;
			objects.mario.quadStartY = 0;
			objects.mario.quadWidth = 32;
			objects.mario.quadHeight = 64;
			objects.mario.originX = objects.mario.quadWidth / 2;
			objects.mario.originY = objects.mario.quadHeight / 2;
			objects.mario.quad = love.graphics.newQuad(objects.mario.quadStartX, objects.mario.quadStartY,
														objects.mario.quadWidth, objects.mario.graphicsHeight, 96, 64);

end

function love.update(dt)
	
	--PLACE HOLDER

end

function love.keypressed(key)

	if key == "right" then
		if not (objects.mario.quadStartX > (objects.mario.graphicsWidth - objects.mario.quadWidth * 2)) then
			objects.mario.quadStartX = objects.mario.quadStartX + objects.mario.quadWidth;
		else
			objects.mario.quadStartX = 0;
		end
	end

end

function love.draw()

	love.graphics.drawq(objects.mario.graphics, objects.mario.quad, (screen.width / 2), (screen.height / 2), 
						0, 1, 1, objects.mario.originX, objects.mario.originY, 0, 0);
	
	love.graphics.print(objects.mario.graphicsWidth,0,0);
	love.graphics.print(objects.mario.quadStartX,0,14);

end
mario's image file located in the root of the program:
jlwaD.png
jlwaD.png (967 Bytes) Viewed 172 times
so i just stored all of mario's graphics information in a table and made the program draw the first frame which is located on the far left of the sheet. in the keypress function, i tried to make it so that the quad's drawing coordinates would switch to his second image by pressing on the right arrow key, however, it doesn't seem to cycle through any of the images at all even though the program is telling me that "objects.mario.quadStartX" is in fact being manipulated. the line "if not (objects.mario.quadStartX > (objects.mario.graphicsWidth - objects.mario.quadWidth * 2)) then" tells the program to switch to the first frame again after the quad's top-right coordinates is larger than a certain point (64,0).

can anyone tell me what i'm doing wrong? i would also prefer to use my own animation system rather than using a library such as AnAL simply because i think it'll help me get more familiar with the language.

thanks everyone.
uh
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: another neophyte having animation issues

Post by bartbes »

Your check looks overly complicated, try this instead:

Code: Select all

function love.keypressed(key)
	if key == "right" then
                            objects.mario.quadStartX = (objects.mario.quadStartX + objects.mario.quadWidth) % objects.mario.graphicsWidth
	end
end
Anyway, the real problem is that you never actually change the Quad. Add this line to that if and you should be fine:

Code: Select all

objects.mario.quad:setViewport(objects.mario.quadStartX, objects.mario.quadStartY, objects.mario.quadWidth, objects.mario.quadHeight, objects.mario.graphicsWidth, objects.mario.graphicsHeight)
I'm not quite sure why you don't use all the variables (and correctly) when initially creating the quad, either.
User avatar
Steak
Prole
Posts: 2
Joined: Sun Jul 08, 2012 10:40 pm
Location: the great white north
Contact:

Re: another neophyte having animation issues

Post by Steak »

thanks, it worked perfectly. i didn't actually know there was a function to modify the quad and that the quad's coordinates update automatically without having to call said function. i was also completely unaware of the modulus operator's existence.

again, thanks so much. this helped a lot.
uh
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests