Beispiel #1
0
 public void setFaceSize(final float pWidth, final float pHeight) {
   PositionerImmovableRelative positioner = PositionerImmovableRelative.getInstance();
   for (IEntity entity : this.mEntities) {
     if (entity != null) {
       entity.setSize(pWidth, pHeight);
       positioner.center(entity.getParent(), entity);
     }
   }
 }
Beispiel #2
0
 public static float getWrapScale(
     IEntity child, float pWidth, float pHeight, float boundingFactor) {
   if (child.getWidth() / pWidth > child.getHeight() / pHeight) {
     // Dealing in X
     return boundingFactor * pWidth / child.getWidth();
   } else {
     // Dealing in Y
     return boundingFactor * pHeight / child.getHeight();
   }
 }
Beispiel #3
0
  public static void setChildrenVisible(IEntity e, boolean pVisible) {
    for (int i = 0; i < e.getChildCount(); i++) {
      IEntity child = e.getChildByIndex(i);

      if (child.getChildCount() > 0) {
        setChildrenVisible(child, pVisible);
      }

      child.setVisible(pVisible);
    }
  }
Beispiel #4
0
  /**
   * Creates a button using provided entities as faces representing Button states
   *
   * @note Supplied entities will be moved to the center of Button
   * @param pNormal
   * @param pPressed
   * @param pDisabled
   */
  public Button(final IEntity pNormal, final IEntity pPressed, final IEntity pDisabled) {

    setSize(pNormal.getWidth(), pNormal.getHeight());
    if (pNormal == null) {
      throw new AndEngineRuntimeException("pNormal button face is null");
    }

    this.mEntities[State.NORMAL.getEntityIndex()] = pNormal;
    this.mEntities[State.PRESSED.getEntityIndex()] = pPressed;
    this.mEntities[State.DISABLED.getEntityIndex()] = pDisabled;

    this.mState = State.NORMAL;
    positionEntities();
  }
Beispiel #5
0
 public static void printEntityDebugInfo(IEntity e, String name) {
   Log.d(
       "Riska",
       ((name != null) ? name : "Entity")
           + ": at ("
           + e.getX()
           + ", "
           + e.getY()
           + ") sized ("
           + e.getWidth()
           + ", "
           + e.getHeight()
           + ")");
 }
Beispiel #6
0
  public void positionEntities() {
    detachChild(mEntities[0]);
    detachChild(mEntities[1]);
    detachChild(mEntities[2]);

    attachChild(mEntities[0]);
    attachChild(mEntities[1]);
    attachChild(mEntities[2]);

    PositionerImmovableRelative positioner = PositionerImmovableRelative.getInstance();
    for (IEntity entity : this.mEntities) {
      if (entity != null) {
        positioner.center(entity.getParent(), entity);
      }
    }

    detachChild(mEntities[0]);
    detachChild(mEntities[1]);
    detachChild(mEntities[2]);

    State savedState = mState;
    mState = State.UNDEFINED;
    changeState(savedState);
  }
  protected void detachAndDisposeEntities(boolean onlyPreserved) {
    IEntity index;

    final int CHILD_COUNT = this.getChildCount();
    final int HUD_CHILD_COUNT = SessionScene.HUD.getChildCount();

    for (int i = 0; i < CHILD_COUNT; i++) {
      index = this.getChildByIndex(0);
      if (onlyPreserved ? index.getTag() != SessionScene.TAG_PRESERVE : true) {
        index.detachSelf();
        if (!index.isDisposed()) index.dispose();
      }
    }

    for (int i = 0; i < HUD_CHILD_COUNT; i++) {
      index = SessionScene.HUD.getChildByIndex(0);
      if (onlyPreserved ? index.getTag() != SessionScene.TAG_PRESERVE : true) {
        index.detachSelf();
        if (!index.isDisposed()) index.dispose();
      }
    }
  }
  private void broadcast(final IEntity entity, final IEntityModifierListener listener) {
    entity.registerEntityModifier(
        new MoveModifier(
            0.5f,
            BROADCAST_RIGHT,
            BROADCAST_LEVEL,
            BROADCAST_LEFT,
            BROADCAST_LEVEL,
            new IEntityModifierListener() {
              @Override
              public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                entity.setVisible(true);
                listener.onModifierStarted(pModifier, pItem);
              }

              @Override
              public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                entity.setVisible(false);
                listener.onModifierFinished(pModifier, pItem);
              }
            },
            EaseBroadcast.getInstance()));
  }
Beispiel #9
0
 public static void hideChildren(IEntity e) {
   for (int i = 0; i < e.getChildCount(); i++) {
     e.getChildByIndex(i).setVisible(false);
   }
 }
Beispiel #10
0
 public static float halfY(IEntity e) {
   return 0.5f * e.getHeight();
 }
Beispiel #11
0
 public static float halfX(IEntity e) {
   return 0.5f * e.getWidth();
 }
Beispiel #12
0
 public static float topLocal(IEntity e) {
   return e.getHeight();
 }
Beispiel #13
0
 public static float rightLocal(IEntity e) {
   return e.getWidth();
 }
Beispiel #14
0
 public static float getCenterX(IEntity e) {
   return (0.5f * e.getWidth());
 }
Beispiel #15
0
 public static boolean contains(IEntity e, float pX, float pY) {
   return (isBetween(pX, 0, e.getWidth()) && isBetween(pY, 0, e.getHeight()));
 }
 @Override
 protected void onSetInitialValue(final IEntity pEntity, final float pX) {
   pEntity.setX(pX);
 }
Beispiel #17
0
 private float getItemSizeExtra(final IEntity pEntity) {
   return (mDirection != eDirection.DIR_HORIZONTAL) ? pEntity.getWidth() : pEntity.getHeight();
 }
Beispiel #18
0
 public static float posY(float perc, IEntity e) {
   return bottomGlobal(e) + perc * e.getHeight();
 }
Beispiel #19
0
 // ======================================================
 // ======================================================
 public static float posX(float perc, IEntity e) {
   return leftGlobal(e) + perc * e.getWidth();
 }
Beispiel #20
0
 public static void slideX(IEntity e, float distance) {
   e.setX(e.getX() + distance);
 }
Beispiel #21
0
 public static float getCenterY(IEntity e) {
   return (0.5f * e.getHeight());
 }
Beispiel #22
0
 public static void showChildren(IEntity e) {
   for (int i = 0; i < e.getChildCount(); i++) {
     e.getChildByIndex(i).setVisible(true);
   }
 }
Beispiel #23
0
 /** Works with scale */
 public static float getScaledWidth(IEntity e) {
   return (Math.abs(e.getScaleX() * e.getWidth()));
 }
Beispiel #24
0
 public static float bottomGlobal(IEntity e) {
   return e.getY() - 0.5f * e.getHeight();
 }
Beispiel #25
0
 public static float leftGlobal(IEntity e) {
   return e.getX() - 0.5f * e.getWidth();
 }
Beispiel #26
0
 /** Works with scale */
 public static float getScaledHeight(IEntity e) {
   return (Math.abs(e.getScaleY() * e.getHeight()));
 }
 @Override
 protected void onChangeValues(
     final float pSecondsElapsed, final IEntity pEntity, final float pX, final float pY) {
   pEntity.setPosition(pEntity.getX() + pX, pEntity.getY() + pY);
 }
Beispiel #28
0
 public static float rightGlobal(IEntity e) {
   return e.getX() + 0.5f * e.getWidth();
 }
 @Override
 protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pX) {
   pEntity.setX(pX);
 }
Beispiel #30
0
 public static float topGlobal(IEntity e) {
   return e.getY() + 0.5f * e.getHeight();
 }