void Sprite::setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) { _rectRotated = rotated; setContentSize(untrimmedSize); setVertexRect(rect); setTextureCoords(rect); float relativeOffsetX = _unflippedOffsetPositionFromCenter.x; float relativeOffsetY = _unflippedOffsetPositionFromCenter.y; // issue #732 if (_flippedX) { relativeOffsetX = -relativeOffsetX; } if (_flippedY) { relativeOffsetY = -relativeOffsetY; } _offsetPosition.x = relativeOffsetX + (_contentSize.width - _rect.size.width) / 2; _offsetPosition.y = relativeOffsetY + (_contentSize.height - _rect.size.height) / 2; // rendering using batch node if (_batchNode) { // update dirty_, don't update recursiveDirty_ setDirty(true); } else { // self rendering // Atlas: Vertex float x1 = 0.0f + _offsetPosition.x; float y1 = 0.0f + _offsetPosition.y; float x2 = x1 + _rect.size.width; float y2 = y1 + _rect.size.height; // Don't update Z. _quad.bl.vertices.set(x1, y1, 0.0f); _quad.br.vertices.set(x2, y1, 0.0f); _quad.tl.vertices.set(x1, y2, 0.0f); _quad.tr.vertices.set(x2, y2, 0.0f); } _polyInfo.setQuad(&_quad); }
void CALabel::setImageRect(const CCRect& rect) { m_bRectRotated = false; setVertexRect(rect); setImageCoords(rect); if (m_pobBatchView) { setDirty(true); } else { this->updateImageRect(); } }
void CATextField::setImageRect(const CCRect& rect) { m_bRectRotated = false; setVertexRect(rect); setImageCoords(rect); if (m_pobBatchView) { // update dirty_, don't update recursiveDirty_ setDirty(true); } else { this->updateImageRect(); } }
void Sprite::setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) { _rectRotated = rotated; setContentSize(untrimmedSize); setVertexRect(rect); setTextureCoords(rect); _offsetPosition.x = (contentSize.width - _rect.size.width) / 2; _offsetPosition.y = (contentSize.height - _rect.size.height) / 2; // self rendering // Atlas: Vertex float x1 = 0 + _offsetPosition.x; float y1 = 0 + _offsetPosition.y; float x2 = x1 + _rect.size.width; float y2 = y1 + _rect.size.height; FKLOG("Sprite vertexs:x1 %.4f,y1 %.4f,x2 %.4f,y2 %.4f",x1,y1,x2,y2); /* * _____(x2,y2) | | |(x1,y1)___| 3_____4 | | |1____2| */ //leftB rightTop; float vertexs[] = {x1,y1,0, x2,y1,0, x1,y2,0, x2,y2,0}; //{ -0.5,-0.5,0,0.5,-0.5,0,-0.5,0.5,0,0.5,0.5,0}; _vbo->updateData(VERTEX_INDEX,3,vertexs); }
/** * 设置数据 */ void MapCoordLine::setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize) { m_bRectRotated = rotated; setContentSize(untrimmedSize); setVertexRect(rect); setTextureCoords(rect); // 设置纹理坐标 CCPoint relativeOffset = m_obUnflippedOffsetPositionFromCenter; // issue #732 if (m_bFlipX) { relativeOffset.x = -relativeOffset.x; } if (m_bFlipY) { relativeOffset.y = -relativeOffset.y; } m_obOffsetPosition.x = relativeOffset.x + (m_tContentSize.width - m_obRect.size.width) / 2; m_obOffsetPosition.y = relativeOffset.y + (m_tContentSize.height - m_obRect.size.height) / 2; // rendering using batch node if (m_pobBatchNode) { // update dirty_, don't update recursiveDirty_ setDirty(true); } else { // self rendering // Atlas: Vertex float x = 0 + m_obOffsetPosition.x; float y = 0 + m_obOffsetPosition.y; // Atlas: Color ccColor4B tmpColor = { 67,67, 76, 255 }; // 设置顶点坐标 // Don't update Z. int eachWidth = _eachWidth; int eachHeight = _eachHeight; if (eachWidth > _width) eachWidth = _width; if (eachHeight > _height) eachHeight = _height; std::vector<ccV3F_C4B_T2F> tpoints; int widthSize = _width / eachWidth ; int heightSize = _height/ eachHeight; for (int i = 0; i < widthSize + 1;i++) { // 生成横向点 ccV3F_C4B_T2F point; point.vertices = vertex3(i * eachWidth + x,0,0); // y,z 均为0 tpoints.push_back(point); point.vertices = vertex3(i * eachWidth + x,_height,0); // y 为最高值z 均为0 tpoints.push_back(point); } for (int j = 0; j < heightSize + 1;j++) { ccV3F_C4B_T2F point; point.vertices = vertex3(0,j * eachHeight + y,0); // y,z 均为0 tpoints.push_back(point); point.vertices = vertex3(_width,j * eachHeight + y,0); // y 为最高值z 均为0 tpoints.push_back(point); } // 生成顶点集合 for (int i = 0; i < tpoints.size()/2;i++) { ccV3F_C4B_T2F p; static int indexs[] = {0,1}; // 固态的指定渲染的引索号 static float textures[] = {0,1,0,0,1,1,1,0}; // 纹理映射点 for (int z = 0; z < 2;z++) { p.vertices = tpoints[i*2+indexs[z]].vertices; p.colors = tmpColor; p.texCoords.u = textures[indexs[z]*2]; p.texCoords.v = textures[indexs[z]*2+1]; points.push_back(p); } } } }