2 개의 볼이 움직이고 하나는 정적 (움직이지 않음) 인 데모 응용 프로그램을 만들고 있습니다. 난 그냥 두 사람이 런타임에 충돌 싶어요. 내가 코드이 줄을 업데이트 위치 진정한를 적용 할 때하지만 내 움직이는 물체는 움직이지 :움직이는 공을 움직이는 공에 어떻게 적용합니까? AndEngine
this.mPhysicsWorld.registerPhysicsConnector (새 PhysicsConnector (공, 거짓 몸, TRUE));
여기 우는 소리가 런타임 이미지이지만, 모두 충돌하지 않는 내 코드
public class DizyBall extends SimpleBaseGameActivity implements IOnSceneTouchListener {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 740;
private static final int CAMERA_HEIGHT = 480;
private static final float DEMO_VELOCITY = 150.0f;
// ===========================================================
// Fields
// ===========================================================
private Scene mScene;
private PhysicsWorld mPhysicsWorld;
private Body body;
private FixtureDef objectFixtureDef ;
private BitmapTextureAtlas mBitmapTextureAtlas;
private TiledTextureRegion mFaceTextureRegion;
private TextureRegion mColiTextureRegion;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, DizyBall.CAMERA_WIDTH, DizyBall.CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(DizyBall.CAMERA_WIDTH, DizyBall.CAMERA_HEIGHT), camera);
}
@Override
public void onCreateResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 48, 48, TextureOptions.BILINEAR);
this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "ball.png", 0, 0, 1, 1);
this.mColiTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ball.png",0,0);
this.mBitmapTextureAtlas.load();
}
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
mScene = new Scene();
mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
mScene.setOnSceneTouchListener(this);
objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 3, 2);
final float centerX = (DizyBall.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth())/2;
final float centerY = (DizyBall.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight())/2;
final Sprite Coli = new Sprite(centerX, centerY, this.mColiTextureRegion, this.getVertexBufferObjectManager());
body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, Coli, BodyType.DynamicBody, objectFixtureDef);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(Coli, body, true, true));
mScene.attachChild(Coli);
this.mScene.registerUpdateHandler(this.mPhysicsWorld);
return mScene;
}
// ===========================================================
// Methods
// ===========================================================
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
// pSceneTouchEvent
if(this.mPhysicsWorld != null) {
if(pSceneTouchEvent.isActionUp()){
final Ball ball = new Ball(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), this.mFaceTextureRegion, this.getVertexBufferObjectManager());
body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, ball, BodyType.DynamicBody, objectFixtureDef);
this.mScene.attachChild(ball);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(ball, body, false, true));
return false;
}
}else{
Log.v("PhysicsWorld","NULL");
}
return false;
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
private static class Ball extends AnimatedSprite {
private final PhysicsHandler mPhysicsHandler;
public Ball(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.mPhysicsHandler = new PhysicsHandler(this);
this.registerUpdateHandler(this.mPhysicsHandler);
this.mPhysicsHandler.setVelocity(DizyBall.DEMO_VELOCITY, DizyBall.DEMO_VELOCITY);
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
if(this.mX < 0) {
this.mPhysicsHandler.setVelocityX(DizyBall.DEMO_VELOCITY);
} else if(this.mX + this.getWidth() > DizyBall.CAMERA_WIDTH) {
this.mPhysicsHandler.setVelocityX(-DizyBall.DEMO_VELOCITY);
}
if(this.mY < 0) {
this.mPhysicsHandler.setVelocityY(DizyBall.DEMO_VELOCITY);
} else if(this.mY + this.getHeight() > DizyBall.CAMERA_HEIGHT) {
this.mPhysicsHandler.setVelocityY(-DizyBall.DEMO_VELOCITY);
}
super.onManagedUpdate(pSecondsElapsed);
}
}
}
입니다.
이 줄을 주석 처리 할 때 터치됩니다. this.registerUpdateHandler (this.mPhysicsHandler); ../ –
그것은이 질문에 현상금을 넣기 전에 많은 연구를하지 못했던 것처럼 보입니다. –
나는 신축성 1을 사용하여 같은 속도로 튀었고 body.setLinearVelocity (10,10); 너무. 그러나 중력 때문에 잘 움직이지 않는 것은 각성하지 않는 것을 의미합니다. –