Node::Node(void) : _rotationX(0.0f) , _rotationY(0.0f) , _scaleX(1.0f) , _scaleY(1.0f) , _vertexZ(0.0f) , _position(Point::ZERO) , _skewX(0.0f) , _skewY(0.0f) , _anchorPointInPoints(Point::ZERO) , _anchorPoint(Point::ZERO) , _contentSize(Size::ZERO) , _additionalTransform(AffineTransformMakeIdentity()) , _camera(NULL) // children (lazy allocs) // lazy alloc , _grid(NULL) , _ZOrder(0) , _children(NULL) , _parent(NULL) // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true , _tag(kNodeTagInvalid) // userData is always inited as nil , _userData(NULL) , _userObject(NULL) , _shaderProgram(NULL) , _GLServerState(ccGLServerState(0)) , _orderOfArrival(0) , _running(false) , _transformDirty(true) , _inverseDirty(true) , _additionalTransformDirty(false) , _visible(true) , _ignoreAnchorPointForPosition(false) , _reorderChildDirty(false) , _isTransitionFinished(false) , _updateScriptHandler(0) , _componentContainer(NULL) { // set default scheduler and actionManager Director *director = Director::getInstance(); _actionManager = director->getActionManager(); _actionManager->retain(); _scheduler = director->getScheduler(); _scheduler->retain(); ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); _scriptType = pEngine != NULL ? pEngine->getScriptType() : kScriptTypeNone; _componentContainer = new ComponentContainer(this); }
bool CScale9Sprite::updateWithBatchNode(SpriteBatchNode* batchnode, Rect rect, bool rotated, Rect capInsets) { GLubyte opacity = getOpacity(); Color3B color = getColor(); // Release old sprites this->removeAllChildrenWithCleanup(true); 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(Rect::ZERO) ) { // Get the texture size as original Size textureSize = _scale9Image->getTextureAtlas()->getTexture()->getContentSize(); rect = Rect(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(Rect::ZERO) ) { // CCLog("... cap insets not specified : using default cap insets ..."); m_capInsetsInternal = Rect(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 Rect lefttopbounds = Rect(x, y, left_w, top_h); // top center TRANSLATE_X(x, y, left_w); Rect centertopbounds = Rect(x, y, center_w, top_h); // top right TRANSLATE_X(x, y, center_w); Rect righttopbounds = Rect(x, y, right_w, top_h); // ... center row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, top_h); // center left Rect leftcenterbounds = Rect(x, y, left_w, center_h); // center center TRANSLATE_X(x, y, left_w); Rect centerbounds = Rect(x, y, center_w, center_h); // center right TRANSLATE_X(x, y, center_w); Rect rightcenterbounds = Rect(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 Rect leftbottombounds = Rect(x, y, left_w, bottom_h); // bottom center TRANSLATE_X(x, y, left_w); Rect centerbottombounds = Rect(x, y, center_w, bottom_h); // bottom right TRANSLATE_X(x, y, center_w); Rect rightbottombounds = Rect(x, y, right_w, bottom_h); if (!rotated) { // CCLog("!rotated"); AffineTransform t = AffineTransformMakeIdentity(); t = AffineTransformTranslate(t, rect.origin.x, rect.origin.y); centerbounds = RectApplyAffineTransform(centerbounds, t); rightbottombounds = RectApplyAffineTransform(rightbottombounds, t); leftbottombounds = RectApplyAffineTransform(leftbottombounds, t); righttopbounds = RectApplyAffineTransform(righttopbounds, t); lefttopbounds = RectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = RectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = RectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = RectApplyAffineTransform(centerbottombounds, t); centertopbounds = RectApplyAffineTransform(centertopbounds, t); // Centre _centre = Sprite::createWithTexture(_scale9Image->getTexture(), centerbounds); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = Sprite::createWithTexture(_scale9Image->getTexture(), centertopbounds); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), centerbottombounds); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = Sprite::createWithTexture(_scale9Image->getTexture(), leftcenterbounds); _scale9Image->addChild(_left, 1, pLeft); // Right _right = Sprite::createWithTexture(_scale9Image->getTexture(), rightcenterbounds); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), lefttopbounds); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), righttopbounds); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), leftbottombounds); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = Sprite::createWithTexture(_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"); AffineTransform t = AffineTransformMakeIdentity(); Rect rotatedcenterbounds = centerbounds; Rect rotatedrightbottombounds = rightbottombounds; Rect rotatedleftbottombounds = leftbottombounds; Rect rotatedrighttopbounds = righttopbounds; Rect rotatedlefttopbounds = lefttopbounds; Rect rotatedrightcenterbounds = rightcenterbounds; Rect rotatedleftcenterbounds = leftcenterbounds; Rect rotatedcenterbottombounds = centerbottombounds; Rect rotatedcentertopbounds = centertopbounds; t = AffineTransformTranslate(t, rect.size.height+rect.origin.x, rect.origin.y); t = AffineTransformRotate(t, 1.57079633f); centerbounds = RectApplyAffineTransform(centerbounds, t); rightbottombounds = RectApplyAffineTransform(rightbottombounds, t); leftbottombounds = RectApplyAffineTransform(leftbottombounds, t); righttopbounds = RectApplyAffineTransform(righttopbounds, t); lefttopbounds = RectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = RectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = RectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = RectApplyAffineTransform(centerbottombounds, t); centertopbounds = RectApplyAffineTransform(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 = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); _scale9Image->addChild(_left, 1, pLeft); // Right _right = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = Sprite::createWithTexture(_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; }