Page 1 of 1
Help with Changing a sprite using quads and love.update
Posted: Wed Oct 26, 2011 3:37 pm
by Benni88
Hello,
I'm just in the process of trying to create my first game and im attempting to move the character along the x-axis and changing the sprite to indicate direction with each love.keyboard.isDown. I've set up a quad with different orientations of my character sprite using a technique i saw in a tutorial (
https://github.com/kikito/love-tile-tutorial/wiki) but i am getting errors regarding which function to use in the love.update. If i use graphics.draw i get an error saying that im using the incorrect parameter, and i get a different error when trying to draw from the quad using love.drawq.
Attached is my .love file.
I'd greatly appreciate any help anyone could give, perhaps aswell as an explanation as to why it is incorrect? (my last post was answered so clearly!).
Many thanks,
Ben
Re: Help with Changing a sprite using quads and love.update
Posted: Wed Oct 26, 2011 4:08 pm
by tentus
1: Delete the ".lua" extension from your requires, bartbes changed the way that require will work in future versions of Love.
2: Don't call love.graphics.draw from love.update or any contained functions. Call love.graphics.draw from love.draw.
3: You're going to want to add max/min checks to your movement function. That is to say, make sure that if the player orientation dips below 1, it gets changed to 4, and vice versa.
Re: Help with Changing a sprite using quads and love.update
Posted: Wed Oct 26, 2011 4:12 pm
by adnzzzzZ
There a few things that you got wrong, I think:
If you want to draw quads you'll need to use love.graphics.drawq in line 21.
Code: Select all
function love.draw()
love.graphics.draw(Background,0,0)
love.graphics.drawq(Char_Image, Player_Image, Player_x, Player_y)
end
You don't need to redraw the image in the movement function, you only need to change Player_Image and then when you call love.graphics.drawq(Char_Image, Player_Image, Player_x, Player_y) the correct quad will be drawn.
Code: Select all
function movement()
if love.keyboard.isDown("left") then
Player_Image = Char_Orientation[2]
Player_x = (Player_x - 1)
elseif love.keyboard.isDown("right") then
Player_Image = Char_Orientation[4]
Player_x = (Player_x + 1)
end
end
And the most important thing: you are defining Player_{image, x, y} as locals and then redefining Player_{x, y} inside love.draw. You only need to define them once in love.load (not as locals) and then change them in the rest of your program.
Code: Select all
...
Player_Image = Char_Orientation[1]
Player_x = 50
Player_y = 210
end
Re: Help with Changing a sprite using quads and love.update
Posted: Thu Oct 27, 2011 9:26 am
by Benni88
Thanks very much for your answers guys. Very helpful.
Re: Help with Changing a sprite using quads and love.update
Posted: Thu Oct 27, 2011 3:56 pm
by Benni88
Hi guys. I followed your advice and got my character sprite changing and moving in a satisfactory manner, however when i tried to use the same approach (love.graphics.drawq) for an enemy sprite I'm getting the same Love error (Incorrect parameter type: expected Image). I don't understand why it doesnt work as I've used the same method and reviewed what i've written so far and it seems to be correct.
The image file i'm using is only split into 2 different sprites, would this have an impact?
Attached is a fresh copy of my .love.
Thanks if any of you can spare some time.
Re: Help with Changing a sprite using quads and love.update
Posted: Thu Oct 27, 2011 8:58 pm
by miko
Benni88 wrote:
I don't understand why it doesnt work as I've used the same method and reviewed what i've written so far and it seems to be correct.
Change this:
Code: Select all
love.graphics.drawq(Char_Image,Player_Image, Player_x, Player_y)
love.graphics.drawq(Enemy_Image,Enemy_Image, Enemy_x, Enemy_y)
to this:
Code: Select all
love.graphics.drawq(Char_Image,Player_Image, Player_x, Player_y)
love.graphics.drawq(Char_Image,Enemy_Image, Enemy_x, Enemy_y)
drawq() need an image as a first argument, not a quad.
Re: Help with Changing a sprite using quads and love.update
Posted: Thu Oct 27, 2011 9:03 pm
by bartbes
Looking at this, I think this could have been prevented by naming the variables properly, you're calling a Quad an Image, and that's bound to go wrong sometime (this time!).
Re: Help with Changing a sprite using quads and love.update
Posted: Fri Oct 28, 2011 9:58 am
by Benni88
thanks guys. help is greatly appreciated.