Any help would be appreciated.
The following is the code I use to create a cross consisting of 5 bodies (top,right,bottom,left and mid).
Using java Syntax Highlighting
- gearCount++;
- Vector2[] topVertices = {
- new Vector2(-20,62),
- new Vector2(20,62),
- new Vector2(20,20),
- new Vector2(-20,20),
- };
- Vector2[] rightVertices = {
- new Vector2(20,20),
- new Vector2(62,20),
- new Vector2(62,-20),
- new Vector2(20,-20),
- };
- Vector2[] bottomVertices = {
- new Vector2(-20,-20),
- new Vector2(20,-20),
- new Vector2(20,-62),
- new Vector2(-20,-62),
- };
- Vector2[] leftVertices = {
- new Vector2(-62,20),
- new Vector2(-20,20),
- new Vector2(-20,-20),
- new Vector2(-62,-20),
- };
- Vector2[] midVertices = {
- new Vector2(-20,20),
- new Vector2(20,20),
- new Vector2(20,-20),
- new Vector2(-20,-20),
- };
- entity = new Sprite(pX,pY,pWidth,pHeight,this.gear125_125);
- entity.setUserData("gear"+gearCount);
- entity.setRotation(pRotation);
- Body top = null;
- Body left = null;
- Body bottom = null;
- Body right = null;
- Body mid = null;
- top = PhysicsFactory.createPolygonBody(mPhysicsWorld, entity, topVertices, BodyType.DynamicBody, GEAR_NORMAL_FIXTURE_DEF);
- top.setUserData("gear"+gearCount);
- mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(entity, top, true, true));
- right = PhysicsFactory.createPolygonBody(mPhysicsWorld, entity, rightVertices, BodyType.DynamicBody, GEAR_NORMAL_FIXTURE_DEF);
- right .setUserData("gear"+gearCount);
- mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(entity, right , true, true));
- bottom = PhysicsFactory.createPolygonBody(mPhysicsWorld, entity, bottomVertices, BodyType.DynamicBody, GEAR_NORMAL_FIXTURE_DEF);
- bottom.setUserData("gear"+gearCount);
- mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(entity, bottom, true, true));
- left = PhysicsFactory.createPolygonBody(mPhysicsWorld, entity, leftVertices, BodyType.DynamicBody, GEAR_NORMAL_FIXTURE_DEF);
- left.setUserData("gear"+gearCount);
- mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(entity, left, true, true));
- mid = PhysicsFactory.createPolygonBody(mPhysicsWorld, entity, midVertices, BodyType.DynamicBody, GEAR_NORMAL_FIXTURE_DEF);
- mid.setUserData("gear"+gearCount);
- mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(entity, mid, true, true));
- try{
- pScene.attachChild(entity);
- }
- catch (NullPointerException e) {
- e.printStackTrace();
- }
Parsed in 0.058 seconds, using GeSHi 1.0.8.4
