Example #1
0
 @Override
 public void onTouchUp(int x, int y, boolean hotspot) {
   final Sprite explosionSprite = new Sprite(x, y, explosionTexture);
   explosionSprite.setAnimationHandler(
       new AnimationHandler() {
         @Override
         public void finished(Sprite sprite) {
           rokon.removeSprite(sprite);
         }
       });
   rokon.addSprite(explosionSprite);
   explosionSprite.animate(1, 25, 35, 1, false);
 }
Example #2
0
 public void onUpdate(Sprite sprite) {
   timeDiff = Rokon.getTime() - _startTime;
   scale = _startScale + ((float) timeDiff / (float) _time);
   if (timeDiff > _time) {
     setExpired(true);
     if (_handler != null) _handler.onFinished();
   }
   sprite.setScale(scale, scale);
   width = sprite.getWidth();
   height = sprite.getHeight();
   offsetX = (width / 2f) - (scale * (width / 2f));
   offsetY = (height / 2f) - (scale * (height / 2f));
   sprite.setOffset(offsetX, offsetY);
 }
Example #3
0
 @Override
 public void onReady() {
   // You can also set it to move over a period of time.
   // (if this is called again while it is already moving, the previous movement is canceled)
   // It takes x, y and time in ms.
   bob3.moveTo(450, 100, 5000);
 }
Example #4
0
  @Override
  public void onGameLoop() {
    // This is the game loop that is called once every frame.
    // It's where you update all your objects.

    // Here we make Bob constantly move to the right.
    bob.x += 1;

    // If Bob walks outside the screen, move him back.
    if (bob.x >= MainActivity.GAME_WIDTH) {
      bob.x = 0;
    }

    // Here we make the 2nd Bob rotate by 2 degrees every frame.
    bob2.rotate(2);
  }
Example #5
0
  public GameScene() {
    super(
        1, 3); // Setup the scene to have 1 layer of sprites with a maximum of 3 sprites per layer.
    // (note that the background does NOT count as a sprite)

    setBackground(background = new FixedBackground(Textures.background));

    // Create the Bob sprites.
    bob = new Sprite(100, 220, Textures.bob.getWidth(), Textures.bob.getHeight());
    bob.setTexture(Textures.bob); // Set the actual texture.
    bob2 = new Sprite(100, 180, Textures.bob.getWidth(), Textures.bob.getHeight());
    bob2.setTexture(Textures.bob); // Note that you can use the same texture for multiple sprites.
    bob3 = new Sprite(100, 260, Textures.bob.getWidth(), Textures.bob.getHeight());
    bob3.setTexture(Textures.bob);

    // Add the Bob sprites to the first layer.
    add(0, bob);
    add(0, bob2);
    add(0, bob3);
  }