<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Understanding pixels and meters with Box2D and how to select an object with mouse &#8211; part 2</title>
	<atom:link href="http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Sat, 11 Feb 2012 05:27:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Nick</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-671229</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Mon, 01 Nov 2010 18:47:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-671229</guid>
		<description>REALLY REALLY happy to get that working, thank you so much: ) (your demo on the website doesn&#039;t work as well as the one in the download for me)

THANK YOU : )</description>
		<content:encoded><![CDATA[<p>REALLY REALLY happy to get that working, thank you so much: ) (your demo on the website doesn&#8217;t work as well as the one in the download for me)</p>
<p>THANK YOU : )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jo paul</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-530929</link>
		<dc:creator>jo paul</dc:creator>
		<pubDate>Tue, 15 Dec 2009 05:43:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-530929</guid>
		<description>i found that box2d world actually works in pixel units.

;==================================================
var worldAABB: b2AABB = new b2AABB ();
worldAABB.lowerBound.Set (0, 0);
worldAABB.upperBound.Set (stage.stageWidth, stage.stageHeight);
_b2World = new b2World (worldAABB, new b2Vec2 (0.0, 10), true);

// debug draw start
var m_sprite:Sprite;
m_sprite = new Sprite();
addChild(m_sprite);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
var dbgSprite:Sprite = new Sprite();
m_sprite.addChild(dbgSprite);
dbgDraw.m_sprite=m_sprite;
dbgDraw.m_drawScale=1;
dbgDraw.m_alpha=1;
dbgDraw.m_fillAlpha=0.5;
dbgDraw.m_lineThickness=1;
dbgDraw.m_drawFlags=0xFFFFFFFF;			_b2World.SetDebugDraw(dbgDraw);

//flash stage
var mcCircle: Sprite = new McCircle();//McCircle is a movie clip in the library identified as McCircle
mcCircle.width = 100;
mcCircle.height = 100;
mcCircle.x = 100;
mcCircle.y = 100;
addChild (mcCircle);

//box2d world
var rect: Rectangle = mcCircle.getBounds (mcCircle);
var circleDef: b2CircleDef = new b2CircleDef ();
circleDef.radius = rect.width / 2;
circleDef.density = 1;
circleDef.friction = 0.5;
circleDef.restitution = 1.1;

var bodyDef: b2BodyDef  = new b2BodyDef ();
bodyDef.position.Set (mcCircle.x, mcCircle.y);
bodyDef.angle = mc.rotation * (Math.PI / 180);
bodyDef.userData = mcCircle;

var body: b2Body = _b2World.CreateBody (bodyDef);
body.CreateShape (circleDef);
body.SetMassFromShapes ();
;==================================================





but...calculations from box2d tend to be really slow when its units are set to 1:1 pixel ratio.
what i do is simply scale all units when inputing into box2d world...then i scale them all up when translating back to flash stage.

e.g.:
;==================================================
var _scale: Number = 0.1
var worldAABB: b2AABB = new b2AABB ();
worldAABB.lowerBound.Set (0, 0);
worldAABB.upperBound.Set (stage.stageWidth * _scale, stage.stageHeight * _scale);
_b2World = new b2World (worldAABB, new b2Vec2 (0.0, 10), true);

// debug draw start
var m_sprite:Sprite;
m_sprite = new Sprite();
addChild(m_sprite);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
var dbgSprite:Sprite = new Sprite();
m_sprite.addChild(dbgSprite);
dbgDraw.m_sprite=m_sprite;
dbgDraw.m_drawScale=1/_scale;
dbgDraw.m_alpha=1;
dbgDraw.m_fillAlpha=0.5;
dbgDraw.m_lineThickness=1;
dbgDraw.m_drawFlags=0xFFFFFFFF;			_b2World.SetDebugDraw(dbgDraw);

;and...

;...
circleDef.radius = rect.width / 2 * _scale;
;...
bodyDef.position.Set (mcCircle.x * _scale, mcCircle.y * _scale);
;...
;==================================================</description>
		<content:encoded><![CDATA[<p>i found that box2d world actually works in pixel units.</p>
<p>;==================================================<br />
var worldAABB: b2AABB = new b2AABB ();<br />
worldAABB.lowerBound.Set (0, 0);<br />
worldAABB.upperBound.Set (stage.stageWidth, stage.stageHeight);<br />
_b2World = new b2World (worldAABB, new b2Vec2 (0.0, 10), true);</p>
<p>// debug draw start<br />
var m_sprite:Sprite;<br />
m_sprite = new Sprite();<br />
addChild(m_sprite);<br />
var dbgDraw:b2DebugDraw = new b2DebugDraw();<br />
var dbgSprite:Sprite = new Sprite();<br />
m_sprite.addChild(dbgSprite);<br />
dbgDraw.m_sprite=m_sprite;<br />
dbgDraw.m_drawScale=1;<br />
dbgDraw.m_alpha=1;<br />
dbgDraw.m_fillAlpha=0.5;<br />
dbgDraw.m_lineThickness=1;<br />
dbgDraw.m_drawFlags=0xFFFFFFFF;			_b2World.SetDebugDraw(dbgDraw);</p>
<p>//flash stage<br />
var mcCircle: Sprite = new McCircle();//McCircle is a movie clip in the library identified as McCircle<br />
mcCircle.width = 100;<br />
mcCircle.height = 100;<br />
mcCircle.x = 100;<br />
mcCircle.y = 100;<br />
addChild (mcCircle);</p>
<p>//box2d world<br />
var rect: Rectangle = mcCircle.getBounds (mcCircle);<br />
var circleDef: b2CircleDef = new b2CircleDef ();<br />
circleDef.radius = rect.width / 2;<br />
circleDef.density = 1;<br />
circleDef.friction = 0.5;<br />
circleDef.restitution = 1.1;</p>
<p>var bodyDef: b2BodyDef  = new b2BodyDef ();<br />
bodyDef.position.Set (mcCircle.x, mcCircle.y);<br />
bodyDef.angle = mc.rotation * (Math.PI / 180);<br />
bodyDef.userData = mcCircle;</p>
<p>var body: b2Body = _b2World.CreateBody (bodyDef);<br />
body.CreateShape (circleDef);<br />
body.SetMassFromShapes ();<br />
;==================================================</p>
<p>but&#8230;calculations from box2d tend to be really slow when its units are set to 1:1 pixel ratio.<br />
what i do is simply scale all units when inputing into box2d world&#8230;then i scale them all up when translating back to flash stage.</p>
<p>e.g.:<br />
;==================================================<br />
var _scale: Number = 0.1<br />
var worldAABB: b2AABB = new b2AABB ();<br />
worldAABB.lowerBound.Set (0, 0);<br />
worldAABB.upperBound.Set (stage.stageWidth * _scale, stage.stageHeight * _scale);<br />
_b2World = new b2World (worldAABB, new b2Vec2 (0.0, 10), true);</p>
<p>// debug draw start<br />
var m_sprite:Sprite;<br />
m_sprite = new Sprite();<br />
addChild(m_sprite);<br />
var dbgDraw:b2DebugDraw = new b2DebugDraw();<br />
var dbgSprite:Sprite = new Sprite();<br />
m_sprite.addChild(dbgSprite);<br />
dbgDraw.m_sprite=m_sprite;<br />
dbgDraw.m_drawScale=1/_scale;<br />
dbgDraw.m_alpha=1;<br />
dbgDraw.m_fillAlpha=0.5;<br />
dbgDraw.m_lineThickness=1;<br />
dbgDraw.m_drawFlags=0xFFFFFFFF;			_b2World.SetDebugDraw(dbgDraw);</p>
<p>;and&#8230;</p>
<p>;&#8230;<br />
circleDef.radius = rect.width / 2 * _scale;<br />
;&#8230;<br />
bodyDef.position.Set (mcCircle.x * _scale, mcCircle.y * _scale);<br />
;&#8230;<br />
;==================================================</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Box2D: tutorial for the absolute beginners : Emanuele Feronato</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-379057</link>
		<dc:creator>Box2D: tutorial for the absolute beginners : Emanuele Feronato</dc:creator>
		<pubDate>Tue, 27 Jan 2009 21:39:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-379057</guid>
		<description>[...] Lines 15-16 : Defining the upper and lower corners of the environment bounding box, in meters. 1 meter = 30 pixels. So our box has sides made by 6000 pixels. They&#8217;re pretty too much for a single-screen project, but if you are using scrolling, it could be useful to set up a big environment. For more information about pixels and meters refer to Understanding pixels and meters with Box2D and how to select an object with mouse - part 2. [...]</description>
		<content:encoded><![CDATA[<p>[...] Lines 15-16 : Defining the upper and lower corners of the environment bounding box, in meters. 1 meter = 30 pixels. So our box has sides made by 6000 pixels. They&#8217;re pretty too much for a single-screen project, but if you are using scrolling, it could be useful to set up a big environment. For more information about pixels and meters refer to Understanding pixels and meters with Box2D and how to select an object with mouse &#8211; part 2. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Understanding custom polygons in Box2D : Emanuele Feronato</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-357283</link>
		<dc:creator>Understanding custom polygons in Box2D : Emanuele Feronato</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-357283</guid>
		<description>[...] of the yet-to-be-created polygon, I am placing the vertex one unit (a meter, in this case, refer to Understanding pixels and meters with Box2D and how to select an object with mouse - part 2 for more information) above it. The 0 represents the horizontal distance from the center (positive: [...]</description>
		<content:encoded><![CDATA[<p>[...] of the yet-to-be-created polygon, I am placing the vertex one unit (a meter, in this case, refer to Understanding pixels and meters with Box2D and how to select an object with mouse &#8211; part 2 for more information) above it. The 0 represents the horizontal distance from the center (positive: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Understanding Box2D debug draw : Emanuele Feronato</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-351495</link>
		<dc:creator>Understanding Box2D debug draw : Emanuele Feronato</dc:creator>
		<pubDate>Wed, 10 Dec 2008 14:23:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-351495</guid>
		<description>[...] (line 29) sets the drawing scale of the rendering. As seen in Understanding pixels and meters with Box2D and how to select an object with mouse - part 2, one meter is equal to 30 pixels, so setting m_drawscale to 30 allows me to use pixel [...]</description>
		<content:encoded><![CDATA[<p>[...] (line 29) sets the drawing scale of the rendering. As seen in Understanding pixels and meters with Box2D and how to select an object with mouse &#8211; part 2, one meter is equal to 30 pixels, so setting m_drawscale to 30 allows me to use pixel [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dragging objects with Box2D Flash : Emanuele Feronato</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-339798</link>
		<dc:creator>Dragging objects with Box2D Flash : Emanuele Feronato</dc:creator>
		<pubDate>Thu, 20 Nov 2008 17:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-339798</guid>
		<description>[...] is ideally the next part after Understanding pixels and meters with Box2D and how to select an object with mouse - part 2, but it&#039;s so important understanding how to drag objects with Box2D that I decided to change the [...]</description>
		<content:encoded><![CDATA[<p>[...] is ideally the next part after Understanding pixels and meters with Box2D and how to select an object with mouse &#8211; part 2, but it&#8217;s so important understanding how to drag objects with Box2D that I decided to change the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anlik</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-337767</link>
		<dc:creator>anlik</dc:creator>
		<pubDate>Tue, 18 Nov 2008 11:19:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-337767</guid>
		<description>I am studying your tutorial, it is great,thanks to your good work.</description>
		<content:encoded><![CDATA[<p>I am studying your tutorial, it is great,thanks to your good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anlik</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-337766</link>
		<dc:creator>anlik</dc:creator>
		<pubDate>Tue, 18 Nov 2008 11:17:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-337766</guid>
		<description>Sirï¼Œif i make a flash game with two different language version(two .swf file but same game content),then what will happen?
A.Can I get two Mochi ID?
B.I have to use one Mochi ID in one version,and the other one is unuseful
Please tell me:)
Thanks</description>
		<content:encoded><![CDATA[<p>Sirï¼Œif i make a flash game with two different language version(two .swf file but same game content),then what will happen?<br />
A.Can I get two Mochi ID?<br />
B.I have to use one Mochi ID in one version,and the other one is unuseful<br />
Please tell me:)<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Diam</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-337449</link>
		<dc:creator>Colin Diam</dc:creator>
		<pubDate>Tue, 18 Nov 2008 03:54:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-337449</guid>
		<description>hello Sir 
Can you please make tutorial of game like myrethia found on kongregate.com</description>
		<content:encoded><![CDATA[<p>hello Sir<br />
Can you please make tutorial of game like myrethia found on kongregate.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xavi</title>
		<link>http://www.emanueleferonato.com/2008/11/17/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-2/#comment-337007</link>
		<dc:creator>xavi</dc:creator>
		<pubDate>Mon, 17 Nov 2008 16:53:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=653#comment-337007</guid>
		<description>hey emanuele,
can you make a tutorial on how to make a game like
&#039;enless zombie rampage&#039;? (by diseased prodcutions)</description>
		<content:encoded><![CDATA[<p>hey emanuele,<br />
can you make a tutorial on how to make a game like<br />
&#8216;enless zombie rampage&#8217;? (by diseased prodcutions)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 6/11 queries in 0.014 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-11 17:43:56 -->
