コード例 #1
0
ファイル: CCSprite.java プロジェクト: museng/PuzzleGame
  public void updateColor() {
    float tmpR = color_.r / 255.f;
    float tmpG = color_.g / 255.f;
    float tmpB = color_.b / 255.f;
    float tmpA = opacity_ / 255.f;

    colors
        .put(tmpR)
        .put(tmpG)
        .put(tmpB)
        .put(tmpA)
        .put(tmpR)
        .put(tmpG)
        .put(tmpB)
        .put(tmpA)
        .put(tmpR)
        .put(tmpG)
        .put(tmpB)
        .put(tmpA)
        .put(tmpR)
        .put(tmpG)
        .put(tmpB)
        .put(tmpA);
    colors.position(0);

    // renders using Sprite Manager
    if (usesSpriteSheet_) {
      if (atlasIndex != CCSpriteIndexNotInitialized) {
        tmpColor4B.r = color_.r;
        tmpColor4B.g = color_.g;
        tmpColor4B.b = color_.b;
        tmpColor4B.a = opacity_;
        textureAtlas_.updateColor(tmpColors, atlasIndex);

      } else {
        // no need to set it recursively
        // update dirty_, don't update recursiveDirty_
        dirty_ = true;
      }
    }
    // self render
    // do nothing
  }
コード例 #2
0
ファイル: CCSprite.java プロジェクト: museng/PuzzleGame
  private void updateTextureCoords(CGRect rect) {
    float atlasWidth = 1;
    float atlasHeight = 1;

    if (texture_ != null) {
      atlasWidth = texture_.pixelsWide();
      atlasHeight = texture_.pixelsHigh();
    }

    if (rectRotated_) {
      float left = (2 * rect.origin.x + 1) / (2 * atlasWidth);
      float right = left + (rect.size.height * 2 - 2) / (2 * atlasWidth);
      float top = (2 * rect.origin.y + 1) / (2 * atlasHeight);
      float bottom = top + (rect.size.width * 2 - 2) / (2 * atlasHeight);

      if (flipX_) {
        float tmp = top;
        top = bottom;
        bottom = tmp;
      }

      if (flipY_) {
        float tmp = left;
        left = right;
        right = tmp;
      }

      tmpV[0] = right;
      tmpV[1] = top; // tl v
      tmpV[2] = left; // bl u
      tmpV[3] = top; // bl v
      tmpV[4] = right; // tr u
      tmpV[5] = bottom; // tr v
      tmpV[6] = left; // br u
      tmpV[7] = bottom; // br v

      BufferUtils.copyFloats(tmpV, 0, texCoords, 8);

      //	        texCoords.put(0, right); // tl u
      //	        texCoords.put(1, top); // tl v
      //	        texCoords.put(2, left); // bl u
      //	        texCoords.put(3, top); // bl v
      //	        texCoords.put(4, right); // tr u
      //	        texCoords.put(5, bottom); // tr v
      //	        texCoords.put(6, left); // br u
      //	        texCoords.put(7, bottom); // br v
    } else {
      float left = (2 * rect.origin.x + 1) / (2 * atlasWidth);
      float right = left + (rect.size.width * 2 - 2) / (2 * atlasWidth);
      float top = (2 * rect.origin.y + 1) / (2 * atlasHeight);
      float bottom = top + (rect.size.height * 2 - 2) / (2 * atlasHeight);

      if (flipX_) {
        float tmp = left;
        left = right;
        right = tmp;
      }

      if (flipY_) {
        float tmp = top;
        top = bottom;
        bottom = tmp;
      }

      tmpV[0] = left; // tl u
      tmpV[1] = top; // tl v
      tmpV[2] = left; // bl u
      tmpV[3] = bottom; // bl v
      tmpV[4] = right; // tr u
      tmpV[5] = top; // tr v
      tmpV[6] = right; // br u
      tmpV[7] = bottom; // br v
      BufferUtils.copyFloats(tmpV, 0, texCoords, 8);

      //	        texCoords.put(0, left); // tl u
      //	        texCoords.put(1, top); // tl v
      //	        texCoords.put(2, left); // bl u
      //	        texCoords.put(3, bottom); // bl v
      //	        texCoords.put(4, right); // tr u
      //	        texCoords.put(5, top); // tr v
      //	        texCoords.put(6, right); // br u
      //	        texCoords.put(7, bottom); // br v
    }

    texCoords.position(0);

    if (usesSpriteSheet_) textureAtlas_.putTexCoords(texCoords, atlasIndex);
  }
コード例 #3
0
ファイル: CCSprite.java プロジェクト: museng/PuzzleGame
  /** updates the quad according the the rotation, position, scale values. */
  public void updateTransform() {
    tmpMatrix.setToIdentity();

    // Optimization: if it is not visible, then do nothing
    if (!visible_) {
      Arrays.fill(tmpV, 0);
      textureAtlas_.putVertex(textureAtlas_.getVertexBuffer(), tmpV, atlasIndex);
      dirty_ = recursiveDirty_ = false;
      return;
    }

    // Optimization: If parent is spritesheet, or parent is nil
    // build Affine transform manually
    if (parent_ == null || parent_ == spriteSheet_) {
      float radians = -ccMacros.CC_DEGREES_TO_RADIANS(rotation_);
      float c = (float) Math.cos(radians);
      float s = (float) Math.sin(radians);

      tmpMatrix.set(c * scaleX_, s * scaleX_, -s * scaleY_, c * scaleY_, position_.x, position_.y);

      tmpMatrix.translate(-anchorPointInPixels_.x, -anchorPointInPixels_.y);
    }

    // else do affine transformation according to the HonorParentTransform
    else if (parent_ != spriteSheet_) {

      int prevHonor = CC_HONOR_PARENT_TRANSFORM_ALL;

      for (CCNode p = this; p != null && p != spriteSheet_; p = p.getParent()) {
        CCSprite sprP = (CCSprite) p;

        tmpNewMatrix.setToIdentity();
        // 2nd: Translate, Rotate, Scale
        if ((prevHonor & CC_HONOR_PARENT_TRANSFORM_TRANSLATE) != 0)
          tmpNewMatrix.translate(sprP.position_.x, sprP.position_.y);
        if ((prevHonor & CC_HONOR_PARENT_TRANSFORM_ROTATE) != 0)
          tmpNewMatrix.rotate(-ccMacros.CC_DEGREES_TO_RADIANS(sprP.rotation_));
        if ((prevHonor & CC_HONOR_PARENT_TRANSFORM_SCALE) != 0) {
          tmpNewMatrix.scale(sprP.scaleX_, sprP.scaleY_);
        }

        // 3rd: Translate anchor point
        tmpNewMatrix.translate(-sprP.anchorPointInPixels_.x, -sprP.anchorPointInPixels_.y);
        // 4th: Matrix multiplication
        tmpMatrix.multiply(tmpNewMatrix);
        prevHonor = sprP.honorParentTransform_;
      }
    }

    //
    // calculate the Quad based on the Affine Matrix
    //

    CGSize size = rect_.size;

    float x1 = offsetPosition_.x;
    float y1 = offsetPosition_.y;

    float x2 = x1 + size.width;
    float y2 = y1 + size.height;
    float x = (float) tmpMatrix.m02;
    float y = (float) tmpMatrix.m12;

    float cr = (float) tmpMatrix.m00;
    float sr = (float) tmpMatrix.m10;
    float cr2 = (float) tmpMatrix.m11;
    float sr2 = (float) -tmpMatrix.m01;

    float ax = x1 * cr - y1 * sr2 + x;
    float ay = x1 * sr + y1 * cr2 + y;

    float bx = x2 * cr - y1 * sr2 + x;
    float by = x2 * sr + y1 * cr2 + y;

    float cx = x2 * cr - y2 * sr2 + x;
    float cy = x2 * sr + y2 * cr2 + y;

    float dx = x1 * cr - y2 * sr2 + x;
    float dy = x1 * sr + y2 * cr2 + y;

    tmpV[0] = dx;
    tmpV[1] = dy;
    tmpV[2] = vertexZ_;
    tmpV[3] = ax;
    tmpV[4] = ay;
    tmpV[5] = vertexZ_;
    tmpV[6] = cx;
    tmpV[7] = cy;
    tmpV[8] = vertexZ_;
    tmpV[9] = bx;
    tmpV[10] = by;
    tmpV[11] = vertexZ_;

    textureAtlas_.putVertex(textureAtlas_.getVertexBuffer(), tmpV, atlasIndex);
    dirty_ = recursiveDirty_ = false;
  }