ли интеграция box2d в andengine требует дополнительных jar-файлов кроме libandenginephysicsbox2dextension.so - PullRequest
1 голос
/ 30 марта 2012

Я использую следующий код, просто чтобы нарисовать спрайт и установить границы экрана. И к этому спрайту я создаю тело и добавил определение тела к телу. А затем я использовал физический соединитель для объединения спрайта. и тело. Но я не могу видеть, как тело движется. В результате я получаю только спрайт на экране, но тело и его свойства не были интегрированы в спрайт. Может кто-нибудь пройти код, который я написал, и поправьте меня Я следовал всем правилам, доступным в примерах,

public class BallGameWithAndEngineActivity extends BaseGameActivity 
{
public static final int CAMERA_WIDTH = 800;
public static final int CAMERA_HEIGHT = 480;
private TextureRegion mBoxFaceTextureRegion;
private BitmapTexture mBitmapTexture;
private Body mGroundBody;
private PhysicsWorld mPhysicsWorld;
private Scene mScene;
private ZoomCamera camera;
public static float maxZoom = 4;
public static float minZoom = 0.4f;
public static float minX = 200;
public static float maxX = 200;
public static float minY = 200;
public static float maxY = 200;
@Override
public void onLoadComplete() 
{
}
@Override
public Engine onLoadEngine() {
this.camera = new ZoomCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);        
camera.setBounds(0 - minX, CAMERA_WIDTH + minX, 0 - minY, CAMERA_HEIGHT + maxY); 
this.camera.setBoundsEnabled(true);
final EngineOptions engineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), camera);
engineOptions.getTouchOptions().setRunOnUpdateThread(true);
Engine engine = new Engine(engineOptions);
try 
{
if (MultiTouch.isSupported(this)) {
engine.setTouchController(new MultiTouchController());
} 
else 
{
Toast.makeText(this,"Sorry your device does NOT support MultiTouch!\n\n(No  
PinchZoom is possible!)",Toast.LENGTH_LONG).show();
}
} 
catch (final MultiTouchException e) {
Toast.makeText(this,"Sorry your Android Version does NOT support MultiTouch!\n\n(No 
PinchZoom is possible!)",Toast.LENGTH_LONG).show();
}
return engine;
}
@Override
public void onLoadResources() {
BitmapTextureRegionFactory.setAssetBasePath("gfx/");
this.mBitmapTexture = new BitmapTexture(1024, 256,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mBoxFaceTextureRegion = BitmapTextureRegionFactory
.createFromAsset(this.mBitmapTexture, this, "face_box.png", 0,0);
this.mEngine.getTextureManager().loadTexture(this.mBitmapTexture);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,
SensorManager.GRAVITY_EARTH), false);
}
@Override
public Scene onLoadScene() 
{
final Sprite face;
final Body body;
this.mScene = new Scene();
this.mScene.setBackground(new ColorBackground(0, 0, 0));
this.mGroundBody = this.mPhysicsWorld.createBody(new BodyDef());
FixtureDef FIXTURE_DEF = PhysicsFactory
.createFixtureDef(1, 0.3f, 0.7f);
face = new Sprite(100, 100, this.mBoxFaceTextureRegion);
body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face,
BodyType.DynamicBody, FIXTURE_DEF);
face.setUserData(body);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face,
body, true, true));
final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH,
2);
final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0,
0.5f);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
BodyType.StaticBody, wallFixtureDef);
this.mScene.attachChild(ground);
this.mScene.attachChild(roof);
this.mScene.attachChild(left);
this.mScene.attachChild(right);
this.mScene.attachChild(face);
final PhysicsHandler physicsHandler = new PhysicsHandler(face);
face.registerUpdateHandler(physicsHandler);
this.mScene.registerTouchArea(face);
return this.mScene;
}
}
...