Solve the problem of gaps in two background graphs during rotation

Source: Internet
Author: User

The horizontal version of the game is useful to multiple pictures appearing as dynamic backgrounds. But in the actual project, I found that the picture may have a gap when scrolling, affecting the game experience. After analysis, this is due to the time difference when resetting the buffered picture .

Turns show the principle is a picture scrolling, the other as a buffer, scrolling out of the screen image and then replaced as a buffer, so that the cycle of rotation.

To give an example:

void Testsprite::onenter () {cclayer::onenter (); Ccactioninterval *move1 = ccmoveby::create (5, CCP (-480, 0)); Cccallfunc *moveagain = Cccallfunc::create (This, Callfunc_selector (Testsprite::callback)); Ccactioninterval *move2 = Ccmoveby::create (, CCP (-960, 0)); Ccsequence *seq = ccsequence::create (move1, Moveagain, NULL); m_bg1->runaction (seq); m_bg2->runaction (move2);} void Testsprite::callback () {M_bg1->setpositionx (480); Ccactioninterval *move = Ccmoveby::create (Ten, CCP ( -960, 0)); m_bg1->runaction (move);}

M_bg1 and M_bg2 refer to two white opaque cclayercolor, which are the same size as the screen, and they begin to move the distance from the screen width to the left. Since it is started at the same time, there is no gap at first. But after M_bg1 moved out of the screen, it went back to the right side of the screen as a buffer into the screen, and then there was a gap. What is this for?

Originally in the M_BG1 "buffer" process, m_bg2 still in the nonstop move. This gap is m_bg1 to buffer the time between the two sides opened the distance, although very small, but also very conspicuous.

The time it takes to call the callback function from M_BG1 to the end of the call is inevitably consumed.

Workaround:

Therefore, want to not appear the gap, I think of the method is m_bg1 to buffer, its position slightly forward, and m_bg2 coincident a little bit, so that the gap "fill" on the. But now that has moved a little forward, the total mobile distance can not change, you can no longer use the relative displacement action Moveby, had to use MoveTo to specify an absolute position. See Code:

M_bg1->setpositionx (480-5); Ccactioninterval *move = Ccmoveto::create (Ten, CCP ( -480, 0)); m_bg1->runaction (move);

So the gap is gone.

New questions:

But here's another small problem, which is that there is overlap between the two layers. The project often joins other nodes on the layer, so if the nodes appear in overlapping areas, there will be a display problem (which will also be partially overwritten). Therefore, in the actual development, it is important to avoid nodes appearing in such areas.

Solve the problem of gaps in two background graphs during rotation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.