示例#1
0
  private void addFace(final Scene pScene, final float pX, final float pY) {
    this.mFaceCount++;

    final AnimatedSprite face;
    final Body body;

    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

    if (this.mFaceCount % 2 == 0) {
      face = new AnimatedSprite(pX, pY, this.mBoxFaceTextureRegion);
      body =
          PhysicsFactory.createBoxBody(
              this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    } else {
      face = new AnimatedSprite(pX, pY, this.mCircleFaceTextureRegion);
      body =
          PhysicsFactory.createCircleBody(
              this.mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    }

    face.setUpdatePhysics(false);

    pScene.getTopLayer().addEntity(face);
    this.mPhysicsWorld.registerPhysicsConnector(
        new PhysicsConnector(face, body, true, true, false, false));
  }
  private void addFace(final float pX, final float pY) {
    final Scene scene = mEngine.getScene();

    mFaceCount++;

    final AnimatedSprite face;
    final Body body;

    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

    if (mFaceCount % 2 == 0) {
      face = new AnimatedSprite(pX, pY, mBoxFaceTextureRegion);
      body =
          PhysicsFactory.createBoxBody(mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    } else {
      face = new AnimatedSprite(pX, pY, mCircleFaceTextureRegion);
      body =
          PhysicsFactory.createCircleBody(
              mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef);
    }

    face.animate(200, true);

    scene.registerTouchArea(face);
    scene.getLastChild().attachChild(face);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));
  }
示例#3
0
  public void randomType(Scene scene, int type, BaseMSprise bigs) {
    this.type = type;

    int index = type;
    if (index >= 10) index = index / 10;
    if (sprite == null) {
      sprite = new AnimatedSprite(backgroud.getX(), backgroud.getY(), bigs.getRegCat().deepCopy());
      scene.attachChild(sprite);
    }
    update(scene);
  }
示例#4
0
 // This simple creates the scene
 // That can hold other objects too
 @Override
 public Scene onLoadScene() {
   mEngine.registerUpdateHandler(new FPSLogger());
   // Create a scene 'myscene' object
   Scene myscene = new Scene();
   // Create one animated Sprite
   AnimatedSprite banana = new AnimatedSprite(100, 100, mTiledTextureRegion);
   // Attach sprite to the scene
   myscene.attachChild(banana);
   // set the time in milisec for each picture
   banana.animate(100);
   return myscene;
 }
示例#5
0
  @Override
  protected void onManagedUpdate(final float pSecondsElapsed) {
    if (mSensor != null) {
      float directionX = 0 - mSensor.getDimensions()[0];
      float directionY = 0 + mSensor.getDimensions()[1];

      directionX *= 15 * (1 + Math.random());
      directionY *= 15 * (1 + Math.random());

      if (this.mX <= 0 && directionX < 0)
        // on left edge going left
        directionX = 0;
      else if (this.mX + this.getWidth() >= mCameraWidth && directionX > 0) {
        // on right edge going right
        directionX = 0;
      }
      this.mVelocityX = directionX;

      if (this.mY < 0 && directionY < 0)
        // on top edge going up
        directionY = 0;
      else if (this.mY + this.getHeight() >= mCameraHeight && directionY > 0) {
        // on bottom edge going down
        directionY = 0;
      }
      this.mVelocityY = directionY;

      if (directionX == 0 || directionY == 0) this.setCurrentTileIndex(1);
      else this.setCurrentTileIndex(0);
    }
    super.onManagedUpdate(pSecondsElapsed);
  }
示例#6
0
 public void clear(Scene scene) {
   type = -1;
   isChecked = false;
   if (sprite != null) {
     sprite.setCurrentTileIndex(3, 1);
   }
   update(scene);
 }
示例#7
0
 public void way(boolean isWay) {
   if (backgroud != null) {
     backgroud.setCurrentTileIndex(isWay ? 1 : 0);
     if (isWay) {
       handler.sendEmptyMessageAtTime(0, 500);
     }
   }
 }
示例#8
0
  @Override
  public void onPositionChanged() {
    super.onPositionChanged();

    if (lastXPos < this.getX()) this.flipSprite(false);
    else if (lastXPos > this.getX()) this.flipSprite(true);

    lastXPos = this.getX();
  }
示例#9
0
  public void update(Scene getmMainScene) {
    if (sprite != null) {
      if (getType() == -1) {
        sprite.stopAnimation();
        sprite.setCurrentTileIndex(2, 0);
      } else if (isBig()) {
        if (isChecked()) {
          sprite.setCurrentTileIndex(0, getType());
          sprite.animate(
              new long[] {100, 100, 100}, (getType() - 1) * 3, (getType() - 1) * 3 + 2, true);
        } else {
          sprite.stopAnimation();
          sprite.setCurrentTileIndex(0, getType() - 1);
        }

      } else {
        sprite.stopAnimation();
        sprite.setCurrentTileIndex(1, (getType() / 10) - 1);
      }
    }
  }
示例#10
0
 public boolean isSelected(int x, int y) {
   return backgroud.getX() < x
       && x < (backgroud.getX() + backgroud.getWidth())
       && backgroud.getY() < y
       && y < (backgroud.getY() + backgroud.getHeight());
 }