How to add the announcement board (when the right side is displayed, the left side disappears)
The announcement board uses the node, the anchor position is (0, 0), the text information is saved using CCLabelTTF, and the anchor position is (0, 0). You can add it to the node when using it.
The idea of text movement is: update the coordinates of the CCLabelTTF announced every time. In order to move it from right to left, the right sidebar is displayed, and the left sidebar disappears, you need to set the display area of the CCLabelTTF. The CCLabelTTF: setTextureRect function sets the display area of the Label. Therefore, the left and right boundaries need special processing. solution:
// TODO: Initialize the announcement board void publish (); void publish (float dt); CCRect m_informRect; CCLabelTTF * m_inform; // The announcement board text float m_informScrollX; // TODO: announcement board void CMainMenu:: InitAnnounceMsg () {string strInform; Struct_Sysnotice notice; CTableCache <Struct_Sysnotice> * table = sDBMgr-> GetTable <Struct_Sysnotice> (); for (int I = 1; I <= table-> GetNumRows (); ++ I) {if (table-> GetEntry (I, using ice) {strInform + = notice. m_noticecontent; strInform + = "" ;}} CCSize size = m_nodes ["node_inform"]-> getContentSize (); m_inform = CCLabelTTF: create (strInform. c_str (), "Arial", 24); m_inform-> setAnchorPoint (ccp (0, 0); m_inform-> setPosition (CCSize (size. width, 0); m_informScrollX = size. width; m_informRect = m_inform-> getTextureRect (); m_nodes ["node_inform"]-> addChild (m_inform); this-> schedule (schedule_selector (CMainMenu: UpdateTopAnnounce ), 0.01f);} void CMainMenu: UpdateTopAnnounce (float dt) {CCPoint pt = m_nodes ["node_inform"]-> getPosition (); CCSize size = m_nodes ["node_inform"]-> getContentSize (); // left boundary of the text X axis m_informScrollX-= 1.0f; if (m_informScrollX <-m_informRect.size.width) {m_informScrollX. width; m_inform-> setTextureRect (CCRectMake (0, 0, m_informRect.size.width, size. height);} // The text is output from the right int expose = size. width-m_informScrollX; if (expose <m_informRect.size.width) {// text section not all show m_inform-> setTextureRect (CCRectMake (0, 0, expose, size. height);} The else {// text section is displayed from the right. m_inform-> setTextureRect (CCRectMake (0, 0, m_informRect.size.width, size. height);} // text disappears from the left if (m_informScrollX <= 0) {float offset = fabs (m_informScrollX); m_inform-> setTextureRect (CCRectMake (offset, 0, m_inform-> getTextureRect (). size. width-offset, size. height); return;} m_inform-> setPosition (CCSize (m_informScrollX, 0 ));}