Page 1 of 1

need help with anim8

Posted: Tue Feb 19, 2013 12:24 am
by tomshreds
Hi!

I'm using anim8 for my animations, it's a perfect solution and I love it.

But I encountered a little problem. I'm trying to draw OVER an animation but since the animation seems to be redrawn quicker than what I draw after it... or I simply don't why but the anim8 animation gets drawn over what I draw after it programatically-wise.

For example:

self.animation:draw(self.image, x, y)
love.graphics.rectangle('fill', x, y, 300, 200)

The animation gets over the rectangle which seems illogical. Any ideas why?

Thanks!

Re: need help with anim8

Posted: Tue Feb 19, 2013 1:38 am
by scutheotaku
What are those last two arguments in your love.graphics.rectangle call for? Unless I'm missing something, the docs ( https://www.love2d.org/wiki/love.graphics.rectangle ) only show that function having 5 arguments: draw mode, x, y, width, and height. Perhaps that has something do with it?

If not that...does anim8 possibly change the draw alpha or draw color? Maybe try "resetting" those (e.g. "love.graphics.setColor( 255, 255, 255, 255)" ) between drawing the animation and the rectangle? This seems like a stretch, but I guess it's worth a try...?

EDIT:
And to clarify...are you not seeing the rectangle at all, or is it drawing underneath the animation but you can see part of it (either through transparent parts of the animation's image, or overlapping)?

Re: need help with anim8

Posted: Tue Feb 19, 2013 1:50 am
by master both
I bet, it is overlapping. Try to draw the background first and then the player by changing their position on your code.

Re: need help with anim8

Posted: Tue Feb 19, 2013 4:36 am
by tomshreds
scutheotaku wrote:What are those last two arguments in your love.graphics.rectangle call for? Unless I'm missing something, the docs ( https://www.love2d.org/wiki/love.graphics.rectangle ) only show that function having 5 arguments: draw mode, x, y, width, and height. Perhaps that has something do with it?

If not that...does anim8 possibly change the draw alpha or draw color? Maybe try "resetting" those (e.g. "love.graphics.setColor( 255, 255, 255, 255)" ) between drawing the animation and the rectangle? This seems like a stretch, but I guess it's worth a try...?

EDIT:
And to clarify...are you not seeing the rectangle at all, or is it drawing underneath the animation but you can see part of it (either through transparent parts of the animation's image, or overlapping)?
It was a typo when I wrote the example code. Yes we see the rectangle but the animation is over it.

Thanks!

Re: need help with anim8

Posted: Tue Feb 19, 2013 4:37 am
by tomshreds
master both wrote:I bet, it is overlapping. Try to draw the background first and then the player by changing their position on your code.
I don't think so since the draw order is:

- background
- player
- rectangle

:-/ Thanks

Re: need help with anim8

Posted: Tue Feb 19, 2013 4:41 am
by tomshreds
Found the bug. It's because there's multiple instance of the character on the screen. So other character gets drawn over other's bubbles.

Damn.

Re: need help with anim8

Posted: Tue Feb 19, 2013 11:52 am
by kikito
tomshreds wrote:I'm using anim8 for my animations, it's a perfect solution and I love it.
Well, thank you, you are very kind, but it's still not perfect :neko:
tomshreds wrote:Found the bug. It's because there's multiple instance of the character on the screen. So other character gets drawn over other's bubbles.
I'm glad that you found the problem. For the next time, consider uploading a .love file showing the issue, otherwise it's very difficult to know what is happening.

Re: need help with anim8

Posted: Wed Feb 20, 2013 2:49 pm
by monsieur_h
I ask it here since I'm encountering kind of the same problem:
Is there a library that implements a kind of RenderQueue? If not, what would be the best approach to make one?

Re: need help with anim8

Posted: Wed Feb 20, 2013 5:38 pm
by scutheotaku
monsieur_h wrote:I ask it here since I'm encountering kind of the same problem:
Is there a library that implements a kind of RenderQueue? If not, what would be the best approach to make one?
By that, do you mean depth sorting? e.g. you have two images. Image 1 is "closer" to the "camera" (i.e. the screen, the player) than image 2, so image 1 draws after image 2 (so that it will be on top of image 2).

If so, this may give you some ideas (though this sorts it by the images' y value...you'd want to sort it by a depth/z value):
https://www.love2d.org/wiki/Tutorial:Drawing_Order
Or this:
https://www.love2d.org/wiki/Skip_list:Drawing_Order

I also have a "draw table" with depth sorting in my framework (not a plug!). Feel free to "steal" any parts you like (you may want to read my description of the framework in the thread to understand it better/quicker): viewtopic.php?f=5&t=12238&p=73732

Re: need help with anim8

Posted: Wed Feb 20, 2013 11:17 pm
by kikito
monsieur_h wrote:I ask it here since I'm encountering kind of the same problem:
Is there a library that implements a kind of RenderQueue? If not, what would be the best approach to make one?
LÖVE makes the draw operations exactly in the order it receives them. So, if you want to make one image appear "behind" another one... you must draw it "before".

The easiest way is: put every image (or entity - whatever your "visual unit" is) in a table. Sort it using table.sort, probably with a custom function, and then parse the resulting table with a for loop, drawing every image in order.