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.
How to change player image?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Wed Jan 08, 2014 10:52 am
How to change player image?
Last edited by YoungProgrammer on Wed Jan 08, 2014 12:49 pm, edited 1 time in total.
Re: How to change player image?
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!
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!
-
- Prole
- Posts: 3
- Joined: Wed Jan 08, 2014 10:52 am
Re: How to change player image?
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.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!
Re: How to change player image?
This is what is currently drawing your player:
You have to replace it with this:
And in love.load you need to load your character roughly like this:
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.
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)
Code: Select all
love.graphics.draw( playerImage, player.x, player.y )
Code: Select all
playerImage = love.graphics.newImage( 'nameofyourimage.png' )
Re: How to change player image?
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.
I highly suggest reading the tutorial in the wiki to understand how that works. See here. You should start with the hamster ball tutorial.
Check out my blog on gamedev
Re: How to change player image?
Make a player draw function
something like this:
and set isFacing in player:left / right
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
Re: How to change player image?
I read minds!
You are re-making Vlambeer's Super Crate Box!
You are re-making Vlambeer's Super Crate Box!
-
- Prole
- Posts: 3
- Joined: Wed Jan 08, 2014 10:52 am
Re: How to change player image?
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?
Hey YoungProgrammer, how did you manage to do math.clamp() ? When I do that love2D throws an error.
Re: How to change player image?
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: No registered users and 8 guests