Hi there..
I'm using Tedd's box2d tutorial.. First of all I have to thank him..
Anyways, I studied it till "Chapter 25 Getting a platform to move - the wrong way"..
But I got stuck here..
Because Box2d 2.0.1 doesn't have this old codes&features anymore I think...
The code is below. It tries to move bonus object left and right repeatedly:
I can not move _body..
Can you give me any hints about what can I do?
Thank you all in advance..
I'm using Tedd's box2d tutorial.. First of all I have to thank him..
Anyways, I studied it till "Chapter 25 Getting a platform to move - the wrong way"..
But I got stuck here..
Because Box2d 2.0.1 doesn't have this old codes&features anymore I think...
The code is below. It tries to move bonus object left and right repeatedly:
Code:
package com.peggle.control
{
import Box2D.Collision.Shapes.b2PolygonShape;
import Box2D.Common.Math.b2Mat22;
import Box2D.Common.Math.b2Transform;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2FixtureDef;
import com.peggle.objects.BonusGraphic;
import com.peggle.vo.PhysicsValues;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.sampler.NewObjectSample;
/**
$(CBI)* ...
$(CBI)* @author Yasin Adatoz
$(CBI)*/
public class BonusShootActor extends Actor
{
private var RAT : int = PhysicsValues.getInstance().RATIO;
public static const BONUS_TARGET : String = "BONUS_TARGET";
private var bounds: Array = new Array();
private var yPosition : int;
private var direction :int;
public function BonusShootActor(parent: DisplayObjectContainer, leftBounds: int, rightBounds:int, yPos:int)
{
bounds = [leftBounds, rightBounds];
yPosition = yPos;
direction = 1;
var chuteGraphic: Sprite = new BonusGraphic();
parent.addChild(chuteGraphic);
var leftRampShapeDefinition : b2FixtureDef = new b2FixtureDef();
var leftRampShape : b2PolygonShape = new b2PolygonShape();
leftRampShapeDefinition.shape = leftRampShape;
var leftRampVerticesArray : Array = [new b2Vec2(-62/RAT,-9/RAT),new b2Vec2(-62/RAT,9/RAT),new b2Vec2(-84/RAT)];
leftRampShape.SetAsArray(leftRampVerticesArray, leftRampVerticesArray.length);
leftRampShapeDefinition.friction = 0.1;
leftRampShapeDefinition.restitution = 0.6;
leftRampShapeDefinition.density = 1;
var rightRampShapeDefinition : b2FixtureDef = new b2FixtureDef();
var rightRampShape : b2PolygonShape = new b2PolygonShape();
rightRampShapeDefinition.shape = rightRampShape;
var rightRampVerticesArray : Array = [new b2Vec2(61/RAT,-9/RAT),new b2Vec2(84/RAT,9/RAT),new b2Vec2(61/RAT,9/RAT)];
rightRampShape.SetAsArray(rightRampVerticesArray, rightRampVerticesArray.length);
rightRampShapeDefinition.friction = 0.1;
rightRampShapeDefinition.restitution = 0.6;
rightRampShapeDefinition.density = 1;
var centerHoleShapeDefinition : b2FixtureDef = new b2FixtureDef();
var centerHoleShape : b2PolygonShape = new b2PolygonShape();
centerHoleShapeDefinition.shape = centerHoleShape;
var centerHoleVericesArray : Array = [new b2Vec2(-62/RAT,0), new b2Vec2(61/RAT, 0), new b2Vec2(61/RAT , 8/RAT), new b2Vec2(-62/RAT, 9/RAT)];
centerHoleShape.SetAsArray(centerHoleVericesArray, centerHoleVericesArray.length);
centerHoleShapeDefinition.friction = 0.1;
centerHoleShapeDefinition.restitution = 0.6;
centerHoleShapeDefinition.density = 1;
centerHoleShapeDefinition.isSensor = true;
centerHoleShapeDefinition.userData = BonusShootActor.BONUS_TARGET;
var chuteBodyDefinition : b2BodyDef = new b2BodyDef();
chuteBodyDefinition.position.Set((((leftBounds + rightBounds) * .5) / RAT), yPos/RAT);
var chuteBody : b2Body = PhysicsValues.getInstance().world.CreateBody(chuteBodyDefinition);
chuteBody.CreateFixture(leftRampShapeDefinition);
chuteBody.CreateFixture(rightRampShapeDefinition);
chuteBody.CreateFixture(centerHoleShapeDefinition);
chuteBodyDefinition.type = b2Body.b2_kinematicBody;
super(chuteBody, chuteGraphic);
}
override public function childSpecificUpdating():void
{
if (_costume.x >= bounds[1]) {
direction = -1
}else if (_costume.x <= bounds[0]){
direction = 1;
}
var newLocationPoint : Point = new Point((_costume.x + (direction * 2)), yPosition);
// tutorial shows _body.SetXForm(b2vec2) here..
//_body.ApplyImpulse(new b2Vec2(500, 0), _body.GetWorldCenter());
//I tried to use apply impulse..
super.childSpecificUpdating();
}
}
}
{
import Box2D.Collision.Shapes.b2PolygonShape;
import Box2D.Common.Math.b2Mat22;
import Box2D.Common.Math.b2Transform;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2FixtureDef;
import com.peggle.objects.BonusGraphic;
import com.peggle.vo.PhysicsValues;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.sampler.NewObjectSample;
/**
$(CBI)* ...
$(CBI)* @author Yasin Adatoz
$(CBI)*/
public class BonusShootActor extends Actor
{
private var RAT : int = PhysicsValues.getInstance().RATIO;
public static const BONUS_TARGET : String = "BONUS_TARGET";
private var bounds: Array = new Array();
private var yPosition : int;
private var direction :int;
public function BonusShootActor(parent: DisplayObjectContainer, leftBounds: int, rightBounds:int, yPos:int)
{
bounds = [leftBounds, rightBounds];
yPosition = yPos;
direction = 1;
var chuteGraphic: Sprite = new BonusGraphic();
parent.addChild(chuteGraphic);
var leftRampShapeDefinition : b2FixtureDef = new b2FixtureDef();
var leftRampShape : b2PolygonShape = new b2PolygonShape();
leftRampShapeDefinition.shape = leftRampShape;
var leftRampVerticesArray : Array = [new b2Vec2(-62/RAT,-9/RAT),new b2Vec2(-62/RAT,9/RAT),new b2Vec2(-84/RAT)];
leftRampShape.SetAsArray(leftRampVerticesArray, leftRampVerticesArray.length);
leftRampShapeDefinition.friction = 0.1;
leftRampShapeDefinition.restitution = 0.6;
leftRampShapeDefinition.density = 1;
var rightRampShapeDefinition : b2FixtureDef = new b2FixtureDef();
var rightRampShape : b2PolygonShape = new b2PolygonShape();
rightRampShapeDefinition.shape = rightRampShape;
var rightRampVerticesArray : Array = [new b2Vec2(61/RAT,-9/RAT),new b2Vec2(84/RAT,9/RAT),new b2Vec2(61/RAT,9/RAT)];
rightRampShape.SetAsArray(rightRampVerticesArray, rightRampVerticesArray.length);
rightRampShapeDefinition.friction = 0.1;
rightRampShapeDefinition.restitution = 0.6;
rightRampShapeDefinition.density = 1;
var centerHoleShapeDefinition : b2FixtureDef = new b2FixtureDef();
var centerHoleShape : b2PolygonShape = new b2PolygonShape();
centerHoleShapeDefinition.shape = centerHoleShape;
var centerHoleVericesArray : Array = [new b2Vec2(-62/RAT,0), new b2Vec2(61/RAT, 0), new b2Vec2(61/RAT , 8/RAT), new b2Vec2(-62/RAT, 9/RAT)];
centerHoleShape.SetAsArray(centerHoleVericesArray, centerHoleVericesArray.length);
centerHoleShapeDefinition.friction = 0.1;
centerHoleShapeDefinition.restitution = 0.6;
centerHoleShapeDefinition.density = 1;
centerHoleShapeDefinition.isSensor = true;
centerHoleShapeDefinition.userData = BonusShootActor.BONUS_TARGET;
var chuteBodyDefinition : b2BodyDef = new b2BodyDef();
chuteBodyDefinition.position.Set((((leftBounds + rightBounds) * .5) / RAT), yPos/RAT);
var chuteBody : b2Body = PhysicsValues.getInstance().world.CreateBody(chuteBodyDefinition);
chuteBody.CreateFixture(leftRampShapeDefinition);
chuteBody.CreateFixture(rightRampShapeDefinition);
chuteBody.CreateFixture(centerHoleShapeDefinition);
chuteBodyDefinition.type = b2Body.b2_kinematicBody;
super(chuteBody, chuteGraphic);
}
override public function childSpecificUpdating():void
{
if (_costume.x >= bounds[1]) {
direction = -1
}else if (_costume.x <= bounds[0]){
direction = 1;
}
var newLocationPoint : Point = new Point((_costume.x + (direction * 2)), yPosition);
// tutorial shows _body.SetXForm(b2vec2) here..
//_body.ApplyImpulse(new b2Vec2(500, 0), _body.GetWorldCenter());
//I tried to use apply impulse..
super.childSpecificUpdating();
}
}
}
I can not move _body..
Can you give me any hints about what can I do?
Thank you all in advance..