Пример #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);
 }
Пример #2
0
 private void setTextureRect(CGRect rect, CGSize size, Boolean rotated) {
   setTextureRect(
       rect.origin.x,
       rect.origin.y,
       rect.size.width,
       rect.size.height,
       size.width,
       size.height,
       rotated);
 }
Пример #3
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_);
  }
Пример #4
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_);
  }
Пример #5
0
 public void setFlipY(boolean b) {
   if (flipY_ != b) {
     flipY_ = b;
     setTextureRect(rect_);
   }
 }
Пример #6
0
 public void setTextureRect(CGRect rect) {
   setTextureRect(rect, rectRotated_);
 }
Пример #7
0
 public void setTextureRect(CGRect rect, Boolean rotated) {
   setTextureRect(rect, rect.size, rotated);
 }
Пример #8
0
 /** updates the texture rect of the CCSprite. */
 public void setTextureRect(float x, float y, float w, float h, Boolean rotated) {
   setTextureRect(x, y, w, h, w, h, rotated);
 }