cocos2d-x 制作系统公告

2013-12-15  21:57:33

下载地址:http://download.csdn.net/detail/jackyvincefu/6434549 (摘自:CSDN资源)

cocos2d-x 制作系统公告

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/,visibleSize.height/+));
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",);
text1->setHorizontalAlignment(kCCTextAlignmentLeft);
text1->setAnchorPoint(ccp(0.5,));
text1->setPosition(ccp(visibleSize.width/,visibleSize.height/-));
this->addChild(text1);
CCSprite* fg=CCSprite::create("fg.png");
fg->setPosition(ccp(visibleSize.width/,visibleSize.height/));
this->addChild(fg); //水平滚动公告
CCSprite* textbase=CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_textbase.png"));
textbase->setPosition(ccp(visibleSize.width/,));
textbase->setScaleX(2.5f);
this->addChild(textbase);
text2=CCLabelTTF::create("Hi! Welcome to JackyStudio,My Blog is blog.csdn.net/jackystudio!","Arial",);
text2->setPosition(ccp(visibleSize.width+text2->getContentSize().width/,));
text2->setColor(ccc3(,,));
this->addChild(text2); this->scheduleUpdate(); bRet = true;
} while (); return bRet;
} void CTestLayer::update( float dt )
{
CCSize visibleSize=CCDirector::sharedDirector()->getVisibleSize(); int newY = text1->getPositionY()+;
if (newY == )
{
newY = visibleSize.height/-;
}
text1->setPositionY(newY); int newX = text2->getPositionX()-;
if (newX <= -text2->getContentSize().width/)
{
newX = visibleSize.width+text2->getContentSize().width/;
}
text2->setPositionX(newX);
}
上一篇:Android Fragment用法之给Activity创建事件回调


下一篇:vue2购物车ch1-(安装依赖、简单配置、 axios获取api的模拟数据)