/** 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); }
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); }
/** 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_); }
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_); }
public void setFlipY(boolean b) { if (flipY_ != b) { flipY_ = b; setTextureRect(rect_); } }
public void setTextureRect(CGRect rect) { setTextureRect(rect, rectRotated_); }
public void setTextureRect(CGRect rect, Boolean rotated) { setTextureRect(rect, rect.size, rotated); }
/** 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); }