2、影响缩放
3、影响旋转
#include "T01LayerAnchorPoint.h"
CCScene * T01LayerAnchorPoint::scene()
{
CCScene * scene = CCScene::create();
T01LayerAnchorPoint * layer = T01LayerAnchorPoint::create();
scene->addChild(layer);
return scene;
}
bool T01LayerAnchorPoint::init()
{
if (!CCLayer::init())
{
return false;
}
winSize = CCDirector::sharedDirector()->getWinSize();
sprite = CCSprite::create("anchor3.png");
//sprite->setScale(4);//放大4倍
//sprite->setAnchorPoint(ccp(0.8,0.2));//设置锚点位置
sprite->ignoreAnchorPointForPosition(true);//设置位置忽略锚点
sprite->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(sprite);
//定时器
schedule(schedule_selector(T01LayerAnchorPoint::rotationBy2s), 0.3);
return true;
}
void T01LayerAnchorPoint::draw()//绘制
{
ccDrawColor4B(255, 0, 0, 255);
ccDrawLine(ccp(0, winSize.height / 2),ccp(winSize.width,winSize.height / 2, 0));
ccDrawLine(ccp(winSize.width / 2, 0), ccp(winSize.width / 2, winSize.height));
}
void T01LayerAnchorPoint::rotationBy2s(float dt)
{
static float num = 0;
num += 30;
sprite->setRotation(num);//旋转
}
#ifndef __T01LayerAnchorPoint_H__
#define __T01LayerAnchorPoint_H__
#include "cocos2d.h"
USING_NS_CC;
class T01LayerAnchorPoint : public CCLayer
{
public:
static CCScene *scene();
CREATE_FUNC(T01LayerAnchorPoint);
bool init();
void draw();
CCSize winSize;
CCSprite * sprite;
void rotationBy2s(float dt);
};
#endif