位置: 编程技术 - 正文

cocos2dx3.3 跑马灯功能的简单实现(css跑马灯效果)

编辑:rootadmin
================================================头文件 Marquee.h================================================

推荐整理分享cocos2dx3.3 跑马灯功能的简单实现(css跑马灯效果),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:android跑马灯,notchification跑马灯设置教程,跑马灯js代码,ccs跑马灯程序,iapp跑马灯代码,跑马灯效果代码,跑马灯效果代码,跑马灯效果代码,内容如对您有帮助,希望把文章链接给更多的朋友!

#ifndef __H_MARQUEE_H__

#define __H_MARQUEE_H__#include "cocos2d.h"class Marquee:public cocos2d::Layer{public:Marquee();~Marquee();static void show(const char *content, int speed = -3, int fontSize = , cocos2d::Color3B color3B = cocos2d::Color3B::WHITE, int y = cocos2d::Director::getInstance()->getVisibleSize().height- - );private:virtual bool init();virtual void onEnter();virtual void onExit();CREATE_FUNC(Marquee);void update(float dt);void setSpeed(int dir);int getSpeed();private:int m_speed;};

#endif

cocos2dx3.3 跑马灯功能的简单实现(css跑马灯效果)

================================================cpp文件 Marquee.cpp================================================

#include "Marquee.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;Marquee::Marquee(){m_speed = 0;}Marquee::~Marquee(){}bool Marquee::init(){if (!Layer::init()){return false;}this->scheduleUpdate();return true;}void Marquee::show(const char *content, int speed, int fontSize, Color3B color3B, int y){Marquee *marquee = Marquee::create();auto scene = Director::getInstance()->getRunningScene();Size visibleSize = Director::getInstance()->getVisibleSize();Label *label = Label::create(content, "", fontSize);label->setColor(color3B);label->setTag();label->setPositionY(y);if (speed < 0){label->setAnchorPoint(Vec2::ZERO);label->setPositionX(visibleSize.width);}else{label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT);label->setPositionX(0);}marquee->setSpeed(speed);marquee->addChild(label);scene->addChild(marquee);}void Marquee::update(float dt){Size visibleSize = Director::getInstance()->getVisibleSize();Label *label = (Label*)this->getChildByTag();int dirX = this->getSpeed();int labelWidth = label->getStringLength()*(label->getSystemFontSize() / 2);label->setPositionX(label->getPositionX() &#; dirX);if (dirX < 0){if (label->getPositionX() < -labelWidth){//label->setPositionX(visibleSize.width);this->removeFromParent();}}else{if (label->getPositionX() > labelWidth &#; visibleSize.width){//label->setPositionX(0);this->removeFromParent();}}}void Marquee::setSpeed(int speed){m_speed = speed;}int Marquee::getSpeed(){return m_speed;}void Marquee::onEnter(){Layer::onEnter();}void Marquee::onExit(){Layer::onExit();}

================================================调用:===============================================

调用方法:

MarqueeEffect::show("Most people... blunder round this cityMost people blunder round this cityMost people ", 6, , Color3B::RED);

cocos2dx3.3 便条提示语功能简单实现 =====================头文件===#ifndef__H_NOTETIP_H__#define__H_NOTETIP_H__#includeGlobal.hclassNoteTip:publicLayer{public:NoteTip();~NoteTip();CREATE_FUNC(NoteTip);staticvoidshow(constchar*content)

cocos2dx多边形纹理填充 演示demo:

Cocos2dx3.2编写常用UI组件(五)带滚动的表格GridView 前言:按照惯例先发上效果图:正文:先来吐槽几句,一说起滚动效果大家可能会联想到Cocos2dx给我们提供的ScrollView。我一开始也是打算用ScrollView来实

本文链接地址:https://www.jiuchutong.com/biancheng/372742.html 转载请保留说明!

上一篇:【新功能】“回调特性”的使用教程:

下一篇:cocos2dx3.3 便条提示语功能简单实现

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络