Exemple #1
0
void Scale9Sprite::setTexture(cocos2d::Texture2D *texture, const cocos2d::Rect &rect) {
	_contentSizeDirty = true;
	DynamicBatchNode::setTexture(texture);
	if (rect.equals(cocos2d::Rect::ZERO)) {
		setTextureRect(cocos2d::Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height));
	} else {
		setTextureRect(rect);
	}
}
Exemple #2
0
void DynamicSprite::setTextureRect(const cocos2d::Rect &rect) {
	auto tex = getTexture();
	if (rect.equals(cocos2d::Rect::ZERO) && tex) {
		_textureRect = cocos2d::Rect(0, 0, tex->getPixelsHigh(), tex->getPixelsWide());
		_contentSizeDirty = true;
	} else {
		if (!_textureRect.equals(rect)) {
			_textureRect = rect;
			_contentSizeDirty = true;
		}
	}
	if (_autofit == Autofit::None) {
		setContentSize(cocos2d::Size(_textureRect.size.width / _density, _textureRect.size.height / _density));
	}
}
Exemple #3
0
bool Scale9Sprite::init(cocos2d::Texture2D *tex, cocos2d::Rect rect, cocos2d::Rect capInsets) {
	if (!DynamicBatchNode::init(tex)) {
		return false;
	}

	if (rect.equals(cocos2d::Rect::ZERO)) {
		rect.size = getTexture()->getContentSize();
	}
	_textureRect = rect;
	_capInsets = capInsets;
	_contentSize = _textureRect.size;
	
	setCascadeColorEnabled(true);
	setCascadeOpacityEnabled(true);
	
	return true;
}