Exemplo n.º 1
0
 public static Texture createForTextureRegionSize(
     final TextureFormat pTextureFormat,
     final TextureRegion pTextureRegion,
     final TextureOptions pTextureOptions) {
   final int textureRegionWidth = pTextureRegion.getWidth();
   final int textureRegionHeight = pTextureRegion.getHeight();
   return new Texture(
       MathUtils.nextPowerOfTwo(textureRegionWidth),
       MathUtils.nextPowerOfTwo(textureRegionHeight),
       pTextureFormat,
       pTextureOptions);
 }
Exemplo n.º 2
0
 public static Texture createForTextureSourceSize(
     final TextureFormat pTextureFormat,
     final ITextureSource pTextureSource,
     final TextureOptions pTextureOptions) {
   final int textureSourceWidth = pTextureSource.getWidth();
   final int textureSourceHeight = pTextureSource.getHeight();
   return new Texture(
       MathUtils.nextPowerOfTwo(textureSourceWidth),
       MathUtils.nextPowerOfTwo(textureSourceHeight),
       pTextureFormat,
       pTextureOptions);
 }
Exemplo n.º 3
0
  @Override
  public boolean onAreaTouched(
      final TouchEvent pSceneTouchEvent,
      final ITouchArea pTouchArea,
      final float pTouchAreaLocalX,
      final float pTouchAreaLocalY) {

    PlayerSprite sprite = null;

    // float[]Xs = null;
    // float[]Ys = null;

    float moveX, moveY;
    moveX = 0;
    moveY = 0;
    float diff;
    // float angleDeg = 0.0f;

    if ((pTouchArea) instanceof PlayerSprite) {

      sprite = (PlayerSprite) pTouchArea;
      selectedPlayer = sprite;
      Body body = this.mPhysicsWorld.getPhysicsConnectorManager().findBodyByShape(sprite);

      switch (pSceneTouchEvent.getAction()) {
        case TouchEvent.ACTION_DOWN:
          sprite.setScale(2.0f);
          sprite.setmGrabbed(true);

          sprite.setStartX(sprite.getX());
          sprite.setStartY(sprite.getY());
          return true;

        case TouchEvent.ACTION_MOVE:
          if (sprite.ismGrabbed()) {

            sprite.setPosition(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
            body.setTransform(
                new Vector2(pSceneTouchEvent.getX() / 32, pSceneTouchEvent.getY() / 32), 0);

            moveX = sprite.getX();
            moveY = sprite.getY();

            float relativeX =
                MathUtils.bringToBounds(0, sprite.getWidth(), pTouchAreaLocalX) / sprite.getWidth()
                    - 0.5f;
            float relativeY =
                MathUtils.bringToBounds(0, sprite.getHeight(), pTouchAreaLocalY)
                        / sprite.getHeight()
                    - 0.5f;

            relativeX = relativeX * 2;
            relativeY = relativeY * 2;

            // angleDeg = MathUtils.radToDeg((float)Math.atan2(-relativeX, relativeY));

            if (true) {

              diff = MathUtils.distance(sprite.getStartX(), sprite.getStartY(), moveX, moveY);

              if (diff > 30) {
                sprite.setStartX(moveX);
                sprite.setStartY(moveY);
              }
            }
          }
          return true;

        case TouchEvent.ACTION_UP:
          if (sprite.ismGrabbed()) {
            sprite.setmGrabbed(false);
            sprite.setScale(1.0f);
          }
          return true;
      }
    }
    return false;
  }
Exemplo n.º 4
0
 private void setFrogToRandomCell() {
   this.mFrog.setCell(
       MathUtils.random(1, CELLS_HORIZONTAL - 2), MathUtils.random(1, CELLS_VERTICAL - 2));
 }