Example #1
0
 /** Constructor */
 private Buffer(final int quantity, final Texture texture, final int id) {
   mTilesQuantity = quantity;
   mElementsVertex = GeneralUtils.createFloatBuffer(quantity * 12);
   mTextureVertex = GeneralUtils.createFloatBuffer(quantity * 12);
   mTexture = texture;
   mTilesetId = id;
 }
Example #2
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();
  }
Example #3
0
  /** Add model to TileMap */
  public final void addModel(final TileMapModel model) {
    int mapTileWidth = (int) model.getTileSize().x;
    int mapTileHeight = (int) model.getTileSize().y;

    for (int i = 0; i < model.getLayersCount(); i++) {

      final TileMapLayer layer = model.getLayer(i);

      int width = (int) Math.min(layer.mWidth, model.getMapSize().x);
      int height = (int) Math.min(layer.mHeight, model.getMapSize().y);

      LayerInfo layerInfo = addLayerInfo(new Vector2(width, height));

      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          final int tileId = layer.mData[x + y * width];
          if (tileId == 0) continue;

          final TileInfo tileInfo = model.getTileInfo(tileId);

          // Prepare Buffer
          layerInfo.prepareBuffer(tileInfo);

          // Get Buffer
          LayerInfo.Buffer buff = layerInfo.getBuffer(tileInfo);

          // Get Rect Area
          RectF textureArea = tileInfo.getTextureArea();
          RectF textureAreaU =
              GeneralUtils.divideRect(textureArea, tileInfo.getTexture().getSize());

          Vector2 tileSize = tileInfo.getSize();
          final int tileWidth = (int) tileSize.x;
          final int tileHeight = (int) tileSize.y;

          // Put Element buffer
          buff.mElementsVertex.put(x * mapTileWidth);
          buff.mElementsVertex.put(y * mapTileHeight);
          buff.mElementsVertex.put(x * mapTileWidth + tileWidth);
          buff.mElementsVertex.put(y * mapTileHeight);
          buff.mElementsVertex.put(x * mapTileWidth + tileWidth);
          buff.mElementsVertex.put(y * mapTileHeight + tileHeight);
          buff.mElementsVertex.put(x * mapTileWidth);
          buff.mElementsVertex.put(y * mapTileHeight);
          buff.mElementsVertex.put(x * mapTileWidth);
          buff.mElementsVertex.put(y * mapTileHeight + tileHeight);
          buff.mElementsVertex.put(x * mapTileWidth + tileWidth);
          buff.mElementsVertex.put(y * mapTileHeight + tileHeight);

          // Put Texture Buffer
          buff.mTextureVertex.put(textureAreaU.left);
          buff.mTextureVertex.put(textureAreaU.top);
          buff.mTextureVertex.put(textureAreaU.right);
          buff.mTextureVertex.put(textureAreaU.top);
          buff.mTextureVertex.put(textureAreaU.right);
          buff.mTextureVertex.put(textureAreaU.bottom);
          buff.mTextureVertex.put(textureAreaU.left);
          buff.mTextureVertex.put(textureAreaU.top);
          buff.mTextureVertex.put(textureAreaU.left);
          buff.mTextureVertex.put(textureAreaU.bottom);
          buff.mTextureVertex.put(textureAreaU.right);
          buff.mTextureVertex.put(textureAreaU.bottom);
        }
      }

      layerInfo.pack();
    }
  }