Page 1 of 2
How to change player image?
Posted: Wed Jan 08, 2014 11:13 am
by YoungProgrammer
Hello, I am very new to LOVE. I have a game that i am working on and I need someone to help me change cube character in the game to the character in "sprites/player_right.png"
That blue cube in the middle needs to be replaced with my character.
Basically, I want that cube replaced with my character that i have in the "sprites folder", I have included a .zip and .love of my project to this thread. If you need any more info, just ask. And please don't be mean, this is my first post. Thanks in advance.
Re: How to change player image?
Posted: Wed Jan 08, 2014 12:09 pm
by norubal
Please attach file so we can see your project and answer! I can see only text, no link or something..
I have some links that might be help..
http://www.love2d.org/wiki/love.graphics.rectangle (blue cube seems like drawn by this function)
http://www.love2d.org/wiki/love.graphics.draw (it draws image instead of cube)
Good luck to your project!
Re: How to change player image?
Posted: Wed Jan 08, 2014 12:51 pm
by YoungProgrammer
Sorry about that project link problem. I have updated it so you can have a look at it. Thanks for the reply. And by the way, I am still unsure of how i would use love.graphics.draw in my code. I mean, I know what it does and how to use it but it is not compatible with my code. Anyways you will see when you have a look at my main.lua. Thanks again.
Re: How to change player image?
Posted: Wed Jan 08, 2014 1:19 pm
by Plu
This is what is currently drawing your player:
Code: Select all
love.graphics.setColor( 0, 0, 255)
love.graphics.rectangle("fill", player.x - player.w/2, player.y - player.h/2, player.w, player.h)
You have to replace it with this:
Code: Select all
love.graphics.draw( playerImage, player.x, player.y )
And in love.load you need to load your character roughly like this:
Code: Select all
playerImage = love.graphics.newImage( 'nameofyourimage.png' )
And it should work. At least to load the character
Making it face the right way and/or animating it will be a lot more work.
Re: How to change player image?
Posted: Wed Jan 08, 2014 1:22 pm
by micha
It will work the way Norubal explained. In the love.draw function there currently is a love.graphics.rectangle. You need to replace this by a love.graphics.draw. (Edit: I got Plu'd)
I highly suggest reading the tutorial in the wiki to understand how that works.
See here. You should start with the hamster ball tutorial.
Re: How to change player image?
Posted: Wed Jan 08, 2014 1:23 pm
by Zeliarden
Make a player draw function
something like this:
Code: Select all
function player:draw()
if self.isFacing == "left" then
love.graphics.draw( player_image_left, player.x - player.w/2, player.y - player.h)
end
if self.isFacing == "right" then
love.graphics.draw( player_image_right, player.x - player.w/2, player.y - player.h)
end
end
and set isFacing in player:left / right
Re: How to change player image?
Posted: Wed Jan 08, 2014 4:21 pm
by Doctory
I read minds!
You are re-making Vlambeer's Super Crate Box!
Re: How to change player image?
Posted: Thu Jan 09, 2014 9:37 am
by YoungProgrammer
Doctory wrote:I read minds!
You are re-making Vlambeer's Super Crate Box!
Indeed. I am even using the game's soundtrack for some testing. Nice catch.
Re: How to change player image?
Posted: Thu Jan 09, 2014 10:13 pm
by Fayer
Hey YoungProgrammer, how did you manage to do math.clamp() ? When I do that love2D throws an error.
Re: How to change player image?
Posted: Thu Jan 09, 2014 10:19 pm
by Nixola
Fayer wrote:Hey YoungProgrammer, how did you manage to do math.clamp() ? When I do that love2D throws an error.
Code: Select all
math.clamp = function(min, x max) return math.max(min, math.min(max, x))