Hi all,
just started playing with Box2d, have been trying to adjust minVertex and maxVertex when the screen resizes,
is there a way to do this? is it possible even?
because the world is only created once...and minVertex and MaxVertex is passed as part of worldAABB
worldAABB.minVertex.Set(-1000.0, -1000.0);
worldAABB.maxVertex.Set(1000.0, 1000.0);
m_world = new b2World(worldAABB, gravity, doSleep);
i want to know how do i update the minVertex and maxVertex during a screenResize, kind of like changing the bounds that the random sprites objects are confined to.
any ideas?
thanks
Clark
You cannot edit the world AABB. Instead make it initially twice as big as it will ever need to be. This will not cause any performance problems.
hi Erin.
thanks for the super fast reply, will give it a try.
hi all,
i'm kinda new to this box2D and AS3 stuff and i happen to be stuck again...oh no..
i've been trying to do a modification of the Hello world example. basically, i've fixed up the world size
to
worldAABB.minVertex.Set(-3000, -3000);
worldAABB.maxVertex.Set(3000, 3000);
that sorts out the getting stuck part when screen resizes,
now i've made boundaries to constrain movement for shapes etc.
however i am trying to move these bounds to be that of the screen when the screen is resized.
the code for the left bound looks like this (seems the same as the examples):
//left bound
bodyDef = new b2BodyDef();
boxDef = new b2BoxDef();
boxDef.extents.Set( 50 / 2 , s.stageHeight / 2);
boxDef.density = 0;
//this positions the bounds to stage left, and height is half of its actual size??
bodyDef.position.Set(_stageHandle.getBoundLeft(), s.stageHeight/2);
bodyDef.AddShape(boxDef);
bodyDef.userData = new leftBoundMC();
bodyDef.userData.width = boxDef.extents.x * 2;
bodyDef.userData.height = boxDef.extents.y * 2;
bodyDef.userData.name = "leftBoundMC";
//trying to give a default x, y position doesnt matter, just want to be able to adjust x and y later on...
bodyDef.userData.x = 0;
bodyDef.userData.y = 0;
//add leftBoundMC from library?
s.addChild(bodyDef.userData);
Box2D_PhysicsEngineModel.m_world.CreateBody(bodyDef);
then, in a StageHandler class i have a function called everytime the stage is resized:
var targetL:DisplayObject = stage.getChildByName("leftBoundMC");
var targetR:DisplayObject = stage.getChildByName("rightBoundMC");
var targetT:DisplayObject = stage.getChildByName("topBoundMC");
var targetB:DisplayObject = stage.getChildByName("bottomBoundMC");
repositionBounds(targetL, targetR, targetT, targetB);
public function repositionBounds(targetL, targetR, targetT, targetB)
{
positionBoundLeft(targetL);
positionBoundRight(targetR);
positionBoundTop(targetT);
positionBoundBottom(targetB);
}
public function positionBoundLeft(targetL) {
//targetL.x = getBoundLeft(); does not update
targetL.scaleY = this.stage.stageHeight/100; updates the scale fine
}
i'm not sure if the bounds should be dynamic i guess not. but does that allow me to move it then?
i've attached my code in case i didnt explain myself well enough, but what i am trying to do is move the bounds always to the outermost edges, i'm thinking when the stage is resized the objects will fall a with gravity again until it hits the new y. pos of the bottomBound... currently the bounds dont move..perhaps there is a better way to achieve this?
thanks in advance.
Clark
I'm not sure what you want to happen. Do you want the movement space to expand when the display is resized? If so, you should just delete and recreate your barriers. If not, then you should just scale your rendering axes.
Hello Erin,
i thought maybe there was a easier way to move them, rather than destroy those objects and recreating it.
what i would like to achieve is that the orange box gets more space to "play with" when screen gets resized bigger
i have the blue,red,and black barriers,
and when the flash is made fullscreen, the barriers remain where they are,
i was trying to move these barriers' x and y values to also change to follow the stage when the stage gets resized.
i will give this a try tho.
thanks
Cheers