Esempio n. 1
0
  /*
   * Prepara para desenho. Utiliza AnimationStack.
   */
  @Override
  public void draw(final Drawer drawer) {

    // Prepare Animation
    final AnimationSet animationSet = mAnimationStack.animateFrame();

    // Get final Opacity
    final float opacity = animationSet.getOpacity() * getOpacity();

    // Not Update
    if (opacity <= 0) return;

    // Get Infos
    final Vector2 scale = Vector2.scale(mScale, animationSet.getScale());
    final Vector2 translate = animationSet.getPosition();
    final float rotate = mAngle + animationSet.getRotation();

    // Calc values
    final float ox = mCenter.x;
    final float oy = mCenter.y;
    float sx = scale.x;
    float sy = scale.y;

    float tX = mPosition.x + translate.x;
    float tY = mPosition.y + translate.y;
    float six = ox;
    float siy = oy;
    float mx = 1;
    float my = 1;
    float mtx = 0;
    float mty = 0;

    if (mMirror[0]) {
      mx = -1;
      mtx = 1;
    }

    if (mMirror[1]) {
      my = -1;
      mty = 1;
    }

    // Get Matrix Row
    final WorldMatrix matrixRow = drawer.getWorldMatrix();

    // Push Matrix
    matrixRow.push();

    // Translate and Rotate Matrix with correction
    float rad = (float) GeneralUtils.degreeToRad(rotate);
    float c = (float) Math.cos(rad);
    float s = (float) Math.sin(rad);
    mFinalTransformation[0] = c * sx * mx;
    mFinalTransformation[1] = -s * sy * my;
    mFinalTransformation[2] = c * (sx * mtx - six) + -s * (sy * mty - siy) + tX;
    mFinalTransformation[3] = s * sx * mx;
    mFinalTransformation[4] = c * sy * my;
    mFinalTransformation[5] = s * (sx * mtx - six) + c * (sy * mty - siy) + tY;
    matrixRow.preConcatf(mFinalTransformation);

    // Prepare blend mod
    drawer.begin();
    drawer.setOpacity(opacity);
    drawer.setBlendFunc(mBlendFuncs[0], mBlendFuncs[1], mBlendFuncs[2], mBlendFuncs[3]);
    drawer.snip(mViewport);

    // Draw Layers and sub layers
    for (LayerInfo info : mLayersInfo) {
      for (LayerInfo.Buffer buff : info.mBuffers) {
        // Set Texture
        drawer.setTexture(buff.mTexture);
        drawer.setElementVertex(buff.mElementsVertex);
        drawer.setTextureVertex(buff.mTextureVertex);
        // Draw tilemap
        drawer.drawTileMap(buff.mTilesQuantity * 6);
      }
    }

    // End Drawer
    drawer.end();

    // pop
    matrixRow.pop();
  }
Esempio n. 2
0
 /**
  * Return Real Position
  *
  * <p>Get Position with animations modify.
  *
  * @return {@link Vector2} Position
  */
 public final Vector2 getRealPosition() {
   final AnimationSet animationSet = getAnimationStack().animateFrame();
   Vector2 position = mPosition.clone();
   position.sum(animationSet.getPosition());
   return position;
 }
Esempio n. 3
0
 /**
  * Get center .
  *
  * @return {@link Vector2} Center
  */
 public final Vector2 getCenter() {
   return mCenter.clone();
 }
Esempio n. 4
0
 /**
  * Return Position
  *
  * @return {@link Vector2} Position
  */
 public final Vector2 getPosition() {
   return mPosition.clone();
 }
Esempio n. 5
0
 /** Get Scale */
 public final Vector2 getScale() {
   return mScale.clone();
 }
Esempio n. 6
0
 /**
  * Set center .
  *
  * @param center {@link Vector2} Center
  */
 public final void setCenter(final Vector2 center) {
   mCenter = center.clone();
 }
Esempio n. 7
0
 /**
  * Set Sprite Position
  *
  * @param position {@link Vector2} Position
  */
 public final void setPosition(final Vector2 position) {
   mPosition = position.clone();
 }
Esempio n. 8
0
 /**
  * Set Scale
  *
  * @param scale Float Scale
  */
 public final void setScale(final Vector2 scale) {
   mScale = scale.clone();
 }