cocos2d-x plist文件相关笔记

 1 <dict>
 2     <key>x</key>
 3     <integer>215</integer>
 4     <key>y</key>
 5     <integer>111</integer>
 6     <key>width</key>
 7     <integer>63</integer>
 8     <key>height</key>
 9     <integer>109</integer>
10     <key>offsetX</key>
11     <real>-6</real>
12     <key>offsetY</key>
13     <real>-1</real>
14     <key>originalWidth</key>
15     <integer>85</integer>
16     <key>originalHeight</key>
17     <integer>-121</integer>
18 </dict>

这是plist文件中的片段,用代码将这个sprite画出的效果如下。

外面的框是我根据CCNode的contextSize属性描画的box。(_tmpSprite->setDrawContentBox(true);

里面的框是我根据CCSprite的属性描画的,这里这2个框是重合的。(_tmpSprite->setDrawBoundingBox(true);_tmpSprite->setDrawTextureBox(true);)

代码如下:

 1 void XSSprite::draw(){
 2     //TODO
 3     CCSprite::draw();
 4 
 5     boolean _drawBoundingBox = mDrawBoundingBox;
 6     boolean _drawTextureBox  = mDrawTextureBox;
 7     boolean _drawContentBox  = mDrawContentBox;
 8 
 9 #if XS_SPRITE_DEBUG_DRAW == 1
10     _drawBoundingBox = true;
11 #elif XS_SPRITE_DEBUG_DRAW == 2
12     _drawTextureBox = true;
13 #endif // XS_SPRITE_DEBUG_DRAW
14 
15 
16     if(_drawBoundingBox){
17         // draw bounding box
18         CCPoint vertices[4]={
19             ccp(m_sQuad.tl.vertices.x,m_sQuad.tl.vertices.y),
20             ccp(m_sQuad.bl.vertices.x,m_sQuad.bl.vertices.y),
21             ccp(m_sQuad.br.vertices.x,m_sQuad.br.vertices.y),
22             ccp(m_sQuad.tr.vertices.x,m_sQuad.tr.vertices.y),
23         };
24         ccDrawPoly(vertices, 4, true);
25     }
26 
27     if(_drawTextureBox){
28         // draw texture box
29         CCSize s = this->getTextureRect().size;
30         CCPoint offsetPix = this->getOffsetPosition();
31         CCPoint vertices[4] = {
32             ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y),
33             ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height)
34         };
35         ccDrawPoly(vertices, 4, true);
36     }
37 
38     if(_drawContentBox){
39         CCSize s = this->getContentSize();
40         //CCPoint offsetPix = this->getOffsetPosition();
41         CCPoint offsetPix = CCPoint(0,0);
42         CCPoint vertices[4] = {
43             ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y),
44             ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height)
45         };
46         ccDrawPoly(vertices, 4, true);
47     }
48 }

 

总结一下,originalWidth 与 originalHeight 决定了cocos里的CCNode的contentSize。width与height是CCSprite管理的贴图的大小。offsetX,Y 是CCSprite管理的贴图的大小在整个content中的偏移。

 

just备忘。

 

 

posted @ 2013-05-12 10:26  林间走寸  阅读(421)  评论(0编辑  收藏  举报