Example #1
0
  /**
   * Initializes an sprite with a CGImageRef and a key The key is used by the CCTextureCache to know
   * if a texture was already created with this CGImage. For example, a valid key
   * is: @"sprite_frame_01". If key is nil, then a new texture will be created each time by the
   * CCTextureCache.
   *
   * @since v0.99.0
   */
  public CCSprite(Bitmap image, String key) {
    assert image != null : "Invalid CGImageRef for sprite";

    // XXX: possible bug. See issue #349. New API should be added
    CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(image, key);

    CGSize size = texture.getContentSize();
    CGRect rect = CGRect.make(0, 0, size.width, size.height);

    init(texture, rect);
  }
Example #2
0
  /**
   * Initializes an sprite with an image filepath. The rect used will be the size of the image. The
   * offset will be (0,0).
   */
  public CCSprite(String filepath) {
    assert filepath != null : "Invalid filename for sprite";

    CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(filepath);
    if (texture != null) {
      CGRect rect = CGRect.make(0, 0, 0, 0);
      rect.size = texture.getContentSize();
      init(texture, rect);
    } else {
      ccMacros.CCLOGERROR("CCSprite", "Unable to load texture from file: " + filepath);
    }
  }
Example #3
0
  protected void init() {
    texCoords = BufferProvider.createFloatBuffer(4 * 2);
    vertexes = BufferProvider.createFloatBuffer(4 * 3);
    colors = BufferProvider.createFloatBuffer(4 * 4);

    dirty_ = false;
    recursiveDirty_ = false;

    // zwoptex default values
    offsetPosition_ = CGPoint.zero();
    unflippedOffsetPositionFromCenter_ = new CGPoint();
    rect_ = CGRect.make(0, 0, 1, 1);

    // by default use "Self Render".
    // if the sprite is added to an SpriteSheet,
    // then it will automatically switch to "SpriteSheet Render"
    useSelfRender();

    opacityModifyRGB_ = true;
    opacity_ = 255;
    color_ = new ccColor3B(ccColor3B.ccWHITE);
    colorUnmodified_ = new ccColor3B(ccColor3B.ccWHITE);

    // update texture (calls updateBlendFunc)
    setTexture(null);

    flipY_ = flipX_ = false;

    // lazy alloc
    animations_ = null;

    // default transform anchor: center
    anchorPoint_.set(0.5f, 0.5f);

    honorParentTransform_ = CC_HONOR_PARENT_TRANSFORM_ALL;
    hasChildren_ = false;

    // Atlas: Color
    colors.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
    colors.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
    colors.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
    colors.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
    colors.position(0);

    // Atlas: Vertex
    // updated in "useSelfRender"
    // Atlas: TexCoords
    setTextureRect(0, 0, 0, 0, rectRotated_);
  }
Example #4
0
 /**
  * Initializes an sprite with a texture. The rect used will be the size of the texture. The offset
  * will be (0,0).
  */
 public CCSprite(CCTexture2D texture) {
   CGSize size = texture.getContentSize();
   CGRect rect = CGRect.make(0, 0, size.width, size.height);
   init(texture, rect);
 }
 @Override
 public CGRect enclosedArea() {
   float xMin = center.x - rx, xMax = center.x + rx;
   float yMin = center.y - ry, yMax = center.y + ry;
   return CGRect.make(xMin, yMin, xMax - xMin, yMax - yMin);
 }
Example #6
0
 /**
  * returns a "local" axis aligned bounding box of the node. The returned box is relative only to
  * its parent.
  *
  * @since v0.8.2
  */
 public CGRect getBoundingBox() {
   CGRect rect = CGRect.make(0, 0, contentSize_.width, contentSize_.height);
   return CGRect.applyAffineTransform(rect, nodeToParentTransform());
 }