2012-12-25 1 views

답변

4

가 이동 볼 예를 확인 만 나중에 클래스는 스프라이트 또는 AnimatedSprite 확장하기 당신은 X와 Y 속도에 임의 값을 설정

private static class Ball extends AnimatedSprite { 
      private final PhysicsHandler mPhysicsHandler; 
        Random randomGenerator = new Random(); 
        private float RandomX; 
        private float RandomY; 
        private int CAMERA_WIDTH=720; 
        private int CAMERA_HEIGHT=480; 
      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); 
          RandomX =randomGenerator.nextInt(3); 
          RandomY =randomGenerator.nextInt(3); 
          RandomX=RandomX*100; 
          RandomY=RandomY*100; 
       this.mPhysicsHandler.setVelocity(RandomX, RandomY); 
      } 

      @Override 
      protected void onManagedUpdate(final float pSecondsElapsed) { 
       if(this.mX < 0) { 
        this.mPhysicsHandler.setVelocityX(RandomX); 
       } else if(this.mX + this.getWidth() > CAMERA_WIDTH) { 
        this.mPhysicsHandler.setVelocityX(-RandomX); 
       } 

       if(this.mY < 0) { 
        this.mPhysicsHandler.setVelocityY(RandomY); 
       } else if(this.mY + this.getHeight() > CAMERA_HEIGHT) { 
        this.mPhysicsHandler.setVelocityY(-RandomY); 
       } 

       super.onManagedUpdate(pSecondsElapsed); 
      } 
     } 
0

당신은 "비니 DSL은"말처럼 Box2D의 사용 하나 또는 당신은 [또는 onManagedUpdated]의 onUpdate를 무시하고 자신의 x와 y 위치를 변경하여 공을 수동으로 움직일 수 여기에서

관련 문제