1.04 锚点
Posted 养老保险年审
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1.04 锚点相关的知识,希望对你有一定的参考价值。
1.04 锚点
一、锚点影响了什么
1、锚点影响 放置位置
2、锚点影响 缩放 --- 缩放是围绕锚点旋转的
3、锚点影响 旋转 --- 通常情况下,旋转是围绕锚点进行
二、忽略锚点
1、忽略锚点 --- 将锚点置成 0,0
2、通常情况下,Scene 是忽略锚点的
三、源代码
1、头文件
#ifndef _T01LayerAnchorPoint_H_
#define _T01LayerAnchorPoint_H_
#include "cocos2d.h"
USING_NS_CC;
//锚点
class T01LayerAnchorPoint:public CCLayer
{
public:
static T01LayerAnchorPoint* create( );
static CCScene* scene( );
bool init( );
virtual void draw( );
virtual void mySchedule( float dt );
private:
CCSprite* spr;//定时器需要
};
#endif
2、源文件
#include "T01LayerAnchorPoint.h"
CCScene* T01LayerAnchorPoint::scene( )
{
CCScene* scene = CCScene::create( );
T01LayerAnchorPoint* layer = T01LayerAnchorPoint::create( );
//通常情况下,Scene 是忽略锚点的
//layer->ignoreAnchorPointForPosition( false ); //不忽略锚点
//CCLog( "x = %f, y = %f", layer->getPositionX( ), layer->getPositionY( ) );
scene->addChild( layer );
return scene;
}
T01LayerAnchorPoint* T01LayerAnchorPoint::create( )
{
T01LayerAnchorPoint* pRet = new T01LayerAnchorPoint;
if (pRet && pRet->init())
{
pRet->autorelease( );
}
else
{
delete pRet;
pRet = NULL;
}
return pRet;
}
bool T01LayerAnchorPoint::init( )
{
CCLayer::init( ); //父类初始化
//主战场
CCSize winSize = CCDirector::sharedDirector( )->getWinSize( );
spr = CCSprite::create( "anchor3.png" );
//锚点影响 放置位置
//spr->setAnchorPoint( ccp( 0, 0 ) );
spr->setAnchorPoint( ccp( 0, 1 ) );
//spr->setAnchorPoint( ccp( 1, 0 ) );
//spr->setAnchorPoint( ccp( 1, 1 ) );
//锚点影响 缩放 --- 缩放是围绕锚点旋转的
//spr->setAnchorPoint( ccp( 0.5, 0.5 ) );
//spr->setAnchorPoint( ccp( 0.656, 0.5 ) );
//spr->setScale( 5.0f ); //缩放
//忽略锚点 --- 将锚点置成 0,0
spr->ignoreAnchorPointForPosition( false );
spr->setPosition( ccp( winSize.width / 2, winSize.height / 2 ) );
this->addChild( spr );
//锚点影响 旋转 --- 通常情况下,旋转是围绕锚点进行
//定时器
//typedef void (CCObject::*SEL_SCHEDULE)(float);
//schedule( schedule_selector(T01LayerAnchorPoint::mySchedule ), 2 ); //2秒钟触发
return true;
}
void T01LayerAnchorPoint::draw( )
{
//draw 绘图
CCSize winSize = CCDirector::sharedDirector( )->getWinSize( );
ccDrawColor4B( 255, 0, 0, 255 );
ccDrawLine( ccp( 0, winSize.height / 2 ), ccp( winSize.width, winSize.height/2) );
ccDrawLine( ccp( winSize.width / 2, 0 ), ccp( winSize.width/2 , winSize.height) );
}
void T01LayerAnchorPoint::mySchedule( float dt )
{
static float ro = 0;
ro += 30;
spr->setRotation( ro );
}
以上是关于1.04 锚点的主要内容,如果未能解决你的问题,请参考以下文章