Help Needed: Player Art and Animation

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
GalacticPixelStudios
Prole
Posts: 7
Joined: Sun Nov 25, 2012 4:19 am

Help Needed: Player Art and Animation

Post by GalacticPixelStudios » Sun Nov 25, 2012 4:46 am

To start off with, I am building a top down space shooter. No, I am not trying to remake Galactica or Asteroids, its to be more of an real time, RPG, sandboxy type game.

Well, right now I am working on the player ship, and i want the ship to look the direction its heading. I have gotten the four basic directions down, however when I let go of the key, my ship disappears(because no image is being called to be drawn). How would I toggle the graphics to continuously be drawn, until a new direction key is hit.
[Now: "D"pressed = ship drawn facing right / "D"released = ship disappears | Want: "D"pressed = ship drawn facing right / "D"released = ship drawn facing right]

Also if you know of any great tutorials that will help me with player and background graphic animations please tell me :)

Thank You
-GalacticPixelStudios
-GalacticPixelStudios

User avatar
qaisjp
Party member
Posts: 489
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Help Needed: Player Art and Animation

Post by qaisjp » Sun Nov 25, 2012 8:13 pm

Instead of drawing a specific thing when a key is pressed down, use love.keypressed to set a variable saying what direction the ship is going. Then in the draw callback, draw the image depending on the direction.
Lua is not an acronym.

GalacticPixelStudios
Prole
Posts: 7
Joined: Sun Nov 25, 2012 4:19 am

Re: Help Needed: Player Art and Animation

Post by GalacticPixelStudios » Mon Nov 26, 2012 12:14 am

I've built a system similar to what you suggested(well I'm assuming so). from looking at the code, it seems like it would work, but all I've got was the player image stuck in top left corner. I've checked my spelling and checked if I place the functions in there needed places. Is there something I missed, or anything that is wrong that needs to be fixed? The code of my player.lua draw system should be listed bellow:

Code: Select all

orientation = {}
orientation[1] = love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y)
orientation[2] =  love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y + 30 ,math.rad(270))
orientation[3] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 32 , player.y + 30, math.rad(180))
orientation[4] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 30, player.y - 2, math.rad(90))

player.plet = 1
player.pic = orientation[1]

function player_draw()
	love.graphics.setColor(255, 255, 255, 255)
	if love.keyboard.isDown("w") then
		player.pic = orientation[player.plet]
		player.plet = 1	
		love.graphics.draw(player.pic)
	end
	if love.keyboard.isDown("a") then
		player.pic = orientation[player.plet]
		player.plet = 2
		love.graphics.draw(player.pic)
	end
	if love.keyboard.isDown("s") then
		player.pic = orientation[player.plet]
		player.plet = 3
		love.graphics.draw(player.pic)
	end
	if love.keyboard.isDown("d")  then
		player.pic = orientation[player.plet]
		player.plet = 4
		love.graphics.draw(player.pic)
	end
end
-GalacticPixelStudios

User avatar
qaisjp
Party member
Posts: 489
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Help Needed: Player Art and Animation

Post by qaisjp » Mon Nov 26, 2012 5:22 pm

now you've provided code, i'll fix your code, use this code instead (untested):

Code: Select all

orientation = {}
orientation[1] = love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y)
orientation[2] =  love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y + 30 ,math.rad(270))
orientation[3] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 32 , player.y + 30, math.rad(180))
orientation[4] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 30, player.y - 2, math.rad(90))

player.plet = 1

function player_draw()
	love.graphics.setColor(255, 255, 255, 255)
        love.graphics.draw( orientation[player.plet] or orientation[1] )
end

function love.keypressed(key)
       local t = { w=1, a=2, s=3, d=4 }
       player.plet = t[key] or player.plet
end
Lua is not an acronym.

User avatar
Nixola
Inner party member
Posts: 1940
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Help Needed: Player Art and Animation

Post by Nixola » Mon Nov 26, 2012 7:14 pm

qaisjp wrote:now you've provided code, i'll fix your code, use this code instead (untested):

Code: Select all

orientation = {}
orientation[1] = love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y)
orientation[2] =  love.graphics.newImage("textures/CryonCargoShip.png", player.x, player.y + 30 ,math.rad(270))
orientation[3] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 32 , player.y + 30, math.rad(180))
orientation[4] = love.graphics.newImage("textures/CryonCargoShip.png", player.x + 30, player.y - 2, math.rad(90))

player.plet = 1

function player_draw()
	love.graphics.setColor(255, 255, 255, 255)
        love.graphics.draw( orientation[player.plet] or orientation[1] )
end

function love.keypressed(key)
       local t = { w=1, a=2, s=3, d=4 }
       player.plet = t[key] or player.plet
end
newImage doesn't work like this.
Check out love.graphics.newImage and love.graphics.draw
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

GalacticPixelStudios
Prole
Posts: 7
Joined: Sun Nov 25, 2012 4:19 am

Re: Help Needed: Player Art and Animation

Post by GalacticPixelStudios » Mon Nov 26, 2012 9:35 pm

Oh hahaha, Thanks Nixola, that flew right past me when i was rewriting the code xD
and qaisjp thanks for the rewritten code ill test it out imeiately :)
-GalacticPixelStudios

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests