Love2D Animations?


monstercameron

Well-Known Member
Joined
Oct 19, 2010
Messages
1,001
Website
www.thinkteletronics.com
i have been practicing love2d for a few weeks now and i have not been making much process - in part due to some frustration. I am looking for help with the code for animations. the way i usually do animations is just swap separate sprites on an event but it seems sprite sheets would be better. Anyaway any help would be good!
my source so far! and my love is dl it here, it actually works on caanoo but joysticks and fps are a bit wonky
Code:
function love.load()
	love.mouse.setVisible(false)
	font = love.graphics.newFont(14)
	love.graphics.setFont(font)

	level_1_platform_1= love.graphics.newImage("images/platform.png")
	platform_1_x =0
	platform_1_y =0

	level_1_platform_2= love.graphics.newImage("images/platform.png")
	platform_2_x =320
	platform_2_y =0

	parallax_layer_1=love.graphics.newImage("images/parallax_bg.png")
	parallax_1_x = 0	
	parallax_1_y = 0

	parallax_layer_2=love.graphics.newImage("images/parallax_bg_1.png")
	parallax_2_x = 0	
	parallax_2_y = 0
	
	hero= love.graphics.newImage("images/hero.png")
	hero_x=200
	hero_y=220
	heroMass=100
	heroInertia=5
	heroWalk=5
	heroGravity=3

	pauseMe=0

	music = love.audio.newSource("audio/ambiant.ogg", "stream")
	music:setLooping(true)
	love.audio.play(music)
	love.audio.setVolume(0.5)	
end

function movement(direction)
	if direction == 1 then
		--hero_x = hero_x - heroWalk
		platform_1_x= platform_1_x + 5
		platform_2_x= platform_2_x + 5
		parallax_1_x = parallax_1_x + 2
		parallax_2_x = parallax_2_x + 1
	elseif direction == 2 then
		--hero_x = hero_x - heroWalk
		platform_1_x= platform_1_x - 5
		platform_2_x= platform_2_x - 5
		parallax_1_x = parallax_1_x - 2
		parallax_2_x = parallax_2_x - 1
	end
	--if direction == "up" then
		
	--end
	--if direction == "down" then
		
	--end
end

function love.keypressed(key)
	if key =="escape" or key=="q" or key=="6" then
		love.event.push("q")
	elseif key == "r" then
		love.filesystem.load("main.lua")()
	end
	
	if key =="9" or key == "a" then
		love.audio.pause(music)
	end
end

function  love.update(dt)
	
	if love.joystick.getAxis( 0, 1 ) == 1 then
		hero_y = hero_y - heroWalk

	elseif love.joystick.getAxis( 0, 1 )== -1 then
		hero_y = hero_y + heroWalk

	elseif love.joystick.getAxis( 0, 0 )==1 then
		hero_x = hero_x - heroWalk
		platform_1_x= platform_1_x - 5
		platform_2_x= platform_2_x - 5
		parallax_1_x = parallax_1_x - 2
		parallax_2_x = parallax_2_x - 1

	elseif love.joystick.getAxis( 0, 0 )==-1 then
		hero_x = hero_x + heroWalk
		platform_1_x= platform_1_x + 5
		platform_2_x= platform_2_x + 5
		parallax_1_x = parallax_1_x + 2
		parallax_2_x = parallax_2_x + 1
	end

	if love.keyboard.isDown("up") then
		hero_y = hero_y - heroWalk

	elseif love.keyboard.isDown("down") then
		hero_y = hero_y + heroWalk

	end

	if love.keyboard.isDown("left") then
		--hero_x = hero_x - heroWalk
		platform_1_x= platform_1_x + 5
		platform_2_x= platform_2_x + 5
		parallax_1_x = parallax_1_x + 2
		parallax_2_x = parallax_2_x + 1

	elseif love.keyboard.isDown("right") then
		--hero_x = hero_x + heroWalk
		platform_1_x= platform_1_x - 5
		platform_2_x= platform_2_x - 5
		parallax_1_x = parallax_1_x - 2
		parallax_2_x = parallax_2_x - 1
	end
	
	if platform_1_x < -320 then
		platform_1_x = 320
	end	
	if platform_2_x < -320 then
		platform_2_x = 320
	end	
	if parallax_1_x < -320 then
		parallax_1_x = 320
	end	
	if parallax_2_x < -320 then
		parallax_2_x = 320
	end
	
end

function love.draw()
	love.graphics.draw(parallax_layer_1, parallax_1_x, parallax_1_y, 0, 1, 1, 0, 0)	
	love.graphics.draw(parallax_layer_2, parallax_2_x, parallax_2_y, 0, 1, 1, 0, 0)

	love.graphics.draw(level_1_platform_1,platform_1_x, platform_1_y, 0, 1, 1, 0, 0)
	love.graphics.draw(level_1_platform_2,platform_2_x, platform_2_y, 0, 1, 1, 0, 0)

	love.graphics.draw(hero, hero_x, hero_y, 0, 1, 1, 128, 64)	
	--love.graphics.print("fps: " .. love.timer.getFPS(), 135, 120)	
	--love.graphics.print("fps: " .. , 145, 135)
end
 
well i cant help you, sorry. asking at the http://love2d.org/forums/ will definitely help more i guess :)
 
Back
Top