Cocos2d-X----锚点
发布时间:2020-12-14 20:35:27 所属栏目:百科 来源:网络整理
导读:2、影响缩放 3、影响旋转 #include "T01LayerAnchorPoint.h"CCScene * T01LayerAnchorPoint::scene(){CCScene * scene = CCScene::create();T01LayerAnchorPoint * layer = T01LayerAnchorPoint::create();scene-addChild(layer);return scene;}bool T01Laye
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,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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |