Resolving the crash of drawing geometry using Ccdrawnode in cocos2d

Source: Internet
Author: User
Tags api manual

In Cocos2d v3.x, it is not possible to directly invoke the CCDRAWXXX function as in v2.x to draw the geometry.

We can use Ccdrawnode or ccrenderer to draw graphics.

But the official API manual makes it clear that Ccdrawnode is only recommended for debugging in the game, because changing its state must be removed and then re-added, resulting in poor performance when drawing large numbers of complex geometries.

In cocos2d v2.x, direct calls to OpenGL are generally placed in the draw method, but the actual test in v3.4 found that placing the Ccdrawnode draw on draw will cause the app to crash, with the error of not changing the state of the elements in the array when it is traversed.

I guess it's because the drawing nodes in draw will be traversed, including the ccdrawnode we added, but in draw we've modified the Ccdrawnode state so the app crashes.

In a different way, place the Ccdrawnode drawing in the update.

Of course, this is only necessary if the drawing node will change as the game state changes, and if the drawn node is never changed, it can be placed directly into the initialization of the class instance.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Resolving the crash of drawing geometry using Ccdrawnode in cocos2d

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.