位置: 编程技术 - 正文
推荐整理分享cocos2dx3.3 便条提示语功能简单实现,希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!
=====================头文件===
#ifndef __H_NOTETIP_H__#define __H_NOTETIP_H__#include "Global.h"class NoteTip : public Layer{public:NoteTip();~NoteTip();CREATE_FUNC(NoteTip);static void show(const char *content);virtual bool init();virtual void onEnter();virtual void onExit();};#endif
============cpp文件======
#include "NoteTip.h"USING_NS_CC;NoteTip::NoteTip(){}NoteTip::~NoteTip(){}bool NoteTip::init(){if (!Layer::init()){return false;}return true;}void NoteTip::show(const char *content){NoteTip *noteTip = NoteTip::create();Size visibelSize = Director::getInstance()->getVisibleSize();Label *label = Label::create(content, "", );label->setAnchorPoint(Vec2::ANCHOR_MIDDLE);ui::Scale9Sprite *sp = ui::Scale9Sprite::create("general/img/NoteTip.png");float fontSize = label->getSystemFontSize();float spWidth = label->getStringLength()*(fontSize / 2);const float minWidth = ;sp->setContentSize(Size((spWidth > minWidth ? spWidth : minWidth) , fontSize ));sp->setCapInsets(Rect(6, 6, 1, 1));sp->setScale9Enabled(true);sp->setPosition(visibelSize.width/2, visibelSize.height/ 2.5f);sp->setTag();label->setPosition(sp->getContentSize()/2);sp->addChild(label);noteTip->addChild(sp);auto scene = Director::getInstance()->getRunningScene();scene->addChild(noteTip);}void NoteTip::onEnter(){Layer::onEnter();ui::Scale9Sprite *sp = (ui::Scale9Sprite*)this->getChildByTag();if (sp){auto seq = Sequence::create(MoveBy::create(1.0f, Vec2(0, )),DelayTime::create(0.2f),FadeOut::create(0.2f),CallFunc::create([&](){this->removeFromParent();}),nullptr);sp->runAction(seq);}}void NoteTip::onExit(){Layer::onExit();}
============调用方法====
NoteTip::show("Just is a TEST!!!");
cocos2dx多边形纹理填充 演示demo:
Cocos2dx3.2编写常用UI组件(五)带滚动的表格GridView 前言:按照惯例先发上效果图:正文:先来吐槽几句,一说起滚动效果大家可能会联想到Cocos2dx给我们提供的ScrollView。我一开始也是打算用ScrollView来实
cocos2dx 读取json及解析 ball.json数据如下:[html]viewplaincopy{entities:[{entity:{TapOpposite:0,Interval:0.,BallNum:1}},{entity:{TapOpposite:0,Interval:0.,BallNum:2}},{entity:{TapOpposite:0,Interval:0.,BallNum:3}}
友情链接: 武汉网站建设