How to change player image?

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.
YoungProgrammer
Prole
Posts: 3
Joined: Wed Jan 08, 2014 10:52 am

How to change player image?

Post 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.

Image

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.
Frostbite.love
.love file.
(3.86 MiB) Downloaded 151 times
Frostbite.zip
.zip file.
(3.86 MiB) Downloaded 138 times
Last edited by YoungProgrammer on Wed Jan 08, 2014 12:49 pm, edited 1 time in total.
User avatar
norubal
Party member
Posts: 137
Joined: Tue Jan 15, 2013 5:55 am

Re: How to change player image?

Post 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!
YoungProgrammer
Prole
Posts: 3
Joined: Wed Jan 08, 2014 10:52 am

Re: How to change player image?

Post by YoungProgrammer »

norubal wrote: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!
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.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: How to change player image?

Post 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.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: How to change player image?

Post 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.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: How to change player image?

Post 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
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: How to change player image?

Post by Doctory »

I read minds!

You are re-making Vlambeer's Super Crate Box!
YoungProgrammer
Prole
Posts: 3
Joined: Wed Jan 08, 2014 10:52 am

Re: How to change player image?

Post 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.
User avatar
Fayer
Prole
Posts: 26
Joined: Tue Jan 07, 2014 5:48 pm
Location: Mexico City

Re: How to change player image?

Post by Fayer »

Hey YoungProgrammer, how did you manage to do math.clamp() ? When I do that love2D throws an error.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How to change player image?

Post 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))
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests