Cocos2d-2.x_跑马灯效果

Cocos2d-2.x_跑马灯效果,第1张

概述#ifndef __HELLO_WORLD_H__#define __HELLO_WORLD_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::CCLayer {public: HelloWorld();
#ifndef __HELLO_WORLD_H__#define __HELLO_WORLD_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer {public:	HelloWorld();    virtual ~HelloWorld();        static cocos2d::CCScene* scene();	virtual bool init();	voID scroll(float tm);	CREATE_FUNC(HelloWorld);};#endif
#include "HelloWorldScene.h"#include "SimpleAudioEngine.h"HelloWorld::HelloWorld(){}HelloWorld::~HelloWorld(){}CCScene* HelloWorld::scene(){	CCScene *scene = CCScene::create();	HelloWorld *layer = HelloWorld::create();	scene->addChild(layer);	return scene;}bool HelloWorld::init(){	if (!cclayer::init())	{		return false;	}	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();		//添加背景图片	CCSprite * background = CCSprite::create("HelloWorld.png");	background->setposition(ccp(visibleSize.wIDth / 2,visibleSize.height / 2));	this->addChild(background,1);	//设置文本信息	cclabelTTF * text = cclabelTTF::create("跑马灯,跑马灯,跑马灯,跑马灯,跑马灯!","Arial",22);	text->setcolor(ccc3(0,255,255));	text->setposition(ccp(visibleSize.wIDth / 2,visibleSize.height * 4 / 5));	this->addChild(text,1,0);	//使用定时器,每0.005秒回调一次,产生移动的效果	this->schedule(schedule_selector(HelloWorld::scroll),0.005f);	return true;}voID HelloWorld::scroll(float tm){	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();	cclabelTTF * text = (cclabelTTF *)this->getChildByTag(0);	CCPoint point = text->getposition();	text->setposition(ccp(point.x - 1,point.y));	//当text完全出去的时候重新设置它的坐标	float wIDth = text->getContentSize().wIDth;	if (point.x < -wIDth / 2)	{		text->setposition(ccp(visibleSize.wIDth + wIDth / 2,visibleSize.height * 4 / 5));	}}
总结

以上是内存溢出为你收集整理的Cocos2d-2.x_跑马灯效果全部内容,希望文章能够帮你解决Cocos2d-2.x_跑马灯效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1056854.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存