//----------------------------------------------------------------------------------------------------------------------------- void PersonView::createUI(void) { mInfo->hp = mInfo->maxHp = mConfig->hp(); mInfo->defense = mConfig->defe(); mInfo->attack = mConfig->att(); mInfo->maxattack = mConfig->maxatt(); mInfo->attackDelay = (float)mConfig->delay() / 1000; CCArmature* armature = CCArmature::create(mConfig->name().c_str()); setAvatar(armature); //if (id == 3) //{ // CCBone* bone = armature->getBone("staff"); // CCSpriteDisplayData displayData; // displayData.setParam("Pastor-weapon-pastor_staff_1.png"); // bone->addDisplay(&displayData, 1); // bone->changeDisplayByIndex(1, true); //} if (mBloodBar == NULL) { mBloodBar = BloodBar::create(); CCRect trect = CCRectApplyAffineTransform(armature->boundingBox(), armature->nodeToParentTransform()); // 获取模型的大小 mBloodBar->setPositionY(trect.getMaxY()); addChild(mBloodBar, 1); } }
CCRect CCUtils::getBoundingBoxInWorldSpace(CCNode* node) { CCRect r; r.origin = CCPointZero; r.size = node->getContentSize(); CCAffineTransform t = node->nodeToWorldTransform(); r = CCRectApplyAffineTransform(r, t); return r; }
CCRect VEScrollView::boundingBox() { CCRect rect = CCRectMake(-m_viewSize.width*0.5f, -m_viewSize.height*0.5, m_viewSize.width, m_viewSize.height); return CCRectApplyAffineTransform(rect, nodeToParentTransform()); }
//------------------------------------------------------------------------- // 获取对象包围盒 bool FKFrameSpriteObj::GetBoundingBox( CCRect& rt ) { if( m_pSprite ) { rt = m_pSprite->boundingBox(); rt = CCRectApplyAffineTransform( rt, nodeToParentTransform() ); return true; } return false; }
void CScrollView::visit() { glEnable(GL_SCISSOR_TEST); CCRect rect = CCRectMake(0, 0, m_obContentSize.width, m_obContentSize.height); rect = CCRectApplyAffineTransform(rect, nodeToWorldTransform()); CCEGLView::sharedOpenGLView()->setScissorInPoints(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); CPanel::visit(); glDisable(GL_SCISSOR_TEST); }
bool CCScrollView::isNodeFullyVisible(CCNode* node) { const CCPoint offset = this->getContentOffset(); const CCSize size = this->getViewSize(); const float scale = this->getZoomScale(); CCRect viewRect; viewRect = CCRectMake(-offset.x/scale, -offset.y/scale, size.width/scale, size.height/scale); CCRect nodeBound = CCRectMake(0, 0, node->getContentSize().width, node->getContentSize().height); CCAffineTransform t = node->nodeToAncestorTransform(getContainer()); nodeBound = CCRectApplyAffineTransform(nodeBound, t); return viewRect.containsRect(nodeBound); }
bool Container::checkTouch(CCTouch *pTouch){ //当需要更精确的tab判定时继承并修改修改即可 if( getContentSize().width * getContentSize().height > 1.0f ) { CCPoint pt = pTouch->getLocation(); CCRect rcBoundingBox( 0, 0, getContentSize().width, getContentSize().height ); rcBoundingBox = CCRectApplyAffineTransform( rcBoundingBox, nodeToWorldTransform() ); //[PassMessageDebug] CCLOG("Check here:%f,%f in %f,%f,%f,%f",pt.x,pt.y,rcBoundingBox.origin.x,rcBoundingBox.origin.y,rcBoundingBox.size.width,rcBoundingBox.size.height); if( !rcBoundingBox.containsPoint( pt ) ) { //[PassMessageDebug] CCLOG(">Check the collide rect:failed;"); return false; } }else{ return false; } return true; }
CCPoint CCScrollView::getNodeFullyVisibleOffset(CCNode* node) { // get node bound in container CCRect nodeBound = CCRectMake(0, 0, node->getContentSize().width, node->getContentSize().height); CCAffineTransform t = node->nodeToAncestorTransform(getContainer()); nodeBound = CCRectApplyAffineTransform(nodeBound, t); // get offset float scale = getZoomScale(); CCPoint offset = ccp(-nodeBound.origin.x / scale, -nodeBound.origin.y / scale); // clamp offset const CCPoint minOffset = minContainerOffset(); const CCPoint maxOffset = maxContainerOffset(); offset.x = MAX(minOffset.x, MIN(maxOffset.x, offset.x)); offset.y = MAX(minOffset.y, MIN(maxOffset.y, offset.y)); // return return offset; }
void CCBigImage::updateLoadRect() { // get screen rect CCRect screenRect = CCRectZero; screenRect.size = CCDirector::sharedDirector()->getWinSize(); screenRect = CCRectApplyAffineTransform(screenRect, this->worldToNodeTransform()); // get level's must-be-loaded-part rect _loadedRect = CCRectMake(screenRect.origin.x - _screenLoadRectExtension.width, screenRect.origin.y - _screenLoadRectExtension.height, screenRect.size.width + 3.0f * _screenLoadRectExtension.width, screenRect.size.height + 3.0f * _screenLoadRectExtension.height); // avoid tiles blinking if (_significantPositionChange) { this->updateTiles(); _significantPositionChange = false; } }
static CCRect getRect(CCNode * pNode) { CCSize contentSize = pNode->getContentSize(); CCRect rect = CCRectMake(0, 0, contentSize.width, contentSize.height); return CCRectApplyAffineTransform(rect, pNode->nodeToWorldTransform()); }
bool CCScale9Sprite::updateWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, bool rotated, CCRect capInsets) { GLubyte opacity = getOpacity(); ccColor3B color = getColor(); // Release old sprites this->removeAllChildrenWithCleanup(true); CC_SAFE_RELEASE(this->_centre); CC_SAFE_RELEASE(this->_top); CC_SAFE_RELEASE(this->_topLeft); CC_SAFE_RELEASE(this->_topRight); CC_SAFE_RELEASE(this->_left); CC_SAFE_RELEASE(this->_right); CC_SAFE_RELEASE(this->_bottomLeft); CC_SAFE_RELEASE(this->_bottom); CC_SAFE_RELEASE(this->_bottomRight); if(this->_scale9Image != batchnode) { CC_SAFE_RELEASE(this->_scale9Image); _scale9Image = batchnode; CC_SAFE_RETAIN(_scale9Image); } _scale9Image->removeAllChildrenWithCleanup(true); m_capInsets = capInsets; // If there is no given rect if ( rect.equals(CCRectZero) ) { // Get the texture size as original CCSize textureSize = _scale9Image->getTextureAtlas()->getTexture()->getContentSize(); rect = CCRectMake(0, 0, textureSize.width, textureSize.height); } // Set the given rect's size as original size m_spriteRect = rect; m_originalSize = rect.size; m_preferredSize = m_originalSize; m_capInsetsInternal = capInsets; float w = rect.size.width; float h = rect.size.height; // If there is no specified center region if ( m_capInsetsInternal.equals(CCRectZero) ) { // CCLog("... cap insets not specified : using default cap insets ..."); m_capInsetsInternal = CCRectMake(w/3, h/3, w/3, h/3); } float left_w = m_capInsetsInternal.origin.x; float center_w = m_capInsetsInternal.size.width; float right_w = rect.size.width - (left_w + center_w); float top_h = m_capInsetsInternal.origin.y; float center_h = m_capInsetsInternal.size.height; float bottom_h = rect.size.height - (top_h + center_h); // calculate rects // ... top row float x = 0.0; float y = 0.0; // top left CCRect lefttopbounds = CCRectMake(x, y, left_w, top_h); // top center TRANSLATE_X(x, y, left_w); CCRect centertopbounds = CCRectMake(x, y, center_w, top_h); // top right TRANSLATE_X(x, y, center_w); CCRect righttopbounds = CCRectMake(x, y, right_w, top_h); // ... center row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, top_h); // center left CCRect leftcenterbounds = CCRectMake(x, y, left_w, center_h); // center center TRANSLATE_X(x, y, left_w); CCRect centerbounds = CCRectMake(x, y, center_w, center_h); // center right TRANSLATE_X(x, y, center_w); CCRect rightcenterbounds = CCRectMake(x, y, right_w, center_h); // ... bottom row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, top_h); TRANSLATE_Y(x, y, center_h); // bottom left CCRect leftbottombounds = CCRectMake(x, y, left_w, bottom_h); // bottom center TRANSLATE_X(x, y, left_w); CCRect centerbottombounds = CCRectMake(x, y, center_w, bottom_h); // bottom right TRANSLATE_X(x, y, center_w); CCRect rightbottombounds = CCRectMake(x, y, right_w, bottom_h); if (!rotated) { // CCLog("!rotated"); CCAffineTransform t = CCAffineTransformMakeIdentity(); t = CCAffineTransformTranslate(t, rect.origin.x, rect.origin.y); centerbounds = CCRectApplyAffineTransform(centerbounds, t); rightbottombounds = CCRectApplyAffineTransform(rightbottombounds, t); leftbottombounds = CCRectApplyAffineTransform(leftbottombounds, t); righttopbounds = CCRectApplyAffineTransform(righttopbounds, t); lefttopbounds = CCRectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = CCRectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = CCRectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = CCRectApplyAffineTransform(centerbottombounds, t); centertopbounds = CCRectApplyAffineTransform(centertopbounds, t); // Centre _centre = new CCSprite(); _centre->initWithTexture(_scale9Image->getTexture(), centerbounds); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = new CCSprite(); _top->initWithTexture(_scale9Image->getTexture(), centertopbounds); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = new CCSprite(); _bottom->initWithTexture(_scale9Image->getTexture(), centerbottombounds); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = new CCSprite(); _left->initWithTexture(_scale9Image->getTexture(), leftcenterbounds); _scale9Image->addChild(_left, 1, pLeft); // Right _right = new CCSprite(); _right->initWithTexture(_scale9Image->getTexture(), rightcenterbounds); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = new CCSprite(); _topLeft->initWithTexture(_scale9Image->getTexture(), lefttopbounds); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = new CCSprite(); _topRight->initWithTexture(_scale9Image->getTexture(), righttopbounds); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = new CCSprite(); _bottomLeft->initWithTexture(_scale9Image->getTexture(), leftbottombounds); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = new CCSprite(); _bottomRight->initWithTexture(_scale9Image->getTexture(), rightbottombounds); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // CCLog("rotated"); CCAffineTransform t = CCAffineTransformMakeIdentity(); CCRect rotatedcenterbounds = centerbounds; CCRect rotatedrightbottombounds = rightbottombounds; CCRect rotatedleftbottombounds = leftbottombounds; CCRect rotatedrighttopbounds = righttopbounds; CCRect rotatedlefttopbounds = lefttopbounds; CCRect rotatedrightcenterbounds = rightcenterbounds; CCRect rotatedleftcenterbounds = leftcenterbounds; CCRect rotatedcenterbottombounds = centerbottombounds; CCRect rotatedcentertopbounds = centertopbounds; t = CCAffineTransformTranslate(t, rect.size.height+rect.origin.x, rect.origin.y); t = CCAffineTransformRotate(t, 1.57079633f); centerbounds = CCRectApplyAffineTransform(centerbounds, t); rightbottombounds = CCRectApplyAffineTransform(rightbottombounds, t); leftbottombounds = CCRectApplyAffineTransform(leftbottombounds, t); righttopbounds = CCRectApplyAffineTransform(righttopbounds, t); lefttopbounds = CCRectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = CCRectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = CCRectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = CCRectApplyAffineTransform(centerbottombounds, t); centertopbounds = CCRectApplyAffineTransform(centertopbounds, t); rotatedcenterbounds.origin = centerbounds.origin; rotatedrightbottombounds.origin = rightbottombounds.origin; rotatedleftbottombounds.origin = leftbottombounds.origin; rotatedrighttopbounds.origin = righttopbounds.origin; rotatedlefttopbounds.origin = lefttopbounds.origin; rotatedrightcenterbounds.origin = rightcenterbounds.origin; rotatedleftcenterbounds.origin = leftcenterbounds.origin; rotatedcenterbottombounds.origin = centerbottombounds.origin; rotatedcentertopbounds.origin = centertopbounds.origin; // Centre _centre = new CCSprite(); _centre->initWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = new CCSprite(); _top->initWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = new CCSprite(); _bottom->initWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = new CCSprite(); _left->initWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); _scale9Image->addChild(_left, 1, pLeft); // Right _right = new CCSprite(); _right->initWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = new CCSprite(); _topLeft->initWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = new CCSprite(); _topRight->initWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = new CCSprite(); _bottomLeft->initWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = new CCSprite(); _bottomRight->initWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, true); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } this->setContentSize(rect.size); this->addChild(_scale9Image); if (m_bSpritesGenerated) { // Restore color and opacity this->setOpacity(opacity); this->setColor(color); } m_bSpritesGenerated = true; return true; }
CCRect CCNode::boundingBoxInPixels() { CCRect rect = CCRectMake(0, 0, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height); return CCRectApplyAffineTransform(rect, nodeToParentTransform()); }
bool CCScale9Sprite::updateWithImage(CAImage* image, CCRect rect, CCRect capInsets) { GLubyte opacity = getOpacity(); ccColor3B color = getColor(); // Release old sprites this->removeAllSubviews(); CC_SAFE_RELEASE(this->_centre); CC_SAFE_RELEASE(this->_top); CC_SAFE_RELEASE(this->_topLeft); CC_SAFE_RELEASE(this->_topRight); CC_SAFE_RELEASE(this->_left); CC_SAFE_RELEASE(this->_right); CC_SAFE_RELEASE(this->_bottomLeft); CC_SAFE_RELEASE(this->_bottom); CC_SAFE_RELEASE(this->_bottomRight); this->setImage(image); this->removeAllSubviews(); m_capInsets = capInsets; // If there is no given rect if ( rect.equals(CCRectZero) ) { // Get the Image size as original CCSize textureSize = image->getContentSize(); rect = CCRectMake(0, 0, textureSize.width, textureSize.height); } this->setContentSize(rect.size); // Set the given rect's size as original size m_spriteRect = rect; m_originalSize = rect.size; m_preferredSize = m_originalSize; m_capInsetsInternal = capInsets; float w = rect.size.width; float h = rect.size.height; // If there is no specified center region if ( m_capInsetsInternal.equals(CCRectZero) ) { // CCLog("... cap insets not specified : using default cap insets ..."); m_capInsetsInternal = CCRectMake(w/3, h/3, w/3, h/3); } float left_w = m_capInsetsInternal.origin.x; float center_w = m_capInsetsInternal.size.width; float right_w = rect.size.width - (left_w + center_w); float top_h = m_capInsetsInternal.origin.y; float center_h = m_capInsetsInternal.size.height; float bottom_h = rect.size.height - (top_h + center_h); // calculate rects // ... top row float x = 0.0; float y = 0.0; // top left CCRect leftbottombounds = CCRectMake(x, y, left_w, top_h); // top center TRANSLATE_X(x, y, left_w); CCRect centerbottombounds = CCRectMake(x, y, center_w, top_h); // top right TRANSLATE_X(x, y, center_w); CCRect rightbottombounds = CCRectMake(x, y, right_w, top_h); // ... center row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, bottom_h); // center left CCRect leftcenterbounds = CCRectMake(x, y, left_w, center_h); // center center TRANSLATE_X(x, y, left_w); CCRect centerbounds = CCRectMake(x, y, center_w, center_h); // center right TRANSLATE_X(x, y, center_w); CCRect rightcenterbounds = CCRectMake(x, y, right_w, center_h); // ... bottom row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, bottom_h); TRANSLATE_Y(x, y, center_h); // bottom left CCRect lefttopbounds = CCRectMake(x, y, left_w, bottom_h); // bottom center TRANSLATE_X(x, y, left_w); CCRect centertopbounds = CCRectMake(x, y, center_w, bottom_h); // bottom right TRANSLATE_X(x, y, center_w); CCRect righttopbounds = CCRectMake(x, y, right_w, bottom_h); CCAffineTransform t = CCAffineTransformMakeIdentity(); t = CCAffineTransformTranslate(t, rect.origin.x, rect.origin.y); centerbounds = CCRectApplyAffineTransform(centerbounds, t); rightbottombounds = CCRectApplyAffineTransform(rightbottombounds, t); leftbottombounds = CCRectApplyAffineTransform(leftbottombounds, t); righttopbounds = CCRectApplyAffineTransform(righttopbounds, t); lefttopbounds = CCRectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = CCRectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = CCRectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = CCRectApplyAffineTransform(centerbottombounds, t); centertopbounds = CCRectApplyAffineTransform(centertopbounds, t); // Centre _centre = new CAImageView(); _centre->initWithImage(m_pImage, centerbounds); _centre->setTag(pCentre); this->insertSubview(_centre, 0); // Top _top = new CAImageView(); _top->initWithImage(m_pImage, centertopbounds); _top->setTag(pTop); this->insertSubview(_top, 1); // Bottom _bottom = new CAImageView(); _bottom->initWithImage(m_pImage, centerbottombounds); _bottom->setTag(pBottom); this->insertSubview(_bottom, 1); // Left _left = new CAImageView(); _left->initWithImage(m_pImage, leftcenterbounds); _left->setTag(pLeft); this->insertSubview(_left, 1); // Right _right = new CAImageView(); _right->initWithImage(m_pImage, rightcenterbounds); _right->setTag(pRight); this->insertSubview(_right, 1); // Top left _topLeft = new CAImageView(); _topLeft->initWithImage(m_pImage, lefttopbounds); _topLeft->setTag(pTopLeft); this->insertSubview(_topLeft, 2); // Top right _topRight = new CAImageView(); _topRight->initWithImage(m_pImage, righttopbounds); _topLeft->setTag(pTopRight); this->insertSubview(_topRight, 2); // Bottom left _bottomLeft = new CAImageView(); _bottomLeft->initWithImage(m_pImage, leftbottombounds); _bottom->setTag(pBottomLeft); this->insertSubview(_bottomLeft, 2); // Bottom right _bottomRight = new CAImageView(); _bottomRight->initWithImage(m_pImage, rightbottombounds); _bottomRight->setTag(pBottomRight); this->insertSubview(_bottomRight, 2); this->setContentSize(rect.size); _bottomLeft->setAnchorPoint(CCPoint(0,0)); _bottomRight->setAnchorPoint(CCPoint(0,0)); _topLeft->setAnchorPoint(CCPoint(0,0)); _topRight->setAnchorPoint(CCPoint(0,0)); _left->setAnchorPoint(CCPoint(0,0)); _right->setAnchorPoint(CCPoint(0,0)); _top->setAnchorPoint(CCPoint(0,0)); _bottom->setAnchorPoint(CCPoint(0,0)); _centre->setAnchorPoint(CCPoint(0,0)); if (m_bSpritesGenerated) { // Restore color and opacity this->setOpacity(opacity); this->setColor(color); } m_bSpritesGenerated = true; return true; }
void CCRookieGuide::addRegion(CCNode* n, CCCallFunc* func, bool removeOnTouch) { CCRect b = CCRectMake(0, 0, n->getContentSize().width, n->getContentSize().height); CCAffineTransform t = n->nodeToWorldTransform(); b = CCRectApplyAffineTransform(b, t); addRegion(b, func, removeOnTouch); }