CTestLayer.h
#ifndef __TEST_LAYER__#define __TEST_LAYER__#include "cocos2d.h"USING_NS_CC;class CTestLayer : public cocos2d::cclayer{public: CTestLayer(voID); ~CTestLayer(voID); virtual bool init(); CREATE_FUNC(CTestLayer); virtual voID update(float dt); cclabelTTF* text1; cclabelTTF* text2;};#endif //__TEST_LAYER__
CTestLayer.cpp
#include "TestLayer.h"CTestLayer::CTestLayer(voID){}CTestLayer::~CTestLayer(voID){}bool CTestLayer::init(){ bool bRet = false; do { CC_BREAK_IF(!cclayer::init()); CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize(); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithfile("ui_serverList.pList"); //垂直滚动字幕 CCSprite* Listbase=CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByname("login_Listbase.png")); Listbase->setposition(ccp(visibleSize.wIDth/2,visibleSize.height/2+10)); this->addChild(Listbase); text1=cclabelTTF::create("1.Hi! Welcome to JackyStudio,\nMy Blog is\nblog.csdn.net/jackystudio!\n2.Hi! Welcome to JackyStudio,\nMy Blog is\nblog.csdn.net/jackystudio!\n3.Hi! Welcome to JackyStudio,\nMy Blog is\nblog.csdn.net/jackystudio!\n4.Hi! Welcome to JackyStudio,\nMy Blog is\nblog.csdn.net/jackystudio!","Arial",12); text1->setHorizontalAlignment(kCCTextAlignmentleft); text1->setAnchorPoint(ccp(0.5,1)); text1->setposition(ccp(visibleSize.wIDth/2,visibleSize.height/2-55)); this->addChild(text1); CCSprite* fg=CCSprite::create("fg.png"); fg->setposition(ccp(visibleSize.wIDth/2,visibleSize.height/2)); this->addChild(fg); //水平滚动公告 CCSprite* textbase=CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByname("login_textbase.png")); textbase->setposition(ccp(visibleSize.wIDth/2,50)); textbase->setScaleX(2.5f); this->addChild(textbase); text2=cclabelTTF::create("Hi! Welcome to JackyStudio,My Blog is blog.csdn.net/jackystudio!",12); text2->setposition(ccp(visibleSize.wIDth+text2->getContentSize().wIDth/2,50)); text2->setcolor(ccc3(255,0)); this->addChild(text2); this->scheduleUpdate(); bRet = true; } while (0); return bRet;}voID CTestLayer::update( float dt ){ CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize(); int newY = text1->getpositionY()+1; if (newY == 500) { newY = visibleSize.height/2-55; } text1->setpositionY(newY); int newX = text2->getpositionX()-1; if (newX <= -text2->getContentSize().wIDth/2) { newX = visibleSize.wIDth+text2->getContentSize().wIDth/2; } text2->setpositionX(newX);}
使用:
CTestLayer* testLabel = CTestLayer::create(); CC_BREAK_IF(!testLabel); this->addChild(testLabel);
运行效果:
以上是内存溢出为你收集整理的cocos2d-x 实现游戏中的系统公告全部内容,希望文章能够帮你解决cocos2d-x 实现游戏中的系统公告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)