void Scale9Sprite::createSlicedSprites() { //todo create sliced sprite if (_scale9Enabled) { Texture2D *tex = _scale9Image ? _scale9Image->getTexture() : nullptr; if (tex == nullptr) { return; } if (_renderingType == RenderingType::SIMPLE) { this->configureSimpleModeRendering(); } auto capInsets = CC_RECT_POINTS_TO_PIXELS(_capInsetsInternal); auto textureRect = CC_RECT_POINTS_TO_PIXELS(_spriteRect); auto spriteRectSize = _spriteRect.size; auto originalSize = CC_SIZE_POINTS_TO_PIXELS(_originalSize); auto offset = CC_POINT_POINTS_TO_PIXELS(_offset); Vec4 offsets; offsets.x = offset.x + (originalSize.width - textureRect.size.width) / 2; offsets.w = offset.y + (originalSize.height - textureRect.size.height) / 2; offsets.z = originalSize.width - textureRect.size.width - offsets.x; offsets.y = originalSize.height - textureRect.size.height - offsets.w; //handle .9.png if (_isPatch9) { originalSize = Size(originalSize.width - 2, originalSize.height-2); } if(capInsets.equals(Rect::ZERO)) { capInsets = Rect(originalSize.width/3, originalSize.height/3, originalSize.width/3, originalSize.height/3); } auto uv = this->calculateUV(tex, capInsets, originalSize, offsets); auto vertices = this->calculateVertices(capInsets, originalSize, offsets); auto triangles = this->calculateTriangles(uv, vertices); _scale9Image->getPolygonInfo().setTriangles(triangles); } }
void SuperAnimSprite::SetTexture(CCTexture2D *theTexture, CCRect theTextureRect) { if (theTexture == NULL) { return; } if (mTexture != NULL) { mTexture->release(); mTexture = NULL; } // retain this texture in case removed by removeUnusedTextures(); theTexture->retain(); mTexture = theTexture; // Set Texture coordinates CCRect theTexturePixelRect = CC_RECT_POINTS_TO_PIXELS(theTextureRect); float aTextureWidth = (float)mTexture->getPixelsWide(); float aTextureHeight = (float)mTexture->getPixelsHigh(); float aLeft, aRight, aTop, aBottom; aLeft = theTexturePixelRect.origin.x / aTextureWidth; aRight = (theTexturePixelRect.origin.x + theTexturePixelRect.size.width) / aTextureWidth; aTop = theTexturePixelRect.origin.y / aTextureHeight; aBottom = (theTexturePixelRect.origin.y + theTexturePixelRect.size.height) / aTextureHeight; mQuad.bl.texCoords.u = aLeft; mQuad.bl.texCoords.v = aBottom; mQuad.br.texCoords.u = aRight; mQuad.br.texCoords.v = aBottom; mQuad.tl.texCoords.u = aLeft; mQuad.tl.texCoords.v = aTop; mQuad.tr.texCoords.u = aRight; mQuad.tr.texCoords.v = aTop; // Set position //float x1 = 0; //float y1 = 0; //float x2 = x1 + theTextureRect.size.width; //float y2 = y1 + theTextureRect.size.height; float x1 = theTexturePixelRect.size.width * -0.5f; float y1 = theTexturePixelRect.size.height * -0.5f; float x2 = theTexturePixelRect.size.width * 0.5f; float y2 = theTexturePixelRect.size.height * 0.5f; mQuad.bl.vertices = vertex3(x1, y1, 0); mQuad.br.vertices = vertex3(x2, y1, 0); mQuad.tl.vertices = vertex3(x1, y2, 0); mQuad.tr.vertices = vertex3(x2, y2, 0); // Set color ccColor4B aDefaultColor = {255, 255, 255, 255}; mQuad.bl.colors = aDefaultColor; mQuad.br.colors = aDefaultColor; mQuad.tl.colors = aDefaultColor; mQuad.tr.colors = aDefaultColor; }
SpriteFrame* Sprite::getSpriteFrame() const { return SpriteFrame::createWithTexture(_texture, CC_RECT_POINTS_TO_PIXELS(_rect), _rectRotated, CC_POINT_POINTS_TO_PIXELS(_unflippedOffsetPositionFromCenter), CC_SIZE_POINTS_TO_PIXELS(_contentSize)); }
//--------------------------------------------------------------- // // void CLetterMoveLayer::preVisitWithClippingRect(CCRect clipRect) { if (!this->getIsVisible()) return; glEnable(GL_SCISSOR_TEST); CCDirector *director = CCDirector::sharedDirector(); CCSize size =director->getWinSize(); CCPoint origin = this->convertToWorldSpaceAR(clipRect.origin); CCPoint topRight =this->convertToWorldSpaceAR(ccpAdd(clipRect.origin, ccp(clipRect.size.width, clipRect.size.height))); CCRect scissorRect = CCRectMake(origin.x, origin.y, topRight.x-origin.x, topRight.y-origin.y); // transform the clipping rectangle to adjust to the current screen // orientation: the rectangle that has to be passed into glScissor is // always based on the coordinate system as if the device was held with the // home button at the bottom. the transformations account for different // device orientations and adjust the clipping rectangle to what the user // expects to happen. ccDeviceOrientation orientation =director->getDeviceOrientation(); switch (orientation) { case kCCDeviceOrientationPortrait: break; case kCCDeviceOrientationPortraitUpsideDown: scissorRect.origin.x = size.width-scissorRect.size.width-scissorRect.origin.x; scissorRect.origin.y = size.height-scissorRect.size.height-scissorRect.origin.y; break; case kCCDeviceOrientationLandscapeLeft: { float tmp = scissorRect.origin.x; scissorRect.origin.x = scissorRect.origin.y; scissorRect.origin.y = size.width-scissorRect.size.width-tmp; tmp = scissorRect.size.width; scissorRect.size.width = scissorRect.size.height; scissorRect.size.height = tmp; } break; case kCCDeviceOrientationLandscapeRight: { float tmp = scissorRect.origin.y; scissorRect.origin.y = scissorRect.origin.x; scissorRect.origin.x = size.height-scissorRect.size.height-tmp; tmp = scissorRect.size.width; scissorRect.size.width = scissorRect.size.height; scissorRect.size.height = tmp; } break; } // Handle Retina scissorRect = CC_RECT_POINTS_TO_PIXELS(scissorRect); glScissor((GLint) scissorRect.origin.x, (GLint) scissorRect.origin.y, (GLint) scissorRect.size.width, (GLint) scissorRect.size.height); }
SpriteFrame* MGRBlurSprite::getSpriteFrame() const { if(nullptr != this->_spriteFrame) { return this->_spriteFrame; } return SpriteFrame::createWithTexture(_texture, CC_RECT_POINTS_TO_PIXELS(_rect), _rectRotated, CC_POINT_POINTS_TO_PIXELS(_unflippedOffsetPositionFromCenter), CC_SIZE_POINTS_TO_PIXELS(_contentSize)); }
Rect AutoPolygon::getRealRect(const Rect& rect) { Rect realRect = rect; //check rect to see if its zero if(realRect.equals(Rect::ZERO)) { //if the instance doesn't have width and height, then the whole operation is kaput CCASSERT(_height && _width, "Please specify a width and height for this instance before using its functions"); realRect = Rect(0,0, _width, _height); } else{ //rect is specified, so convert to real rect realRect = CC_RECT_POINTS_TO_PIXELS(rect); } return realRect; }
void Sprite::setTextureCoords(Rect rect) { Texture2D *tex = _batchNode ? _textureAtlas->getTexture() : _texture; if (tex == nullptr) { return; } rect = CC_RECT_POINTS_TO_PIXELS(rect); float atlasWidth = (float)tex->getPixelsWide(); float atlasHeight = (float)tex->getPixelsHigh(); float left, right, top, bottom; if (_rectRotated) { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2*rect.origin.x+1)/(2*atlasWidth); right = left+(rect.size.height*2-2)/(2*atlasWidth); top = (2*rect.origin.y+1)/(2*atlasHeight); bottom = top+(rect.size.width*2-2)/(2*atlasHeight); #else left = rect.origin.x/atlasWidth; right = (rect.origin.x+rect.size.height) / atlasWidth; top = rect.origin.y/atlasHeight; bottom = (rect.origin.y+rect.size.width) / atlasHeight; #endif // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL if (_flippedX) { std::swap(top, bottom); } if (_flippedY) { std::swap(left, right); } _quad.bl.texCoords.u = left; _quad.bl.texCoords.v = top; _quad.br.texCoords.u = left; _quad.br.texCoords.v = bottom; _quad.tl.texCoords.u = right; _quad.tl.texCoords.v = top; _quad.tr.texCoords.u = right; _quad.tr.texCoords.v = bottom; } else { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2*rect.origin.x+1)/(2*atlasWidth); right = left + (rect.size.width*2-2)/(2*atlasWidth); top = (2*rect.origin.y+1)/(2*atlasHeight); bottom = top + (rect.size.height*2-2)/(2*atlasHeight); #else left = rect.origin.x/atlasWidth; right = (rect.origin.x + rect.size.width) / atlasWidth; top = rect.origin.y/atlasHeight; bottom = (rect.origin.y + rect.size.height) / atlasHeight; #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL if(_flippedX) { std::swap(left, right); } if(_flippedY) { std::swap(top, bottom); } _quad.bl.texCoords.u = left; _quad.bl.texCoords.v = bottom; _quad.br.texCoords.u = right; _quad.br.texCoords.v = bottom; _quad.tl.texCoords.u = left; _quad.tl.texCoords.v = top; _quad.tr.texCoords.u = right; _quad.tr.texCoords.v = top; } }
TexModule *Sprite::ensureTexModule() { auto tmMgr = TextureManager::getInstance(); TexModule *tm = nullptr; auto textureFilename = tmMgr->getTextureFilename(_texture); Vec2 offset(Vec2::ZERO); if (textureFilename.find(".md") == std::string::npos) { auto image = tmMgr->getImage(textureFilename); tm = image->getTexModule(); } else { auto module = tmMgr->getModule(textureFilename); if (!tmMgr->hasCalculatedTexCoord(_texCoordId)) { _moduleId = -1; for (int i = 0; i < module->getModuleCount(); ++i) { Rect rect = module->getModuleRect(i); if (!(_rect.getMinX() < rect.getMinX() || _rect.getMinY() < rect.getMinY() || _rect.getMaxX() > rect.getMaxX() || _rect.getMaxY() > rect.getMaxY())) { _moduleId = i; break; } } } if (_moduleId >= 0) { tm = module->getTexModule(_moduleId); offset = module->getModuleOffset(_moduleId); } } if (tm && !tmMgr->hasCalculatedTexCoord(_texCoordId)) { auto rect = CC_RECT_POINTS_TO_PIXELS(_rect); rect.origin = (rect.origin - offset) + Vec2(tm->x, tm->y); float atlasWidth = (float) tm->tex->getPixelsWide(); float atlasHeight = (float) tm->tex->getPixelsHigh(); float left = (rect.origin.x + ((_edgeFlag & kEdgeFlagLeft) ? 0.5f : 0)) / atlasWidth; float right = (rect.origin.x + rect.size.width - ((_edgeFlag & kEdgeFlagRight) ? 0.5f : 0)) / atlasWidth; float top = (rect.origin.y + ((_edgeFlag & kEdgeFlagTop) ? 0.5f : 0)) / atlasHeight; float bottom = (rect.origin.y + rect.size.height - ((_edgeFlag & kEdgeFlagBottom) ? 0.5f : 0)) / atlasHeight; if(_flippedX) { std::swap(left, right); } if(_flippedY) { std::swap(top, bottom); } _quad.bl.texCoords.u = left; _quad.bl.texCoords.v = bottom; _quad.br.texCoords.u = right; _quad.br.texCoords.v = bottom; _quad.tl.texCoords.u = left; _quad.tl.texCoords.v = top; _quad.tr.texCoords.u = right; _quad.tr.texCoords.v = top; tmMgr->calculatedTexCoord(_texCoordId, tm); } return tm; }
bool CCSpriteFrame::initWithTextureFilename(const char* filename, const CCRect& rect) { CCRect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); return initWithTextureFilename(filename, rectInPixels, false, CCPointZero, rectInPixels.size); }
bool LHAnimationFrameInfo::initWithDictionary(LHDictionary* dictionary, LHSprite* sprite){ if(NULL == dictionary) return false; delayPerUnit = dictionary->floatForKey("delayPerUnit"); offset = dictionary->pointForKey("offset"); offset.x *= CC_CONTENT_SCALE_FACTOR(); offset.y *= CC_CONTENT_SCALE_FACTOR(); notifications = NULL; if(dictionary->objectForKey("notifications")) { #if COCOS2D_VERSION >= 0x00020000 notifications = (LHDictionary*)CCDictionary::createWithDictionary(dictionary->dictForKey("notifications")); #else notifications = (LHDictionary*)CCDictionary<std::string, CCObject*>::dictionaryWithDictionary(dictionary->dictForKey("notifications")); #endif notifications->retain(); } spriteframeName = std::string(dictionary->stringForKey("spriteframe")); rect = dictionary->rectForKey("Frame"); rect = CC_RECT_POINTS_TO_PIXELS(rect); rect = LHSettings::sharedInstance()->transformedTextureRect(rect, sprite->getImageFile()); spriteFrameOffset = dictionary->pointForKey("TextureOffset"); spriteFrameOffset.x *= CC_CONTENT_SCALE_FACTOR(); spriteFrameOffset.y *= CC_CONTENT_SCALE_FACTOR(); if(LHSettings::sharedInstance()->isHDImage(sprite->getImageFile())){ spriteFrameOffset.x *= 2.0f; spriteFrameOffset.y *= 2.0f; } CCPoint tempOffset = spriteFrameOffset; tempOffset.x += offset.x; tempOffset.y -= offset.y; offset = tempOffset; rectIsRotated = dictionary->boolForKey("IsRotated"); spriteFrameSize = dictionary->sizeForKey("SpriteSize"); spriteFrameSize.width *= CC_CONTENT_SCALE_FACTOR(); spriteFrameSize.height*= CC_CONTENT_SCALE_FACTOR(); if(LHSettings::sharedInstance()->isHDImage(sprite->getImageFile())){ spriteFrameSize.width *= 2.0f; spriteFrameSize.height*= 2.0f; } sprFrame = NULL; createSpriteFrameWithSprite(sprite); return true; }
bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect) { Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); return initWithTextureFilename(filename, rectInPixels, false, Vec2::ZERO, rectInPixels.size); }
void CC3DSprite::updateTextureCoords(CCRect rect, bool rotated) { rect = CC_RECT_POINTS_TO_PIXELS(rect); CCTexture2D *tex = m_pobTexture; if (! tex) { return; } float atlasWidth = (float)tex->getPixelsWide(); float atlasHeight = (float)tex->getPixelsHigh(); float left, right, top, bottom; if (rotated) { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2*rect.origin.x+1)/(2*atlasWidth); right = left+(rect.size.height*2-2)/(2*atlasWidth); top = (2*rect.origin.y+1)/(2*atlasHeight); bottom = top+(rect.size.width*2-2)/(2*atlasHeight); #else left = rect.origin.x/atlasWidth; right = (rect.origin.x+rect.size.height) / atlasWidth; top = rect.origin.y/atlasHeight; bottom = (rect.origin.y+rect.size.width) / atlasHeight; #endif // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL /* if (m_bFlipX) { CC_SWAP(top, bottom, float); } if (m_bFlipY) { CC_SWAP(left, right, float); }*/ m_sQuad.bl.texCoords.u = left; m_sQuad.bl.texCoords.v = top; m_sQuad.br.texCoords.u = left; m_sQuad.br.texCoords.v = bottom; m_sQuad.tl.texCoords.u = right; m_sQuad.tl.texCoords.v = top; m_sQuad.tr.texCoords.u = right; m_sQuad.tr.texCoords.v = bottom; } else { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2*rect.origin.x+1)/(2*atlasWidth); right = left + (rect.size.width*2-2)/(2*atlasWidth); top = (2*rect.origin.y+1)/(2*atlasHeight); bottom = top + (rect.size.height*2-2)/(2*atlasHeight); #else left = rect.origin.x/atlasWidth; right = (rect.origin.x + rect.size.width) / atlasWidth; top = rect.origin.y/atlasHeight; bottom = (rect.origin.y + rect.size.height) / atlasHeight; #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL /*if(m_bFlipX) { CC_SWAP(left,right,float); } if(m_bFlipY) { CC_SWAP(top,bottom,float); }*/ m_sQuad.bl.texCoords.u = left; m_sQuad.bl.texCoords.v = bottom; m_sQuad.br.texCoords.u = right; m_sQuad.br.texCoords.v = bottom; m_sQuad.tl.texCoords.u = left; m_sQuad.tl.texCoords.v = top; m_sQuad.tr.texCoords.u = right; m_sQuad.tr.texCoords.v = top; } }
void CCSprite::setTextureRect(CGRect rect) { CGRect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect); setTextureRectInPixels(rectInPixels, false, rectInPixels.size); }
void VBModel::InitWithLibName(VBObjectFile2D* _obj2D, CCTexture2D* _texture, VBObjectFile2DLibraryNameID* _library_name_id, bool _is_realtime_animation, ccBlendFunc _blend) { init(); use_mix_color = true; is_use_animation = true; is_play_loop = true; is_play = true; is_real_time_animation = _is_realtime_animation; frame_rate = VBObjectFile2DGetFrameRate(_obj2D); VBObjectFile2DLibrary* _library = VBObjectFile2DGetLibraryByNameID(_obj2D, _library_name_id); void* _library_base = VBObjectFile2DLibraryGetBase(_library); if(VBObjectFile2DLibraryType_Bitmap == VBObjectFile2DLibraryGetType(_library)) { is_bitmap = true; VBObjectFile2DLibraryBitmap* _bitmap = (VBObjectFile2DLibraryBitmap*)_library_base; VBULong _poly_len = VBObjectFile2DLibraryBitmapGetUVInfoLength(_bitmap); VBVector2D _txc[_poly_len]; VBVector2D* _uv = VBObjectFile2DLibraryBitmapGetUVInfo(_bitmap); VBVector2D* _txc_ptr = _txc; for(int _i = 0; _i < _poly_len; _i++) { _txc_ptr->x = _uv[_i].x; _txc_ptr->y = _uv[_i].y; _txc_ptr++; } setTexture(_texture); CCRect _rect = CCRect(_txc[0].x * _texture->getPixelsWide(), _txc[0].y * _texture->getPixelsHigh(), (_txc[2].x * _texture->getPixelsWide() - _txc[0].x * _texture->getPixelsWide()), (_txc[2].y * _texture->getPixelsHigh() - _txc[0].y * _texture->getPixelsHigh())); cocos2d::CCSprite::setTextureRect(CC_RECT_POINTS_TO_PIXELS(_rect)); // cocos2d::CCSprite::setTextureRect(CCRect(_txc[0].x * _texture->getPixelsWide() / CCDirector::sharedDirector()->getContentScaleFactor(), // _txc[0].y * _texture->getPixelsHigh() / CCDirector::sharedDirector()->getContentScaleFactor(), // (_txc[2].x * _texture->getPixelsWide() - _txc[0].x * _texture->getPixelsWide()) / CCDirector::sharedDirector()->getContentScaleFactor(), // (_txc[2].y * _texture->getPixelsHigh() - _txc[0].y * _texture->getPixelsHigh()) / CCDirector::sharedDirector()->getContentScaleFactor()) // ); } else if(VBObjectFile2DLibraryType_Graphic == VBObjectFile2DLibraryGetType(_library) || VBObjectFile2DLibraryType_MovieClip == VBObjectFile2DLibraryGetType(_library)) { frame_all_allocated_child_models = VBArrayVectorInit(VBArrayVectorAlloc()); frame_willFree_child_models = VBArrayVectorInit(VBArrayVectorAlloc()); frame_current_key_frame = VBArrayVectorInit(VBArrayVectorAlloc()); if(VBObjectFile2DLibraryType_Graphic == VBObjectFile2DLibraryGetType(_library)) { VBObjectFile2DLibraryGraphic* _graphic = (VBObjectFile2DLibraryGraphic*)_library_base; frame = VBObjectFile2DLibraryGraphicGetFrame(_graphic); } else if(VBObjectFile2DLibraryType_MovieClip == VBObjectFile2DLibraryGetType(_library)) { VBObjectFile2DLibraryMovieClip* _movie_clip = (VBObjectFile2DLibraryMovieClip*)_library_base; frame = VBObjectFile2DLibraryMovieClipGetFrame(_movie_clip); } is_play = VBTrue; is_play_loop = VBTrue; is_animation_update = VBTrue; while (frame_all_allocated_child_models->len < frame->key_frame->len) { VBArrayVectorAddBack(frame_all_allocated_child_models, NULL); } for(int i = 0; i < frame->key_frame->len; i++) { VBObjectFile2DKeyFrame* _key_frame = (VBObjectFile2DKeyFrame*)frame->key_frame->data[i]; if(frame_all_allocated_child_models->data[i] == NULL) { VBModel* _child = new VBModel(_obj2D, _texture, _key_frame->library_id, _is_realtime_animation, _blend); frame_all_allocated_child_models->data[i] = _child; VBArrayVectorAddBack(frame_willFree_child_models, _child); LinkChildKeyFrames(i, _child, _key_frame); } } } Update(0.0f); setBlendFunc(_blend); }
// (0,0) O = capInsets.origin // v0---------------------- // | | | | // | | | | // v1-------O------+------| // | | | | // | | | | // v2-------+------+------| // | | | | // | | | | // v3-------------------- (1,1) (texture coordinate is flipped) // u0 u1 u2 u3 std::vector<Vec2> Scale9Sprite::calculateUV(Texture2D *tex, const Rect& capInsets, const Size& originalSize, const Vec4& offsets) { auto atlasWidth = tex->getPixelsWide(); auto atlasHeight = tex->getPixelsHigh(); //calculate texture coordinate float leftWidth = 0, centerWidth = 0, rightWidth = 0; float topHeight = 0, centerHeight = 0, bottomHeight = 0; if (_spriteFrameRotated) { rightWidth = capInsets.origin.y - offsets.y; centerWidth = capInsets.size.height; leftWidth = originalSize.height - centerWidth - capInsets.origin.y - offsets.w; topHeight = capInsets.origin.x - offsets.x; centerHeight = capInsets.size.width; bottomHeight = originalSize.width - (capInsets.origin.x + centerHeight) - offsets.z; } else { leftWidth = capInsets.origin.x - offsets.x; centerWidth = capInsets.size.width; rightWidth = originalSize.width - (capInsets.origin.x + centerWidth) - offsets.z; topHeight = capInsets.origin.y - offsets.y; centerHeight = capInsets.size.height; bottomHeight = originalSize.height - (capInsets.origin.y + centerHeight) - offsets.w; } if(leftWidth<0) { centerWidth += leftWidth; leftWidth = 0; } if(rightWidth<0) { centerWidth += rightWidth; rightWidth = 0; } if(topHeight<0) { centerHeight += topHeight; topHeight = 0; } if(bottomHeight<0) { centerHeight += bottomHeight; bottomHeight = 0; } auto textureRect = CC_RECT_POINTS_TO_PIXELS(_spriteRect); //handle .9.png if (_isPatch9) { //This magic number is used to avoiding artifact with .9.png format. float offset = 1.3f; textureRect = Rect(textureRect.origin.x + offset, textureRect.origin.y + offset, textureRect.size.width - 2, textureRect.size.height - 2); } //uv computation should take spritesheet into account. float u0, u1, u2, u3; float v0, v1, v2, v3; if (_spriteFrameRotated) { u0 = textureRect.origin.x / atlasWidth; u1 = (leftWidth + textureRect.origin.x) / atlasWidth; u2 = (leftWidth + centerWidth + textureRect.origin.x) / atlasWidth; u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth; v3 = textureRect.origin.y / atlasHeight; v2 = (topHeight + textureRect.origin.y) / atlasHeight; v1 = (topHeight + centerHeight + textureRect.origin.y) / atlasHeight; v0 = (textureRect.origin.y + textureRect.size.width) / atlasHeight; } else { u0 = textureRect.origin.x / atlasWidth; u1 = (leftWidth + textureRect.origin.x) / atlasWidth; u2 = (leftWidth + centerWidth + textureRect.origin.x) / atlasWidth; u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth; v0 = textureRect.origin.y / atlasHeight; v1 = (topHeight + textureRect.origin.y) / atlasHeight; v2 = (topHeight + centerHeight + textureRect.origin.y) / atlasHeight; v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight; } std::vector<Vec2> uvCoordinates; if (_renderingType == RenderingType::SIMPLE) { uvCoordinates = {Vec2(u0,v3), Vec2(u3,v0)}; } else { uvCoordinates = {Vec2(u0,v3), Vec2(u1,v2), Vec2(u2,v1), Vec2(u3,v0)}; } return uvCoordinates; }
void SpriteFrame::setRect(const Rect& rect) { _rect = rect; _rectInPixels = CC_RECT_POINTS_TO_PIXELS(_rect); }
bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect) { Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect); return initWithTexture(texture, rectInPixels, false, Vec2::ZERO, rectInPixels.size); }
bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect) { Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); return initWithTextureFilename(filename, rectInPixels, false, Point::ZERO, rectInPixels.size); }
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect) { CCRect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect); return initWithTexture(pobTexture, rectInPixels, false, CCPointZero, rectInPixels.size); }
void CCSpriteFrame::setRect(const CCRect& rect) { m_obRect = rect; m_obRectInPixels = CC_RECT_POINTS_TO_PIXELS(m_obRect); }