Cocos2dx內的座標系(Coordinate Systems In Cocos2dx)

窗口座標系:即openGL座標系,左下角爲原點,向右是x正方向,向上是y正方向。

紋理座標系:左上角爲原點,向右是x正方向,向下是y正方向。在使用圖集時,例如截取其中的某個矩形塊來創建一個sprite會用到此座標系。


Window Coordinate System: which uses the openGL coordinate system, has an origin at the left bottom corner, x increases towards the rightside and y increases towards the upside.

Texture Coordinate System: which has an origin at the top left corner, with x increasing towards the rightside and y increasing towards the downside.This coordinate system will be used when you use a tileset, like using a rect from it to create a sprite.


code example:

CCSpriteBatchNode* batchnode = CCSpriteBatchNode::create("data/tileset/grass.png");
CCSprite* sprite= CCSprite::createWithTexture(batchnode->getTexture(), CCRectMake(0,0,48,32));
batchnode->addChild(bnsprite);
this->addChild(batchnode);

The second line in this code fragment, created an sprite,using a 48*32 rect on the top left corner of the texture.

發佈了32 篇原創文章 · 獲贊 10 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章