cocos2dx-3.10 聊天系统实现(C++实现)

Cocos2d-x 3.0 开发(四)使用CocoStudio创建UI并载入到程序中 CocoStudio的使用无疑是cocos2d-x 3.0的重要组成部分,接下来我们用它来创建一组UI,并将其读入到程序中显示出来。先上效果图: 阅读详情

cocos2dx-3.10  聊天系统实现(C++实现)

1.版权声明

    转载请注明出处:http://write.blog.csdn.net/postedit/51910754


2.前言

      一直忙着,没空写,趁中秋有点空,就码上奋斗。

      本期介绍聊天系统制作,使用ListView和RichText 完成,本期重点是官方富文本RickText类的修改

       附上效果图:

        

3.内容

      介绍RichText的修改,由于官方的RickText 不支持描边、下划线、超链接,这里面将对官方RichText进行改造:
       因为用的是官方的预编译库,没有cpp源码,再就是为了不影响源码,就新建了自己的RichUI类。
      首先新建RichUI.h头文件,找到官方的UIRichText.h,拷贝内容至刚新建的RichUI.h头文件中,修改其中几处内容:
      将namespace ui改下,避免和官方冲突,主要做的修改的在RichElementText里,这里贴上我修改好的:
      
#ifndef __RICHUI_H__
#define __RICHUI_H__

#include "ui/UIWidget.h"
#include "cocos2d.h"
USING_NS_CC;

NS_CC_BEGIN
/**
* @addtogroup cui
* @modify source code by iuoon@zhejiang.china
*/

namespace cui {

	/**
	*@brief Rich text element base class.
	* It defines the basic common properties for all rich text element.
	*/
	class  RichElement : public Ref
	{
	public:
		/**
		*@brief Rich element type.
		*/
		enum class Type
		{
			TEXT,
			IMAGE,
			CUSTOM,
			NEWLINE
		};

		/**
		* @brief Default constructor.
		* @js ctor
		* @lua new
		*/
		RichElement() {};

		/**
		* @brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichElement() {};


		/**
		* @brief Initialize a rich element with different arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in @see `Color3B`.
		* @param opacity A opacity value in `GLubyte`.
		* @return True if initialize success, false otherwise.
		*/
		bool init(int tag, const Color3B& color, GLubyte opacity);
	protected:
		Type _type;
		int _tag;
		CC_SYNTHESIZE(std::string, _pramas, Pramas);
		Color3B _color;
		GLubyte _opacity;
		friend class RichText;
	};

	/**
	*@brief Rich element for displaying text.
	*/
	class  RichElementText : public RichElement
	{
	public:

		/**
		*@brief Default constructor.
		* @js ctor
		* @lua new
		*/
		RichElementText() { 
			_type = Type::TEXT;
			_outLine = -1;
			_outLineColor = Color4B::BLACK;
			_shadow = false;
			_linkurl = "";
			_underLinecolor = Color4B(0, 0, 0, 0);
			_underLinesize = -1;
			_touchCallback = nullptr;
		};


		/**
		*@brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichElementText() {};

		/**
		* @brief Initialize a RichElementText with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param text Content string.
		* @param fontName Content font name.
		* @param fontSize Content font size.
		* @return True if initialize scucess, false otherwise.
		*/
		bool init(int tag, const Color3B& color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize);


		/**
		* @brief Create a RichElementText with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param text Content string.
		* @param fontName Content font name.
		* @param fontSize Content font size.
		* @return RichElementText instance.
		*/
		static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize);
	
		void setTouchCallBack(std::function<void(std::string)> touch, std::string tag);
		void setLinkUrl(std::string linkurl);
	
	protected:
		std::string _text;
		std::string _fontName;
		float _fontSize;
		friend class RichText;
		/**************************************/
	protected:
//		CC_SYNTHESIZE(Color4B, _textColor, TextColor); //设置字体颜色
		CC_SYNTHESIZE(int, _outLine, OutLine);  //描边大小
		CC_SYNTHESIZE(Color4B, _outLineColor, OutLineColor);//描边颜色
		CC_SYNTHESIZE(bool, _shadow, Shadow); //启用阴影
		CC_SYNTHESIZE_READONLY(std::string, _linkurl, LinkUrl);//设置链接(或点击事件当参数传输)
		CC_SYNTHESIZE(Color4B, _underLinecolor, UnderLineColor);//下划线颜色
		CC_SYNTHESIZE(int, _underLinesize, UnderLineSize); //下划线大小
		CC_SYNTHESIZE_READONLY(std::function<void(std::string)>, _touchCallback, TouchCallBack);//点击回调函数

	private:
		void linkCallback(std::string str);

	};

	/**
	*@brief Rich element for displaying images.
	*/
	class  RichElementImage : public RichElement
	{
	public:

		/**
		* @brief Default constructor.
		* @js ctor
		* @lua new
		*
		*/
		RichElementImage() { _type = Type::IMAGE; };


		/**
		* @brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichElementImage() {};


		/**
		* @brief Initialize a RichElementImage with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param filePath A image file name.
		* @return True if initialize success, false otherwise.
		*/
		bool init(int tag, const Color3B& color, GLubyte opacity, const std::string& filePath);


		/**
		* @brief Create a RichElementImage with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param filePath A image file name.
		* @return A RichElementImage instance.
		*/
		static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const std::string& filePath);
	protected:
		std::string _filePath;
		Rect _textureRect;
		int _textureType;
		friend class RichText;
	};

	/**
	*@brief Rich element for displaying custom node type.
	*/
	class  RichElementCustomNode : public RichElement
	{
	public:

		/**
		* @brief Default constructor.
		* @js ctor
		* @lua new
		*/
		RichElementCustomNode() { _type = Type::CUSTOM; };


		/**
		* @brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichElementCustomNode() { CC_SAFE_RELEASE(_customNode); };


		/**
		* @brief Initialize a RichElementCustomNode with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param customNode A custom node pointer.
		* @return True if initialize success, false otherwise.
		*/
		bool init(int tag, const Color3B& color, GLubyte opacity, Node* customNode);

		/**
		* @brief Create a RichElementCustomNode with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @param customNode A custom node pointer.
		* @return A RichElementCustomNode instance.
		*/
		static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode);
	protected:
		Node* _customNode;
		friend class RichText;
	};

	/**
	*@brief Rich element for new line.
	*/
	class  RichElementNewLine : public RichElement
	{
	public:

		/**
		* @brief Default constructor.
		* @js ctor
		* @lua new
		*
		*/
		RichElementNewLine() { _type = Type::NEWLINE; };

		/**
		* @brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichElementNewLine() {};

		/**
		* @brief Create a RichElementNewLine with various arguments.
		*
		* @param tag A integer tag value.
		* @param color A color in Color3B.
		* @param opacity A opacity in GLubyte.
		* @return A RichElementNewLine instance.
		*/
		static RichElementNewLine* create(int tag, const Color3B& color, GLubyte opacity);
	protected:
		friend class RichText;
	};

	/**
	*@brief A container for displaying various RichElements.
	* We could use it to display texts with images easily.
	*/
	class  RichText : public ui::Widget
	{
	public:

		/**
		* @brief Default constructor.
		* @js ctor
		* @lua new
		*/
		RichText();

		/**
		* @brief Default destructor.
		* @js NA
		* @lua NA
		*/
		virtual ~RichText();

		/**
		* @brief Create a empty RichText.
		*
		* @return RichText instance.
		*/
		static RichText* create();

		/**
		* @brief Insert a RichElement at a given index.
		*
		* @param element A RichElement type.
		* @param index A given index.
		*/
		void insertElement(RichElement* element, int index);

		/**
		* @brief Add a RichElement at the end of RichText.
		*
		* @param element A RichElement instance.
		*/
		void pushBackElement(RichElement* element);

		/**
		* @brief Remove a RichElement at a given index.
		*
		* @param index A integer index value.
		*/
		void removeElement(int index);

		/**
		* @brief Remove specific RichElement.
		*
		* @param element A RichElement type.
		*/
		void removeElement(RichElement* element);

		/**
		* @brief Set vertical space between each RichElement.
		*
		* @param space Point in float.
		*/
		void setVerticalSpace(float space);

		/**
		* @brief Rearrange all RichElement in the RichText.
		* It's usually called internally.
		*/
		void formatText();

		virtual void visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;

		//override functions.
		virtual void ignoreContentAdaptWithSize(bool ignore) override;
		virtual std::string getDescription() const override;

	CC_CONSTRUCTOR_ACCESS:
		virtual bool init() override;
		virtual void onEnter() override;
		virtual void onExit() override;

	protected:
		virtual void adaptRenderers() override;

		virtual void initRenderer() override;
		void pushToContainer(Node* renderer);
		void handleTextRenderer(const RichElementText& textInfo);
	//	void handleTextRenderer(const std::string& text, const std::string& fontName, float fontSize, const Color3B& color, GLubyte opacity);
		void handleImageRenderer(const std::string& fileParh, const Color3B& color, GLubyte opacity);
		void handleCustomRenderer(Node* renderer);
		void formarRenderers();
		void addNewLine();

		bool onTouchBegan(Touch *touch, Event *unusedEvent);
		void onTouchEnded(Touch *touch, Event *unusedEvent);

		CC_SYNTHESIZE(int, _touchPriority, TouchPriority);
	protected:
		bool _formatTextDirty;
		Vector<RichElement*> _richElements;
		std::vector<Vector<Node*>*> _elementRenders;
		std::map<Node*, std::function<void(std::string)> > _touchDelegate;//定义node对应的事件
		float _leftSpaceWidth;
		float _verticalSpace;

	};

}

NS_CC_END

#endif /* defined(__RICHUI_H__) */



      同样新建RichUI.cpp文件,将UIRichText.cpp中的源码拷贝至RichUI.cpp文件中,修改部分代码日下:
#include "ui/RichUI.h"
#include "ui/UIHelper.h"

NS_CC_BEGIN

namespace cui {


	bool RichElement::init(int tag, const Color3B &color, GLubyte opacity)
	{
		_tag = tag;
		_color = color;
		_opacity = opacity;
		return true;
	}


	RichElementText* RichElementText::create(int tag, const Color3B &color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize)
	{
		RichElementText* element = new (std::nothrow) RichElementText();
		if (element && element->init(tag, color, opacity, text, fontName, fontSize))
		{
			element->autorelease();
			return element;
		}
		CC_SAFE_DELETE(element);
		return nullptr;
	}

	bool RichElementText::init(int tag, const Color3B &color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize)
	{
		if (RichElement::init(tag, color, opacity))
		{
			_text = text;
			_fontName = fontName;
			_fontSize = fontSize;
			return true;
		}
		return false;
	}

	void RichElementText::setTouchCallBack(std::function<void(std::string)> touch, std::string pramas)
	{
		_touchCallback = touch;
		_pramas = pramas;
	}

	void RichElementText::setLinkUrl(std::string linkurl)
	{
		_linkurl = linkurl;
		setTouchCallBack(std::bind(&RichElementText::linkCallback, this, std::placeholders::_1), linkurl);
	}

	void RichElementText::linkCallback(std::string str)
	{
		log("call open url %s", str.c_str());
	}

	RichElementImage* RichElementImage::create(int tag, const Color3B &color, GLubyte opacity, const std::string& filePath)
	{
		RichElementImage* element = new (std::nothrow) RichElementImage();
		if (element && element->init(tag, color, opacity, filePath))
		{
			element->autorelease();
			return element;
		}
		CC_SAFE_DELETE(element);
		return nullptr;
	}

	bool RichElementImage::init(int tag, const Color3B &color, GLubyte opacity, const std::string& filePath)
	{
		if (RichElement::init(tag, color, opacity))
		{
			_filePath = filePath;
			return true;
		}
		return false;
	}

	RichElementCustomNode* RichElementCustomNode::create(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode)
	{
		RichElementCustomNode* element = new (std::nothrow) RichElementCustomNode();
		if (element && element->init(tag, color, opacity, customNode))
		{
			element->autorelease();
			return element;
		}
		CC_SAFE_DELETE(element);
		return nullptr;
	}

	bool RichElementCustomNode::init(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode)
	{
		if (RichElement::init(tag, color, opacity))
		{
			_customNode = customNode;
			_customNode->retain();
			return true;
		}
		return false;
	}

	RichElementNewLine* RichElementNewLine::create(int tag, const Color3B& color, GLubyte opacity)
	{
		RichElementNewLine* element = new (std::nothrow) RichElementNewLine();
		if (element && element->init(tag, color, opacity))
		{
			element->autorelease();
			return element;
		}
		CC_SAFE_DELETE(element);
		return nullptr;
	}

	RichText::RichText() :
		_formatTextDirty(true),
		_leftSpaceWidth(0.0f),
		_verticalSpace(0.0f),
		_touchPriority(-1)
	{
		_touchDelegate.clear();
	}

	RichText::~RichText()
	{
		_richElements.clear();
		//
		std::map<Node*, std::function<void(std::string)> >::const_iterator it = _touchDelegate.begin();
		while (it != _touchDelegate.end())
		{
			Node* node = it->first;
			if (node->getUserData() != nullptr)
			{
				delete (std::string*)(node->getUserData());
				node->setUserData(nullptr);
			}
			++it;
		}
		_touchDelegate.clear();
	}

	/***************可以重写改造换行******************/
	RichText* RichText::create()
	{
		RichText* widget = new (std::nothrow) RichText();
		if (widget && widget->init())
		{
			widget->autorelease();
			return widget;
		}
		CC_SAFE_DELETE(widget);
		return nullptr;
	}

	bool RichText::init()
	{
		if (Widget::init())
		{
			return true;
		}
		return false;
	}

	void RichText::onEnter()
	{
		Widget::onEnter();
		EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
		listener->setSwallowTouches(true);
		listener->onTouchBegan = CC_CALLBACK_2(RichText::onTouchBegan, this);
		listener->onTouchEnded = CC_CALLBACK_2(RichText::onTouchEnded, this);
		_eventDispatcher->addEventListenerWithFixedPriority(listener, _touchPriority);
	}

	void RichText::onExit()
	{
		Widget::onExit();
		_eventDispatcher->removeAllEventListeners();
	}

	void RichText::initRenderer()
	{

	}

	void RichText::insertElement(RichElement *element, int index)
	{
		_richElements.insert(index, element);
		_formatTextDirty = true;
	}

	void RichText::pushBackElement(RichElement *element)
	{
		_richElements.pushBack(element);
		_formatTextDirty = true;
	}

	void RichText::removeElement(int index)
	{
		_richElements.erase(index);
		_formatTextDirty = true;
	}

	void RichText::removeElement(RichElement *element)
	{
		_richElements.eraseObject(element);
		_formatTextDirty = true;
	}

	void RichText::formatText()
	{
		if (_formatTextDirty)
		{
			this->removeAllProtectedChildren();
			_elementRenders.clear();
			if (_ignoreSize)
			{
				addNewLine();
				for (ssize_t i = 0; i<_richElements.size(); i++)
				{
					RichElement* element = _richElements.at(i);
					Node* elementRenderer = nullptr;
					switch (element->_type)
					{
					case RichElement::Type::TEXT:
					{
						Label* elementLabel = nullptr;
						RichElementText* elmtText = static_cast<RichElementText*>(element);
						if (FileUtils::getInstance()->isFileExist(elmtText->_fontName))
						{
							elementLabel = Label::createWithTTF(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize);
						}
						else
						{
							elementLabel = Label::createWithSystemFont(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize);
						}
						if (elmtText->getOutLine() > 0)
						{
							elementLabel->enableOutline(elmtText->getOutLineColor(), elmtText->getOutLine());
						}
						if (elmtText->getShadow())
						{
							elementLabel->enableShadow();
						}
						if (elmtText->getUnderLineSize() > 0)
						{
							LayerColor* l = nullptr;
							if (elmtText->getUnderLineColor().a == 0)
							{
								l = LayerColor::create(Color4B(elmtText->_color), elementLabel->getContentSize().width, elmtText->getUnderLineSize());
							}
							else
							{
								l = LayerColor::create(elmtText->getUnderLineColor(), elementLabel->getContentSize().width, elmtText->getUnderLineSize());
							}
							elementLabel->setUserObject(l);
						}
						if (elmtText->getTouchCallBack())
						{
							std::string* tag = new std::string(""+elmtText->getPramas());
							elementLabel->setUserData(tag);
							_touchDelegate[elementLabel] = elmtText->getTouchCallBack();
						}
						elementRenderer = elementLabel;
						
						break;
					}
					case RichElement::Type::IMAGE:
					{
						RichElementImage* elmtImage = static_cast<RichElementImage*>(element);
						elementRenderer = Sprite::create(elmtImage->_filePath.c_str());
						break;
					}
					case RichElement::Type::CUSTOM:
					{
						RichElementCustomNode* elmtCustom = static_cast<RichElementCustomNode*>(element);
						elementRenderer = elmtCustom->_customNode;
						break;
					}
					case RichElement::Type::NEWLINE:
					{
						addNewLine();
						break;
					}
					default:
						break;
					}
					elementRenderer->setColor(element->_color);
					elementRenderer->setOpacity(element->_opacity);
					pushToContainer(elementRenderer);
				}
			}
			else
			{
				addNewLine();
				for (ssize_t i = 0; i<_richElements.size(); i++)
				{

					RichElement* element = static_cast<RichElement*>(_richElements.at(i));
					switch (element->_type)
					{
					case RichElement::Type::TEXT:
					{
						RichElementText* elmtText = static_cast<RichElementText*>(element);
						handleTextRenderer(*elmtText);
						break;
					}
					case RichElement::Type::IMAGE:
					{
						RichElementImage* elmtImage = static_cast<RichElementImage*>(element);
						handleImageRenderer(elmtImage->_filePath.c_str(), elmtImage->_color, elmtImage->_opacity);
						break;
					}
					case RichElement::Type::CUSTOM:
					{
						RichElementCustomNode* elmtCustom = static_cast<RichElementCustomNode*>(element);
						handleCustomRenderer(elmtCustom->_customNode);
						break;
					}
					case RichElement::Type::NEWLINE:
					{
						addNewLine();
						break;
					}
					default:
						break;
					}
				}
			}
			formarRenderers();
			_formatTextDirty = false;
		}
	}

	void RichText::visit(Renderer * renderer, const Mat4 & parentTransform, uint32_t parentFlags)
	{
		if (_enabled)
		{
			formatText();
			Widget::visit(renderer, parentTransform, parentFlags);
		}
	}


	void RichText::handleTextRenderer(const RichElementText& textInfo)
	{
		auto fileExist = FileUtils::getInstance()->isFileExist(textInfo._fontName);
		Label* textRenderer = nullptr;
		if (fileExist)
		{
			textRenderer = Label::createWithTTF(textInfo._text, textInfo._fontName, textInfo._fontSize);
		}
		else
		{
			textRenderer = Label::createWithSystemFont(textInfo._text, textInfo._fontName, textInfo._fontSize);
		}
		

		float textRendererWidth = textRenderer->getContentSize().width;
		_leftSpaceWidth -= textRendererWidth;
		if (_leftSpaceWidth < 0.0f)
		{
			float overstepPercent = (-_leftSpaceWidth) / textRendererWidth;
			std::string curText = textInfo._text;
			size_t stringLength = StringUtils::getCharacterCountInUTF8String(textInfo._text);
			int leftLength = stringLength * (1.0f - overstepPercent);

			// The adjustment of the new line position
			auto originalLeftSpaceWidth = _leftSpaceWidth + textRendererWidth;
			auto leftStr = ui::Helper::getSubStringOfUTF8String(curText, 0, leftLength);
			textRenderer->setString(leftStr);
			auto leftWidth = textRenderer->getContentSize().width;
			if (originalLeftSpaceWidth < leftWidth) {
				// Have protruding
				for (;;) {
					leftLength--;
					leftStr = ui::Helper::getSubStringOfUTF8String(curText, 0, leftLength);
					textRenderer->setString(leftStr);
					leftWidth = textRenderer->getContentSize().width;
					if (leftWidth <= originalLeftSpaceWidth) {
						break;
					}
					else if (leftLength <= 0) {
						break;
					}
				}
			}
			else if (leftWidth < originalLeftSpaceWidth) {
				// A wide margin
				for (;;) {
					leftLength++;
					leftStr = ui::Helper::getSubStringOfUTF8String(curText, 0, leftLength);
					textRenderer->setString(leftStr);
					leftWidth = textRenderer->getContentSize().width;
					if (originalLeftSpaceWidth < leftWidth) {
						leftLength--;
						break;
					}
					else if (stringLength <= leftLength) {
						break;
					}
				}
			}

			//The minimum cut length is 1, otherwise will cause the infinite loop.
			if (0 == leftLength) leftLength = 1;
			std::string leftWords = ui::Helper::getSubStringOfUTF8String(curText, 0, leftLength);
			std::string cutWords = ui::Helper::getSubStringOfUTF8String(curText, leftLength, stringLength - leftLength);
			if (leftLength > 0)
			{
				Label* leftRenderer = nullptr;
				if (fileExist)
				{
					leftRenderer = Label::createWithTTF(ui::Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), textInfo._fontName, textInfo._fontSize);
				}
				else
				{
					leftRenderer = Label::createWithSystemFont(ui::Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), textInfo._fontName, textInfo._fontSize);
				}
				if (leftRenderer)
				{
					leftRenderer->setColor(textInfo._color);
					leftRenderer->setOpacity(textInfo._opacity);
					if (textInfo.getOutLine() > 0)
					{
						leftRenderer->enableOutline(textInfo.getOutLineColor(), textInfo.getOutLine());
					}
					if (textInfo.getShadow())
					{
						leftRenderer->enableShadow();
					}
					if (textInfo.getUnderLineSize() > 0)
					{
						LayerColor* l = nullptr;
						if (textInfo.getUnderLineColor().a == 0)
						{
							l = LayerColor::create(Color4B(textInfo._color), leftRenderer->getContentSize().width, textInfo.getUnderLineSize());
						}
						else
						{
							l = LayerColor::create(textInfo.getUnderLineColor(), leftRenderer->getContentSize().width, textInfo.getUnderLineSize());
						}
						leftRenderer->setUserObject(l);
					}
					if (textInfo.getTouchCallBack())
					{
						std::string* tag = new std::string(textInfo.getPramas());
						leftRenderer->setUserData(tag);
						_touchDelegate[leftRenderer] = textInfo.getTouchCallBack();
					}

					pushToContainer(leftRenderer);
				}
			}

			addNewLine();
			RichElementText cutRich = textInfo;
			cutRich._text=cutWords;
			handleTextRenderer(cutRich);
		}
		else
		{
			textRenderer->setColor(textInfo._color);
			textRenderer->setOpacity(textInfo._opacity);

			if (textInfo.getOutLine() > 0)
			{
				textRenderer->enableOutline(textInfo.getOutLineColor(), textInfo.getOutLine());
			}
			if (textInfo.getShadow())
			{
				textRenderer->enableShadow();
			}
			if (textInfo.getUnderLineSize() > 0)
			{
				LayerColor* l = nullptr;
				if (textInfo.getUnderLineColor().a == 0)
				{
					l = LayerColor::create(Color4B(textInfo._color), textRenderer->getContentSize().width, textInfo.getUnderLineSize());
				}
				else
				{
					l = LayerColor::create(textInfo.getUnderLineColor(), textRenderer->getContentSize().width, textInfo.getUnderLineSize());
				}
				textRenderer->setUserObject(l);
			}
			if (textInfo.getTouchCallBack())
			{
				std::string* tag = new std::string(textInfo.getPramas());
				textRenderer->setUserData(tag);
				_touchDelegate[textRenderer] = textInfo.getTouchCallBack();
			}

			pushToContainer(textRenderer);
		}
	}

	void RichText::handleImageRenderer(const std::string& fileParh, const Color3B &color, GLubyte opacity)
	{
		Sprite* imageRenderer = Sprite::create(fileParh);
		handleCustomRenderer(imageRenderer);
	}

	void RichText::handleCustomRenderer(cocos2d::Node *renderer)
	{
		Size imgSize = renderer->getContentSize();
		_leftSpaceWidth -= imgSize.width;
		if (_leftSpaceWidth < 0.0f)
		{
			addNewLine();
			pushToContainer(renderer);
			_leftSpaceWidth -= imgSize.width;
		}
		else
		{
			pushToContainer(renderer);
		}
	}

	void RichText::addNewLine()
	{
		_leftSpaceWidth = _customSize.width;
		_elementRenders.push_back(new Vector<Node*>());
	}

	bool RichText::onTouchBegan(Touch * touch, Event * unusedEvent)
	{
		std::map<Node*, std::function<void(std::string)> >::const_iterator it = _touchDelegate.begin();
		while (it != _touchDelegate.end())
		{
			Node* node = it->first;
			if (node->getBoundingBox().containsPoint(node->getParent()->convertTouchToNodeSpace(touch)))
			{
				return true;
			}
			++it;
		}
		return false;
	}

	void RichText::onTouchEnded(Touch * touch, Event * unusedEvent)
	{
		std::map<Node*, std::function<void(std::string)> >::const_iterator it = _touchDelegate.begin();
		while (it != _touchDelegate.end())
		{
			Node* node = it->first;
			if (node->getBoundingBox().containsPoint(node->getParent()->convertTouchToNodeSpace(touch)))
			{
				if (node->getUserData() != nullptr)
				{
					(it->second)(*((std::string*)node->getUserData()));
				}

				return;
			}
			++it;
		}
	}

	void RichText::formarRenderers()
	{
		if (_ignoreSize)
		{
			float newContentSizeWidth = 0.0f;
			float newContentSizeHeight = 0.0f;

			Vector<Node*>* row = (_elementRenders[0]);
			float nextPosX = 0.0f;
			for (ssize_t j = 0; j<row->size(); j++)
			{
				Node* l = row->at(j);
				l->setAnchorPoint(Vec2::ZERO);
				l->setPosition(nextPosX, 0.0f);
				this->addProtectedChild(l, 1);
				/****这里将下划线显示*************/
				Node* under = dynamic_cast<Node*>(l->getUserObject());
				if (under)
				{
					under->setPosition(Point(nextPosX, -1));
					this->addProtectedChild(under,1);
					l->setUserObject(nullptr);
				}
				/**********************************/
				Size iSize = l->getContentSize();
				newContentSizeWidth += iSize.width;
				newContentSizeHeight = MAX(newContentSizeHeight, iSize.height);
				nextPosX += iSize.width;
			}
			this->setContentSize(Size(newContentSizeWidth, newContentSizeHeight));
		}
		else
		{
			float newContentSizeHeight = 0.0f;
			float *maxHeights = new float[_elementRenders.size()];

			for (size_t i = 0; i<_elementRenders.size(); i++)
			{
				Vector<Node*>* row = (_elementRenders[i]);
				float maxHeight = 0.0f;
				for (ssize_t j = 0; j<row->size(); j++)
				{
					Node* l = row->at(j);
					maxHeight = MAX(l->getContentSize().height, maxHeight);
				}
				maxHeights[i] = maxHeight;
				newContentSizeHeight += maxHeights[i];
			}

			float nextPosY = _customSize.height;
			for (size_t i = 0; i<_elementRenders.size(); i++)
			{
				Vector<Node*>* row = (_elementRenders[i]);
				float nextPosX = 0.0f;
				nextPosY -= (maxHeights[i] + _verticalSpace);

				for (ssize_t j = 0; j<row->size(); j++)
				{
					Node* l = row->at(j);
					l->setAnchorPoint(Vec2::ZERO);
					l->setPosition(nextPosX, nextPosY);
					this->addProtectedChild(l, 1);
					/****这里将下划线显示*************/
					Node* under = dynamic_cast<Node*>(l->getUserObject());
					if (under)
					{
						under->setPosition(Point(nextPosX, nextPosY - 1));
						this->addProtectedChild(under,1);
						l->setUserObject(nullptr);
					}
					/**********************************/
					nextPosX += l->getContentSize().width;
				}
			}
			delete[] maxHeights;
		}

		size_t length = _elementRenders.size();
		for (size_t i = 0; i<length; i++)
		{
			Vector<Node*>* l = _elementRenders[i];
			l->clear();
			delete l;
		}
		_elementRenders.clear();

		if (_ignoreSize)
		{
			Size s = getVirtualRendererSize();
			this->setContentSize(s);
		}
		else
		{
			this->setContentSize(_customSize);
		}
		updateContentSizeWithTextureSize(_contentSize);
	}

	void RichText::adaptRenderers()
	{
		this->formatText();
	}

	void RichText::pushToContainer(cocos2d::Node *renderer)
	{
		if (_elementRenders.size() <= 0)
		{
			return;
		}
		_elementRenders[_elementRenders.size() - 1]->pushBack(renderer);
	}

	void RichText::setVerticalSpace(float space)
	{
		_verticalSpace = space;
	}

	void RichText::ignoreContentAdaptWithSize(bool ignore)
	{
		if (_ignoreSize != ignore)
		{
			_formatTextDirty = true;
			Widget::ignoreContentAdaptWithSize(ignore);
		}
	}

	std::string RichText::getDescription() const
	{
		return "RichText";
	}

	

}

NS_CC_END

   到了接近成功的一半了,下面新建ChatUI,这里面需要注意的是,RichUI需要设置尺寸大小的,这里需要根据发送内容动态调整RichUI的尺寸大小,
  否则如果发送内容过长,我们的消息就会叠到一块了。
 
#pragma once
#ifndef _CHAT_UI_H_
#define _CHAT_UI_H_

#include "cocos2d.h"
#include <string.h>
#include "ui/RichUI.h"

USING_NS_CC;
using namespace std;
using namespace cocos2d::cui;

class ChatUI :public cocos2d::Layer
{
public:
	ChatUI();
	~ChatUI();

	static cocos2d::Scene* createScene();

	virtual bool init();

	CREATE_FUNC(ChatUI);

	void initRichEdit();

	cui::RichText* getChatMsg(int channel, string roleName, string chatMsg, char* signs);

private:
	cui::RichText* _richBugle;//喇叭

};



#endif

#include "ui/ChatUI.h"
#include "util/FontChina.h"
#include "ui/UIText.h"


ChatUI::ChatUI()
{
}

ChatUI::~ChatUI()
{
}

cocos2d::Scene * ChatUI::createScene()
{
	auto scene = Scene::create();
	auto layer = ChatUI::create();
	scene->addChild(layer);
	return scene;
}


bool ChatUI::init()
{
	if (!Layer::init())
	{
		return false;
	}
	this->initRichEdit();
	return true;
}


void ChatUI::initRichEdit()
{
	
}

cui::RichText* ChatUI::getChatMsg(int channel, string  roleName, string  chatMsg, char * signs)
{
	string chanStr = "【当前】";
	string siz = ":";
	int msglen = chatMsg.size() + siz.size()+ chanStr.size() + roleName.size();
	int s = msglen / 44;
	if (msglen%44>0)
	{
		s += 1;
	}
	cui::RichText* _richChat = cui::RichText::create();
	_richChat->ignoreContentAdaptWithSize(false);
	if (s==1)
	{
		_richChat->setContentSize(Size(268, 18 * s));
	}
	else {
		_richChat->setContentSize(Size(268, 15 * s+3));
	}
		
	RichElementText* res = new RichElementText();
	RichElementText* resrole = new RichElementText();
	
	if (channel==1)
	{
		chanStr = "【世界】";
		res = RichElementText::create(1, Color3B::YELLOW, 255, FontChina::getStringUTF8(chanStr), "font/simkai.ttf", 15);
	}
	else if (channel == 2) {
		chanStr = "【地区】";
		res = RichElementText::create(1, Color3B::ORANGE, 255, FontChina::getStringUTF8(chanStr), "font/simkai.ttf", 15);
	}
	else if (channel == 3) {
		chanStr = "【系统】";
		res = RichElementText::create(1, Color3B::RED, 255, FontChina::getStringUTF8(chanStr), "font/simkai.ttf", 15);
	}
	else {
		res = RichElementText::create(1, Color3B::WHITE, 255, FontChina::getStringUTF8(chanStr), "font/simkai.ttf", 15);
	}
	resrole = RichElementText::create(1, Color3B::GREEN, 255, FontChina::getStringUTF8(roleName), "font/simkai.ttf", 15);
	resrole->setUnderLineSize(1);
	resrole->setUnderLineColor(Color4B::GREEN);
	auto fuhao= RichElementText::create(1, Color3B::BLACK, 255, FontChina::getStringUTF8(":"), "font/simkai.ttf", 15);
	auto re = RichElementText::create(1, Color3B(0, 255, 255), 255, chatMsg , "font/simkai.ttf", 15);
	
	_richChat->pushBackElement(res);
	_richChat->pushBackElement(resrole);
	if (channel != 3)
	{
		_richChat->pushBackElement(fuhao);
	}	
	_richChat->pushBackElement(re);
	RichElementNewLine* line = RichElementNewLine::create(1,Color3B::WHITE,255);
	_richChat->pushBackElement(line);

	return _richChat;
}

新建MianScene,完成场景加载:
 
#ifndef _MAIN_SCENE_H_
#define _MAIN_SCENE_H_
#include "cocos2d.h"
#include "ui/CocosGUI.h"//UI相关的头文件
#include "cocostudio/CocoStudio.h"
#include "ui/ChatUI.h"

USING_NS_CC;

class MainScene :public cocos2d::Layer
{

public:
	MainScene();
	~MainScene();

	static cocos2d::Scene* createScene();

	virtual bool init();

	CREATE_FUNC(MainScene);

	void sendChatMsg(Ref * pSender, ui::Widget::TouchEventType type);


public:
	Node* _ui_node;
	ChatUI* _chat;
	ui::TextField* _textfield;
	ui::ListView* _listview;
	int index;
	cui::RichText* _text;

};


#endif

#include "scene/MainScene.h"
#include "YijianScene.h"
#include "util/FontChina.h"


MainScene::MainScene()
{
	index = 1;
}

MainScene::~MainScene()
{
}


cocos2d::Scene * MainScene::createScene()
{
	auto scene = Scene::create();

	auto layer = MainScene::create();

	scene->addChild(layer);
	return scene;
}

bool MainScene::init()
{
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	_ui_node = CSLoader::createNode("scene/UILayer.csb");
	this->addChild(_ui_node, 200,100);

	_listview = static_cast<ui::ListView*>(_ui_node->getChildByName("ListView_1"));
	_listview->setBright(true);

	auto enterbt = static_cast<ui::Button*>(_ui_node->getChildByName("Button_3"));
	enterbt->addTouchEventListener(CC_CALLBACK_2(MainScene::sendChatMsg, this));

	//从服务端获取角色所在地图,这里默认加载
	auto yjlayer = YijianScene::createScene();
	this->addChild(yjlayer, 1,200);
	
	_chat = ChatUI::create();
	_text = _chat->getChatMsg(3, "", FontChina::getStringUTF8("欢迎【醉不忆情丝】上线,登陆IP地址:192.168.1.118"), "");
	_listview->insertCustomItem(_text, 0);


	return true;
}

void MainScene::sendChatMsg(Ref * pSender, ui::Widget::TouchEventType type)
{
	switch (type)
	{
	case cocos2d::ui::Widget::TouchEventType::BEGAN:
		break;
	case cocos2d::ui::Widget::TouchEventType::MOVED:
		break;
	case cocos2d::ui::Widget::TouchEventType::ENDED:{
		_textfield = static_cast<ui::TextField*>(_ui_node->getChildByName("TextField_1"));
		if (_textfield->getString().compare("")!=0)
		{
			_text = _chat->getChatMsg(0, "醉不忆情丝", _textfield->getString(), "");
			_listview->insertCustomItem(_text,index);
			_listview->sortAllChildren();
			_listview->jumpToBottom();//将最后显示在底部
			log("send message");
			index += 1;
		}
		
		break;
		}
	case cocos2d::ui::Widget::TouchEventType::CANCELED:
		break;
	default:
		break;
	}
}

 就这样,聊天初步完成。

 未完待续。
      

Cocos2dx游戏开发实践:表情气泡与技能CD效果实现 表情气泡与技能冷却时间(CD)是游戏中提升玩家互动性和策略性的重要机制。本章将概述它们的基本概念、重要性以及在游戏开发中的关键考虑因素,为后续章节打下坚实基础。技能CD是玩家使用特定技能后,必须等待一段时间后才能再次使用该技能的机制。CD的存在确保了技能使用的平衡性,避免了技能滥用导致的游戏失衡。它也是游戏设计中的核心元素之一,影响着玩家的策略选择和游戏体验。表情气泡的实现机制需要兼顾技术和用户体验。 阅读详情

相关推荐

cocos2dx-3.0功能强大的richText控件源码

http://blog.csdn.net/ljxfblog 自写richtext博文配套代码。

Cocos2dx之使用UI库结合cocostudio

使用cocostudio的UI编辑器编辑好UI界面,导出UI文件,直接在cocos2dx中使用,通过tag或者name来获取到UI控件 1、编辑ui界面,直接用模板然后拖几个控件过去 2、cocos2dx种加载这个编辑好的UI,必须先加载cocostudio库,具体操作参照: http://blog.csdn.net/yangxuan0261/article/deta

世事,为之则易,不为则难! 1万+

CocosCreator-WebSocket-Chatroom

CocosCreator-WebSocket-Demo 实现简易CocosCreator+WebSocket 聊天室 服务端在server文件夹里面,装好node.js后双击startup.bat文件就可以开启服务器了,客户端代码在assets里面

Cocos2d-x学习笔记(五)—— 常见UI界面(未完全)

对于UI界面,目前常用的有字体显示,标签,菜单,进度条,调度器。(后续添加) 我们的代码都是直接在新建项目HelloWorld中的HelloWorldScene.cpp的init()函数中操作。 字体和标签显示: CCSize s = CCDirector::sharedDirector()->getWinSize(); // !!!!!字体以及标签!!!!! // 参数:1、

u013707014的博客 1815

【网络图】:附Origin详细画图教程

网络图,是一种由节点(或顶点)和连接这些节点的边(或链路)组成的图形结构。在网络图中,节点通常代表系统中的一个实体(如项目中的一项任务、通信网络中的一个设备、或运输网络中的一个站点),而边则代表这些实体之间的直接联系或流动(如任务的先后顺序、数据的传输路径、或乘客的旅行路线)。 有向图:如果边具有方向性,即从一个节点指向另一个节点,则称为有向图。这种图常用于表示具有明确先后顺序或方向性的系统,如项目管理中的任务依赖关系。 无向图:如果图中的边没有方向,则称为无向图。它适用于表示实体间相互关联但无明确方向性的

weixin_50236590的博客 3965

硬件基础(4):(7)ADC电压采集:软件校准(标定、拟合)

在实际项目中,**软件端校准**可以有效弥补硬件方面(分压电阻误差、放大器失调、参考源误差等)带来的系统性偏差,从而提高 ADC 测量精度。下面是一个常见的**多点实测校准**流程与思路,个人感觉传感器标定的原理也只这样。

FCZlll的博客 6272

cocos2d-x lua 中 ListView scrollView tableView pageView 使用例子

1. ListView 使用local MainScene = class("MainScene", cc.load("mvc").ViewBase) function MainScene:onCreate() -- 测试ListView --[[ 注: 1.子节点如果是RichText,或是文本信息。 设置setVerticalSpace(),高度间隔。ad...

哲学天空的博客 1777

从接线到组态:手把手教你搞定PROFIBUS-DP与PA的混合网络搭建(基于西门子TIA Portal)

本文详细介绍了PROFIBUS-DP与PA混合网络的搭建方法,基于西门子TIA Portal平台,从硬件选型、网络架构设计到组态配置和现场调试,提供了一套完整的实战指南。重点解析了DP/PA耦合器的使用、地址映射策略及网络诊断技巧,帮助工程师高效构建高可靠性的工业自动化网络。

weixin_32103009的博客 311

cocos2d 关于retain、release以及autorelease

cocos2d中的内存管理采用引用计数的机制,当创建的节点使用retain则引用计数+1,使用release则引用计数-1,当节点的引用计数为0时,节点被自动释放,这个作用机制的前提是该节点对象调用了autorelease函数。 目前的cocos2d大部分类都有create函数,而create函数里面已经包含了对节点使用autorelease的部分。而像addChild的函数内部是包含调用re

u014085140的博客 677

【实战】——零代码玩转Supervisely人像分割:从标注到模型训练的数据流水线搭建

本文详细介绍了如何零代码使用Supervisely平台搭建人像分割数据流水线,从智能标注到数据集格式转换,再到模型训练与优化。Supervisely的智能标注工具和协作功能大幅提升了人像分割项目的效率,特别适合视频会议背景虚化、虚拟试衣等应用场景。

weixin_30694389的博客 433

uniapp [全端兼容] - 最新详细实现拍摄视频录像并可播放预览视频,调起本机摄像头开启录像录制完毕后保存到本机临时存放,可对拍摄的视频进行压缩处理减少文件大小不损失画质,详解录制视频并读取播放!

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,录视频,拍视频,拍摄录制视频后上传服务器,调起摄像头录视频并可预览,录视频上传,录像,uniapp录制视频并上传,录制视频并保存到本地设备,如何本地保存并播放预览,提供给用户观看MP4视频录像并上传到后端服务器完整功能源码,视频压缩,mp4文件,删除视频,录像后怎么预览,临时视频文件怎么减少压缩大小,视频压缩及上传,自己录视频并生成可播放的文件,录视频并能打开查看,视频压缩后上传,本机相册,录完怎么预

🏆 前端领域优质创作者 1万+

Pomelo+cocos2dx3.9客户端完美运行启动

Pomelo+cocos2dx3.9客户端完美运行启动

oryoung的博客 1566

YOLOv8首创原创改进:即插即用|创新的轻量化非对称多级压缩LADH检测头

总结而言,本文介绍了一种名为轻量化非对称多级压缩LADH检测头的原创改进,该改进可与YOLOv8无缝适配,并显著提升了检测器的性能。在本文中,我们介绍了一种原创改进的检测头,名为轻量化非对称多级压缩LADH检测头,它可与YOLOv8无缝适配,显著提升了检测器的性能。此外,我们引入了多级压缩的概念,通过在不同的检测层级上应用不同程度的压缩,进一步提升了检测头的轻量化特性。具体而言,我们采用了逐级减少卷积核数量和通道数量的策略,以降低模型的参数量和计算复杂度,同时保持较高的检测精度。

IbcVue的博客 2194

cocos2d(x) HTML label ;CCHTML CCHTMLLabel

这几天由于特殊需要,写了一个HTMLLabel。可以直接支持HTML的几种格式, color size 等等。 参考object C的一个ios开源控件。根据需要集成到cocos2dx中CCLabelTTF中了。 实现方式是 1、解析html标签保存各个属性。 2、调用coreText来画字体。 3、计算trueType字体的大小,设置label尺寸属性。 4、计算url的位

1万+

Open3D(C++) 基于RANSAC和TLS的点云平面拟合

针对点云平面拟合过程中出现的异常值及误差的问题,提出一种将随机采样一致算法(RANSAC)与整体最小二乘法(TLS)相结合的点云平面拟合方法。利用随机采样一致算法剔除异常值,利用整体最小二乘法对剩余有效点进行平面拟合,计算模型参数。实验结果表明,该方法与传统的特征值法、最小二乘法相比,能提高参数的估算精度,更适合对含有不同异常值及误差的点云数据进行拟合,是一种稳健的平面拟合方法。

点云侠的博客 434

Vue3 - [兼容PC和手机H5] 详细监听浏览器刷新 / 关闭 / 前进后退事件,用户点击关闭和刷新页面前 “拦截“ 操作并弹出提示框(实时监听用户关闭或刷新网页,触发时文字提醒并执行自定义操作)

vue3监听页面关闭和刷新,vue3中如何监听页面刷新和关闭事件,vue3中监听浏览器窗口关闭事件,并在窗口关闭进行操作,vue3怎么只在某个页面监听,其他页面不监听,vue3监听刷新和关闭怎么离开页面时注销释放,vue3怎么阻止浏览器前进和后退并提示,页面跳转离开后依旧可以监听到刷新和关闭,vue3怎么知道用户关闭了网页,vue3如何监听刷新网页操作并截断,vue3移动端手机h5网页手机网站监听浏览器刷新关闭,vue3当页面关闭或刷新时怎么提示用户离开不保存数据,vue3项目监听浏览器窗口或标签页关闭,并

🏆 前端领域优质创作者 1万+

Cocos2d-x 手游聊天系统Demo实现(Lua实现)

只要是程序员,不管是Java还是Android,如果不去阅读源码,只看API文档,那就只是停留于皮毛,这对我们知识体系的建立和完备以及实战技术的提升都是不利的。真正最能锻炼能力的便是直接去阅读源码,不仅限于阅读各大系统源码,还包括各种优秀的开源库。腾讯、字节跳动、阿里、百度等BAT大厂 2019-2021面试真题解析资料太多,全部展示会影响篇幅,暂时就先列举这些部分截图《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

2401_84132370的博客 1205

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

《Cocos2d-x实战(卷Ⅰ):C++开发》

《Cocos2d-x实战(卷Ⅰ):C++开发》 基础篇 第1章 准备开始 1.1 本书学习路线图 1.2 使用实例代码 第2章 Cocos2d-x介绍与环境搭建 2.1 移动平台游戏引擎介绍 2.2 Cocos2d家谱 2.3 Cocos2d-x设计目标 2.4 在Windows平台下开始开发Cocos2d-x游戏 2.4.1 ...

weixin_30376083的博客 438

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

用cocos2dx实现聊天效果

首先来看一下现在流行的短信形式,以下的图是随便找的~~ 用cocos2dx来实现它其实非常简单, 需要一个9妹,一个CCLabelTTF就可以实现,OK,先讲一下思路,再上代码 1 把要显示的字符放进LabelITTF 2 获取字符串控件的宽和高与9妹对比,如果小于9妹,则用9妹原来的宽高,否则计算应该把9妹拉到适合的大小 3 设置9妹的大小,就完成了。 代码也非常简单,上面上

9527的专栏 5343

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

quick cocos2dx lua:自定义RichText,能够解析font、br和img标签

环境: 1、Quick-Cocos2dx-Community_3.6.1_release 2、quick engine 移植了cocos2dx V3.10版的 RichText 的换行元素:RichElementNewLine 删节版代码如下 1 local RichText = class("RichText", function () 2 return c...

weixin_30824599的博客 366

linux多线程九宫格,项目实战:Qt九宫格图片资源浏览器(支持window、linux、兼容各国产系统,支持子文件夹,多选,全选,图片预览,行数与列数设置等)...

需求做嵌入式设备,需求九宫格图片资源浏览器:1.设置根目录;2.可拖动;3.可设置列数与行数;4.点击文件夹可以进入文件夹;5.点击图片可以浏览图片;6.支持触摸屏上下拽拖浏览;7.支持长安出现类似手机更多的操作,用于选择多个图片项做其他操作;8.可设置文件排序规则,如大小,更新时间,创建时间等等;QQ群:1047134658(点击“文件”搜索“browser”,群内与博文同步更新)#ifndef...

weixin_33755379的博客 265

cocos2d-js 控件——UIRichText

UIRichText(富文本元素基类,它定义了所有富文本元素的基本公共属性)公有属性、方法 /** * 富文本类型 */ enum class Type { TEXT, // 文本 IMAGE, // 图片 CUSTOM, // 自定义内容 NEWLINE // ? }; RichElementText(用于显示文本) /** * 创建RichElem...

在代码身上,用心去飞翔 1008

游戏开发cocos2d-x实战(5) -- UI系统

Cocos2d-x提供了GUI元素,绘制丰富多彩的界面,其中包括:Label、Menu、MenuItems、Buttons和ScrollView、Slider、LoadBar、RadioButton、CheckBox、Layout、定时器等。 1、Label Label支持四种方式的标签创建。并新增了阴影Shadow、轮廓Outline、发光Glow效果的支持。还支持文字内容的行间距、文字间距、自...

x879014419的博客 636

Cocos2dx富文本 RichText的使用

Cocos2dx富文本 RichText的使用 local richText = ccui.RichText:create() // Left:0 center:1 right:3 richText:setHorizontalAlignment(1) // 锚点 richText:setAnchorPoint(0,0.5) // 忽略内容调整缩放 richText:ignoreContentAdaptWithSize(false) // 宽高 richText:setContentSize(cc.

zihao127589的博客 2429
上一篇: 自学UE4技术文章推荐
下一篇: Cocos2d-3.10 使用Curl异步下载文件(断点续传)
iuoon
博客等级 码龄12年 50粉丝 16原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值