newWorld - what units does it use?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

newWorld - what units does it use?

Post by Sslaxx »

Now, http://love2d.org/docs/love_physics_newWorld_1.html mentions width and height, but my question is quite simple - is this in pixels or is it in Box2D units?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: newWorld - what units does it use?

Post by bartbes »

Whatever you chose, though by default scaling is enabled, allowing you to use pixels.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: newWorld - what units does it use?

Post by Robin »

I believe the default unit is 1/30 of a meter.
Help us help you: attach a .love.
User avatar
Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Re: newWorld - what units does it use?

Post by Sslaxx »

In other words, it uses Box2D units? So, if I had a fixed screen res of 800x600, and a unit size of 64pixels-per-metre, then love.physics.newWorld (800/64, 600/64) would be correct?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: newWorld - what units does it use?

Post by Robin »

Sslaxx wrote:In other words, it uses Box2D units? So, if I had a fixed screen res of 800x600, and a unit size of 64pixels-per-metre, then love.physics.newWorld (800/64, 600/64) would be correct?
Nope, the default is 1/30th of a Box2D unit (B2D unit = meter). That makes it easier to avoid twiddling with scaling, and just say "a LÖVE unit equals one pixel on screen, thus 30 pixels = 1 meter".

Code: Select all

pixels <-> your own drawing scale <-> LÖVE units <-> World:getMeter() <-> Box2D units
So if you draw a 300 pixel image 1:1, and use the default of 30px/m, you use a shape of size:

Code: Select all

300px -> *1 -> 300px -> /30 -> 10 meter
Your specific question:
Sslaxx wrote:So, if I had a fixed screen res of 800x600, and a unit size of 64pixels-per-metre, then love.physics.newWorld (800/64, 600/64) would be correct?
That depents what "unit size" means. Is it World:setMeter(64)? Then, yes.
Help us help you: attach a .love.
User avatar
Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Re: newWorld - what units does it use?

Post by Sslaxx »

I see an issue, or I think I do.

A new world object is created at a scale of 30px-per-metre, yes? So if I were to create a world using love.physics.newWorld (800/30, 600/30) and were then to rescale that world to, say, 64 pixels, what would happen to the scale of that world?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: newWorld - what units does it use?

Post by Robin »

Sslaxx wrote:I see an issue, or I think I do.

A new world object is created at a scale of 30px-per-metre, yes? So if I were to create a world using love.physics.newWorld (800/30, 600/30) and were then to rescale that world to, say, 64 pixels, what would happen to the scale of that world?
I don't think setting the scale changes anything. You usually set the scale of the world only once, right after creating the world, which would result this:

Code: Select all

w = love.physics.newWorld (800/30, 600/30)
w:setMeter(64)
You wouldn't do that. So I don't think there is an issue. If you still think there is, please show me what it is exactly.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests