I'm working on my first QuickBox2D project and I'm finding that things I thought would be hard end up being easy yet I'm having trouble with things that should be easy.
Here's what I'm dealing with here:
http://www.swfcabin.com/open/1282643768
When the ball hits the contact in the bottom right corner, I want the top left ball to appear in the launcher to the right.
Here's my code:
[SWF(width=650,height=650,frameRate=60)]
import com.actionsnippet.qbox.*;
import Box2D.Common.Math.*;
import flash.display.*;
import flash.geom.*;
import flash.events.*;
var sim:QuickBox2D=new QuickBox2D(this);
//floor
var floor:QuickObject=sim.addBox({x:8.3,y:21.6,width:16.8,height:0.1,density:0});
//roof
sim.addBox({x:8.3, y:0, width:16.6, height:0.1, density:0});
//left wall
sim.addBox({x:0, y:10.8, width:0.1, height:21.6, density:0});
//right wall
sim.addBox({x:16.6, y:10.8, width:0.1, height:21.6, density:0});
//round roof
var RCX:Number = 250/30;
var RCY:Number = 8.5;
var pNum:int = 20;
var pWidth:Number = 28/30;
var pRadius:Number = 250/30;
var roofParts:Array = new Array();
for (var i:int=1; i < pNum; i++) {
var r:Number = Math.PI/pNum*i+Math.PI;
sim.addBox({x:RCX+pRadius*Math.cos(r), y:RCY+pRadius*Math.sin(r), width:pWidth, height:4/30, angle:r+Math.PI/2, density:0, skin:dome_cover_lab});
}
//coin 2 position
[color=#0000FF]var coinTwoX:Number=.5;
var coinTwoY:Number=.5;
// coin1
var coinOne:QuickObject=sim.addCircle({x:15.6, y:12, radius:0.6, density:2, draggable:false, categoryBits:0x0002, maskBits:0x0007});
var coinTwo:QuickObject=sim.addCircle({x:coinTwoX, y:coinTwoY, radius:0.6, density:2, draggable:false, categoryBits:0x0002, maskBits:0x0007});
var machineOne:QuickObject=sim.addBox({x:.746, y:20.8, width:1.51, height:1.51, density:0, maskBits:0x0001, categoryBits:0x0002});
var boxes:Array=[];
boxes[0]=sim.addBox({x:0,y:-2.4,width:0.2,height:10,density:0, skin:blackSquare});
//stoppers
boxes[1]=sim.addBox({x:.1,y:-5,width:0.25,height:0.25,density:0, skin:blackSquare});
boxes[2]=sim.addBox({x:1.4,y:-5,width:0.25,height:0.25,density:0, skin:blackSquare});
//pull back box
sim.addGroup({x:15.2, y:19, objects:boxes});
//plunger ball
var plunger:QuickObject=sim.addCircle({x:15.6,y:14.5,radius:0.62,density:1,fixedRotation:true,friction:1});
//plunger target
var target:QuickObject=sim.addCircle({x:15.6,y:-5,radius:0.8,density:0});
sim.addJoint({a:plunger.body, b:target.body, x2:15.6, y2:0, frequencyHz:2.5, dampingRation:.5 });
//dividers
var div1:QuickObject=sim.addBox({x:1.53, y:20.6, width:.2, height:2, density:0});
var div2:QuickObject=sim.addBox({x:3.04, y:20.6, width:.2, height:2, density:0});
var div3:QuickObject=sim.addBox({x:4.56, y:20.6, width:.2, height:2, density:0});
var div4:QuickObject=sim.addBox({x:6.08, y:20.6, width:.2, height:2, density:0});
var div5:QuickObject=sim.addBox({x:7.6, y:20.6, width:.2, height:2, density:0});
var div6:QuickObject=sim.addBox({x:9.12, y:20.6, width:.2, height:2, density:0});
var div7:QuickObject=sim.addBox({x:10.64, y:20.6, width:.2, height:2, density:0});
var div8:QuickObject=sim.addBox({x:12.16, y:20.6, width:.2, height:2, density:0});
var div9:QuickObject=sim.addBox({x:13.68, y:20.6, width:.2, height:2, density:0});
//contact points
var contact1:QuickObject=sim.addBox({x:.82, y:21.635, width:1.51, height:.266, density:0});
sim.start();
sim.mouseDrag();
//contacts
var contacts:QuickContacts = sim.addContactListener();
// listen for contact points being added
contacts.addEventListener(QuickContacts.ADD, onHit);
function onHit(evt:Event):void{
// see if this contact event is associated with coin and box
if(contacts.isCurrentContact(coinOne, contact1)){
// get the location of the collision in world space
var loc:b2Vec2 = contacts.currentPoint.position;
coinOne.destroy();
//coinTwo appear
coinTwoX = 15.6;
coinTwoY = 10;
trace("hit one");
}
}
[/color]
The trace("hit one") shows up so I know the contact is being made but the changing of the coinTwo position doesn't stick.
I've tried a few ways that haven't worked and I'm guessing I'm being too Flash and not Box2D enough in dealing with it.
Any help would be appreciated.
Here's what I'm dealing with here:
http://www.swfcabin.com/open/1282643768
When the ball hits the contact in the bottom right corner, I want the top left ball to appear in the launcher to the right.
Here's my code:
[SWF(width=650,height=650,frameRate=60)]
import com.actionsnippet.qbox.*;
import Box2D.Common.Math.*;
import flash.display.*;
import flash.geom.*;
import flash.events.*;
var sim:QuickBox2D=new QuickBox2D(this);
//floor
var floor:QuickObject=sim.addBox({x:8.3,y:21.6,width:16.8,height:0.1,density:0});
//roof
sim.addBox({x:8.3, y:0, width:16.6, height:0.1, density:0});
//left wall
sim.addBox({x:0, y:10.8, width:0.1, height:21.6, density:0});
//right wall
sim.addBox({x:16.6, y:10.8, width:0.1, height:21.6, density:0});
//round roof
var RCX:Number = 250/30;
var RCY:Number = 8.5;
var pNum:int = 20;
var pWidth:Number = 28/30;
var pRadius:Number = 250/30;
var roofParts:Array = new Array();
for (var i:int=1; i < pNum; i++) {
var r:Number = Math.PI/pNum*i+Math.PI;
sim.addBox({x:RCX+pRadius*Math.cos(r), y:RCY+pRadius*Math.sin(r), width:pWidth, height:4/30, angle:r+Math.PI/2, density:0, skin:dome_cover_lab});
}
//coin 2 position
[color=#0000FF]var coinTwoX:Number=.5;
var coinTwoY:Number=.5;
// coin1
var coinOne:QuickObject=sim.addCircle({x:15.6, y:12, radius:0.6, density:2, draggable:false, categoryBits:0x0002, maskBits:0x0007});
var coinTwo:QuickObject=sim.addCircle({x:coinTwoX, y:coinTwoY, radius:0.6, density:2, draggable:false, categoryBits:0x0002, maskBits:0x0007});
var machineOne:QuickObject=sim.addBox({x:.746, y:20.8, width:1.51, height:1.51, density:0, maskBits:0x0001, categoryBits:0x0002});
var boxes:Array=[];
boxes[0]=sim.addBox({x:0,y:-2.4,width:0.2,height:10,density:0, skin:blackSquare});
//stoppers
boxes[1]=sim.addBox({x:.1,y:-5,width:0.25,height:0.25,density:0, skin:blackSquare});
boxes[2]=sim.addBox({x:1.4,y:-5,width:0.25,height:0.25,density:0, skin:blackSquare});
//pull back box
sim.addGroup({x:15.2, y:19, objects:boxes});
//plunger ball
var plunger:QuickObject=sim.addCircle({x:15.6,y:14.5,radius:0.62,density:1,fixedRotation:true,friction:1});
//plunger target
var target:QuickObject=sim.addCircle({x:15.6,y:-5,radius:0.8,density:0});
sim.addJoint({a:plunger.body, b:target.body, x2:15.6, y2:0, frequencyHz:2.5, dampingRation:.5 });
//dividers
var div1:QuickObject=sim.addBox({x:1.53, y:20.6, width:.2, height:2, density:0});
var div2:QuickObject=sim.addBox({x:3.04, y:20.6, width:.2, height:2, density:0});
var div3:QuickObject=sim.addBox({x:4.56, y:20.6, width:.2, height:2, density:0});
var div4:QuickObject=sim.addBox({x:6.08, y:20.6, width:.2, height:2, density:0});
var div5:QuickObject=sim.addBox({x:7.6, y:20.6, width:.2, height:2, density:0});
var div6:QuickObject=sim.addBox({x:9.12, y:20.6, width:.2, height:2, density:0});
var div7:QuickObject=sim.addBox({x:10.64, y:20.6, width:.2, height:2, density:0});
var div8:QuickObject=sim.addBox({x:12.16, y:20.6, width:.2, height:2, density:0});
var div9:QuickObject=sim.addBox({x:13.68, y:20.6, width:.2, height:2, density:0});
//contact points
var contact1:QuickObject=sim.addBox({x:.82, y:21.635, width:1.51, height:.266, density:0});
sim.start();
sim.mouseDrag();
//contacts
var contacts:QuickContacts = sim.addContactListener();
// listen for contact points being added
contacts.addEventListener(QuickContacts.ADD, onHit);
function onHit(evt:Event):void{
// see if this contact event is associated with coin and box
if(contacts.isCurrentContact(coinOne, contact1)){
// get the location of the collision in world space
var loc:b2Vec2 = contacts.currentPoint.position;
coinOne.destroy();
//coinTwo appear
coinTwoX = 15.6;
coinTwoY = 10;
trace("hit one");
}
}
[/color]
The trace("hit one") shows up so I know the contact is being made but the changing of the coinTwo position doesn't stick.
I've tried a few ways that haven't worked and I'm guessing I'm being too Flash and not Box2D enough in dealing with it.
Any help would be appreciated.