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
Help with Changing a sprite using quads and love.update
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Help with Changing a sprite using quads and love.update
- Attachments
-
- Benni's Project.love
- (2.44 KiB) Downloaded 137 times
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Help with Changing a sprite using quads and love.update
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.
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.
Kurosuke needs beta testers
Re: Help with Changing a sprite using quads and love.update
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.
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.
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.
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
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
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
Thanks very much for your answers guys. Very helpful.
Re: Help with Changing a sprite using quads and love.update
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.
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.
- Attachments
-
- Benni's Project.love
- (3.83 KiB) Downloaded 124 times
Re: Help with Changing a sprite using quads and love.update
Change this: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.
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)
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)
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Help with Changing a sprite using quads and love.update
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
thanks guys. help is greatly appreciated.
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests