2016年4月15日 星期五

0415 cocos2d-x 座標跟縮放關係




文章有誤~~~~以下實作失效
cocos2d-x 座標跟縮放關係

CCLayer s have their Anchor Point on ( 0, 0 ), the bottom left corner. When you scale an object, it will scale relative to the anchor point.
Anyway, I have tried changing it's anchor point to the center but it doesn't work for me so I just did a bit of math to figure out the position of the layer.
// cocos2dx-2.0.4
/* Scale a layer and set it's position to the center */
// Get screen size.
CCSize windowSize = CCDirector::sharedDirector() -> getVisibleSize();

// Scale layer down to 40%
mBaseLayer -> setScale( 0.40f );

// Calculate coordinates
// xPos is the center of the width of the screen ( width * 0.5 ) minus half the width of the layer
float xPos = ( windowSize.width * 0.50f ) - ( mBaseLayer -> getContentSize().width * 0.50f );

// yPos is the center of the height of the screen ( height * 0.5 ) minus half the height of the layer
float yPos = ( windowSize.height * 0.50f ) - ( mBaseLayer -> getContentSize().height * 0.50f );

// Place the bottom left corner of the layer to xPos and yPos.
mBaseLayer -> setPosition( CCPointMake( xPos, yPos ) );

沒有留言:

張貼留言

cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...