Page 1 of 1
Help Needed: Player Art and Animation
Posted: Sun Nov 25, 2012 4:46 am
by GalacticPixelStudios
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
Re: Help Needed: Player Art and Animation
Posted: Sun Nov 25, 2012 8:13 pm
by qaisjp
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.
Re: Help Needed: Player Art and Animation
Posted: Mon Nov 26, 2012 12:14 am
by GalacticPixelStudios
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
Re: Help Needed: Player Art and Animation
Posted: Mon Nov 26, 2012 5:22 pm
by qaisjp
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
Re: Help Needed: Player Art and Animation
Posted: Mon Nov 26, 2012 7:14 pm
by Nixola
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
Re: Help Needed: Player Art and Animation
Posted: Mon Nov 26, 2012 9:35 pm
by GalacticPixelStudios
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