kandi X-RAY | cocos2d-x Summary
kandi X-RAY | cocos2d-x Summary
|Win32|Others| | ----|------| [Build status] Status([cocos2d-x] is a multi-platform framework for building 2d games, interactive books, demos and other graphical applications. It is based on cocos2d-iphone, but instead of using Objective-C, it uses C++. It works on iOS, Android, macOS, Windows and Linux.
Top functions reviewed by kandi - BETA
cocos2d-x Key Features
cocos2d-x Examples and Code Snippets
Trending Discussions on cocos2d-x
I'm trying to make user input of WASD move a sprite around in Cocos2D-X. I'm pretty sure I'm doing everything correct but it gives me this error: expression must be a modifiable lvalue.
Here is my code (Note: I'm new to Cocos2D-X, so it might be a bit messy)...
ANSWERAnswered 2021-Sep-05 at 09:28
Try to use
mutable specifier(which allows lambdas body to modify the objects captured by copy, and to call their non-const member functions):
In our game application for Android which is based on the game engine cocos2d-x, with most of the code being written in C++, we have a very strange and critical issue since Android 11:
When the native library gets loaded in
onLoadNativeLibraries it now suddenly takes 60+ seconds. Before Android 11, it all worked fine and it loaded in 0.2-3 seconds. Now when you start the game, you have a 60+ seconds gray screen.
We already figured out that
JNI_OnLoad gets called directly after the 60 second stall is over.
Here's the code of the
ANSWERAnswered 2020-Oct-29 at 18:06
It's a bug in Android 11 fixed by google but not deployed yet.
Meanwhile, if you don't care about calling static and thread_local variables destructors in your lib when program is exiting/library is unloaded, pass the flag
-fno-c++-static-destructors to the compiler. (see long answer for a more granular solution using clang annotations)
I used this flag on my project (not cocos2d) with no issue and lib is loading even faster than before.
Unfortunately this is a performance regression introduced in android 11 (R) by the Google team. The issue is being tracked by google here.
To summarize, when
System.loadLibrary() is called, the system registers a destructor for each of the C++ global variables contained in the loaded library, using __cxa_atexit()
Since Android 11 (R), the implementation of this function in android has changed:
- In Q, __cxa_atexit uses a linked list of chunks, and calls mprotect twice on the single chunk to be modified.
- In R, __cxa_atexit calls mprotect twice on a single contiguous array of handlers. Each array entry is 2 pointers.
This change regressed the performance drastically when they are many C++ global variables which seems to be the case in cocos2d so libraries.
Google has already implemented a fix https://android-review.googlesource.com/c/platform/bionic/+/1464716 but as stated in the issue:
this won't be in Android 11 until the March QPR at the earliest, and since this isn't a security issue it won't be mandatory for OEMs to actually take that patch.
Google Team suggests also some workarounds at the app level by removing or skipping the destructors on global variables:
- For a particular global variable, the [[clang::no_destroy]] attribute skips the destructor call.
- Pass -fno-c++-static-destructors to the compiler to skip the destructors for all static variables. This flag also skips destructors for thread_local variables. If there are thread_local variables with important destructors, those can be annotated with [[clang::always_destroy]] to override the compiler flag.
- Pass -Wexit-time-destructors to the compiler to make it warn on every instance of an exit-time destructor, to highlight where the __cxa_atexit registrations are coming from.
Cocos2d-x v4.0 crashing in all iPhone Simulator. In device no crash...
ANSWERAnswered 2020-Nov-20 at 22:25
With that little info we can't help much. But if I try to interpret the posted image corretly you receive a "EXC_BAD_ACCESS" Exception.
This means more or less that you access a freed memory region or in general you try dereference a pointer pointing to an invalid memory address.
The only argument which could cause such an error is
So you should check the code path of
In release builds you don't see always "access-after-free" because memory is not immediately released to the OS (which triggers such errors) it is just marked as "free" to allow faster allocations.
I cannot confirm whether this has been since a newer iOS version (perhaps 11 onwards) but the hardware volume buttons do not respond whilst using an app I am updating at present.
SimpleAudioEngine and whilst I have looked at some other projects I have that use Cocos2d-x, I have tried to use the
SimpleAudioEngine source from there, with zero success.
The version of cocos2d-x is v2.1.1
HelloWorldScene.cpp I am calling
ANSWERAnswered 2020-May-25 at 18:53
In most of my apps i use the same syntax and it is working using cocos2d-x version 3.17.2.
Which EventDispatcher to use in cocos2d ? Node::EventDispatcher or Director::EventDispatcher ? After referencing the official documentation of both Director class and Node class Director Class Reference Cocos2d-x Node Class Reference Cocos2d-x I am a bit confused about, what is the difference between using...
ANSWERAnswered 2020-Apr-29 at 18:05
Both are same. this->getEventDispatcher() calls CCNode's getEventDispatcher() function. It returns _eventDispatcher.
The application presents a crash 2~5 seconds after it's terminated by the user (i.e. force kill the app). This happens only on iOS builds on multiple unity versions (see details below). Most of the crashes reports are not arriving on Crashlytics. There are very few crashes on the console, even though we're consistently reproducing this error on a daily basis. The Android builds don't present the same error.Steps to reproduce
- Open the game
- Wait until the loading scene is about to finish or until the game scene is fully loaded
- Kill the application
- Wait 2~5 seconds and see the crash report window
- Reproduction rate: 80%
- Devices used to test: iPhone SE, iPhone 7, iPhone 8, iPad Mini 4
- Also observed the crash on: iPhone XS, iPhone XR
- The issue is iOS specific. We have the same build on Android working without issues.
- Crash reports are not being captured by Crashlytics on most cases (see some of the crashes below).
- Crashes happen only on the final steps of the loading, where the external SDKs are being initialized.
- On TestFlight, the crash count is 0 for almost all builds, including the ones the users are reporting the crashes.
- Using a debug button that calls the Application.Quit() method of Unity doesn't cause the application to crash, even though it takes a while to close.
- The crash seems to be invariante to OS version and iOS device.
- Unity version: 2019.2.17f1. Also reproduced with 2019.2.0f1 and 2019.3.10f1.
- External plugins are listed here.
- Crash reports
Here's a list of all solution attempts without success so far:
- Remove GameAnalytics plugin
- Remove IronSource plugin
- Remove UnityIAP plugin
- Workaround on PostProcess iOS
- Set minimum OS version to 9.0
- Comment all OnApplicationPause/Quit implementations (plugins included)
- Enable Bitcode
ANSWERAnswered 2020-Apr-27 at 15:59
Description: The general problem is to have any piece of code that blocks the Main Thread on iOS when the application is finalizing (see this document for more information). In our case it is happening because of ongoing requests when the player kills the application. As we save the player progress on the server when the application is terminated (using
Dispose() method), the request blocked the main thread, causing the crash. The solution is to remove this particular save. We tested a build including this fix and, so far, we have no crashes on 20 attempts of killing the game after the Game Scene is loaded. We haven't thought about this before because this piece of code is there since August of 2019 and it hasn't been touched since then. The problem started to happen only in February of 2020.
More information: Since the piece of problematic code was in the project since August of 2019 and the problem started to happen only on February of 2020, it's possible that the iOS version has something to do with it. We haven't investigate the changelog yet, but the oldest iOS version presenting the crash so far is iOS 13.2, released on October 28th, 2019.
Another possibility is that some change on our backend code caused the request to hang. As we use BestHTTP, by default all requests are aborted when the application is terminated. We haven't investigate if the execution order of
OnDisable/OnApplicationQuit can be the issue. Also, by default, the requests aborted by BestHTTP during Application Quit still call the callbacks. In our case, the callback for that Save Player is
null, so this might not be the problem.
Related crashes: We're still facing some crashes on the loading scene. As far as we've seen, they happen when there's a request going on. The reproduction rate of those issues are way lower than the problem on Game Scene.
Hints: We had difficulty to retrieve the logs on Crashlytics, because most of them weren't being send. Here's a step-by-step of how to retrieve the log from the iOS device itself:
- Open the Settings app on your iPhone/iPad device
- Go to Privacy (appears below Battery on iOS 13)
- Scroll to the bottom and open Analytics & Improvements
- Open Analytics Data
- Find the logs for the desired application
I'm using cocos2d-x 3.17. When I run a Follow action on a sprite, the tiled map can't render fully. The map looks exactly the same as the screen record shows in posts below
But they were using Cocos Creator and can fix it by setting ENABLE_TILEDMAP_CULLING = false.
Is there any equivalent settings in C++ api?...
ANSWERAnswered 2020-Mar-29 at 09:40
Found out the root cause is that the Scene has been moved by Follow action. It seems in cocos2d-x, Scene is not supposed to move.
I am trying to load particle effects (in .plist format) in my Cocos2d-x game code, and I am facing the warning:
"libpng warning: iCCP: known incorrect sRGB profile", as mentioned in the question. I have done some research on my end, and the other StackOverflow users who asked similar questions had this issue while loading .png files.
However, I am facing the same issue while initializing .plist files instead. Any insight on how to remove this warning would be helpful. Kindly note that I am not facing any issue with loading the .plist file as such, but the warnings are polluting my log streams.
ANSWERAnswered 2020-Feb-11 at 21:09
I was able to solve this by using a sub-class of
ParticleSystem instead of
ParticleSystem itself. The sub-class I used is
ParticleSystemQuad. Additionally, I realized that the
initWithFile API was being called multiple times in my code, due to Cocos2D update schedulers. That may have been a cause for this warning.
To fix this warning, I created a fresh variable/system, and assigned a parent to it, while setting the position of the new variable to that of a well-known (desired position) node.
I just installed cocos2d-x and created a new project using this command line : cocos new ProjectName -l cpp. It created with no errors but when i check proj.win32 folder, there was no .sln file. How can I open up this project? Or why there is no sln file?
Here is what proj.win32 folder looks like:
ANSWERAnswered 2020-Jan-11 at 14:25
You did it correctly. There is no .sln file just from creating a new project.
Since you want .sln file, it means you want to use an IDE. As noted in https://github.com/cocos2d/cocos2d-x#using-ide, cmake is required in order to use IDE.
If you don't have cmake installed, download it from https://cmake.org/download/
After you have it installed, go to the proj.win32:
No vulnerabilities reported
Mac OS X 10.7+, Xcode 8+
or Ubuntu 14.04+, CMake 3.1+
or Windows 7+, VS 2015
Python 2.7.5+(NOT Python 3)
NDK r16+ is required to build Android games
Android Studio 3.0.0+ to build Android games(tested with 3.0.0)
JRE or JDK 1.6+ is required for web publishing
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page