Beispiel #1
0
 /** Initializes an sprite with a texture and a rect. The offset will be (0,0). */
 protected void init(CCTexture2D texture, CGRect rect) {
   assert texture != null : "Invalid texture for sprite";
   // IMPORTANT: [self init] and not [super init];
   init();
   setTexture(texture);
   setTextureRect(rect);
 }
Beispiel #2
0
  /** sets a new display frame to the CCSprite. */
  public void setDisplayFrame(CCSpriteFrame frame) {
    unflippedOffsetPositionFromCenter_.set(frame.offset_);

    CCTexture2D newTexture = frame.getTexture();
    // update texture before updating texture rect
    if (texture_ == null || newTexture.name() != texture_.name()) setTexture(newTexture);

    // update rect
    setTextureRect(frame.rect_, frame.originalSize_, frame.rotated_);
  }
Beispiel #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_);
  }