Debug draw for box2d physics World

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Fri Mar 07, 2014 2:06 pm

Robin wrote:You shouldn't need to do love.graphics.setColor(255, 255, 255) before every image you draw.
Yes, only the ones you intend to be drawn with the same color as in the image file.

User avatar
tio
Citizen
Posts: 60
Joined: Thu Dec 12, 2013 1:04 pm
Location: BR BR?
Contact:

Re: Debug draw for box2d physics World

Post by tio » Fri Mar 07, 2014 2:33 pm

Azhukar wrote:
tio wrote:Well, since I don't need to take care about color (in normal circumstances) to draw sprites
Only you do, if you intend to draw your sprites in the color as you have them in your image file then you have to set the color to full white, i.e. 255,255,255 or you will start wondering why your sprites suddenly flicker when you added X feature.
When it happens, I do exactly what I did here :ultrahappy:
Robin wrote:
tio wrote:Again, if that's not the right way to do, sorry, my bad. I just found the behavior weird and thought reporting was a good idea. :nyu:
Nono, you were right, don't listen to Azukar.
Well, it's valid since Azukar did the function :crazy:
Robin wrote:You shouldn't need to do love.graphics.setColor(255, 255, 255) before every image you draw.
So I thought, since wiki doesn't cite it on love.graphics.draw.

User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Debug draw for box2d physics World

Post by OmarShehata » Fri Mar 07, 2014 3:00 pm

Azhukar wrote:
Robin wrote:You shouldn't need to do love.graphics.setColor(255, 255, 255) before every image you draw.
Yes, only the ones you intend to be drawn with the same color as in the image file.
Think of it this way.

Always taking care to keep a default state for the system removes a lot of headaches. If you have 200 draw calls in your code, 5 of which are rendered with different colors, you'd only need to setColor for those 5 sprites (a total of 10, once before the sprite and once to reset it to the default), allowing you to assume the color will always be 255,255,255 unless you explicitly change it.

There's no right or wrong way to this, as Robin mentioned, but I personally prefer assuming a default state and anything that changes it must change it back after it is done. So that I don't have to worry about resetting color and any other transformations before every draw call.

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Fri Mar 07, 2014 3:58 pm

OmarShehata wrote:Think of it this way.

Always taking care to keep a default state for the system removes a lot of headaches. If you have 200 draw calls in your code, 5 of which are rendered with different colors, you'd only need to setColor for those 5 sprites (a total of 10, once before the sprite and once to reset it to the default), allowing you to assume the color will always be 255,255,255 unless you explicitly change it.
Repeatedly setting the same state is of course bad, that was not the issue debated.
OmarShehata wrote:There's no right or wrong way to this, as Robin mentioned, but I personally prefer assuming a default state and anything that changes it must change it back after it is done. So that I don't have to worry about resetting color and any other transformations before every draw call.
When you're working with libraries from many different people with various habits, the only way to ensure correct state is to always set it the way you want it as you cannot rely on others adhering to your own habits.

User avatar
tio
Citizen
Posts: 60
Joined: Thu Dec 12, 2013 1:04 pm
Location: BR BR?
Contact:

Re: Debug draw for box2d physics World

Post by tio » Fri Mar 07, 2014 4:28 pm

Azhukar wrote:
OmarShehata wrote:Think of it this way.

Always taking care to keep a default state for the system removes a lot of headaches. If you have 200 draw calls in your code, 5 of which are rendered with different colors, you'd only need to setColor for those 5 sprites (a total of 10, once before the sprite and once to reset it to the default), allowing you to assume the color will always be 255,255,255 unless you explicitly change it.
Repeatedly setting the same state is of course bad, that was not the issue debated.
It could be, since it's a draw function o/

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Debug draw for box2d physics World

Post by Robin » Fri Mar 07, 2014 4:37 pm

Azhukar wrote:When you're working with libraries from many different people with various habits, the only way to ensure correct state is to always set it the way you want it as you cannot rely on others adhering to your own habits.
I prefer to use third party libraries that are well-behaved and don't force a particular coding style on me.

But as said, this is a matter of preference, and there isn't really an objective answer here.
Help us help you: attach a .love.

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Fri Mar 07, 2014 4:50 pm

Robin wrote:I prefer to use third party libraries that are well-behaved and don't force a particular coding style on me.

But as said, this is a matter of preference, and there isn't really an objective answer here.
It is not style preference that I'm talking about, this is basics of working with state machines. If you presume a state without checking, you will run into problems.

Acting upon an unknown state is objectively incorrect.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Debug draw for box2d physics World

Post by Robin » Fri Mar 07, 2014 6:25 pm

*Sigh*. It's still a matter of preference. You see, my preference is that each component I use has the post-condition of a single, known state (the "default" state, if you will). Therefore, the state is always known.

The ways we like to do are functionally equivalent. You may not like mine, you may feel wrong to you, you may be disgusted by it, it still doesn't make it any less correct than yours.

This discussion is as productive and meaningful as tabs vs spaces, vim vs emacs and single-spacing vs double-spacing.

Robin out.
Help us help you: attach a .love.

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Debug draw for box2d physics World

Post by Azhukar » Fri Mar 07, 2014 7:17 pm

Robin wrote:This discussion is as productive and meaningful as tabs vs spaces, vim vs emacs and single-spacing vs double-spacing.
But tabs are obviously better. :crazy:

User avatar
tio
Citizen
Posts: 60
Joined: Thu Dec 12, 2013 1:04 pm
Location: BR BR?
Contact:

Re: Debug draw for box2d physics World

Post by tio » Fri Mar 07, 2014 7:23 pm

Azhukar wrote:
Robin wrote:This discussion is as productive and meaningful as tabs vs spaces, vim vs emacs and single-spacing vs double-spacing.
But tabs are obviously better. :crazy:
And opening brackets at the same line as function definition :awesome:

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests