RenderTexture error #1097
-
I get this error after adding below code: `auto sprite1 = Sprite::create("spaceShip.png");
How to use this class correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Please have a look on |
Beta Was this translation helpful? Give feedback.
-
If you check the location of that crash via a debugger, you would see that the crash is from this assert: It is pointing out exactly what the problem is. Also, given that you haven't provided any context to your code snippet, we cannot tell where and when you're calling that code. My guess is that you're using it in the The way to fix it is to ensure that you do not call that code until after the scene has finished initializing, and there are many ways to handle this. For example, you can still use it in
You can also do it in an override of
The other issue is that you're creating a render texture that is half the size of the sprite, yet you're trying to render the full sprite to the render texture, and you haven't set the position of that sprite correctly either within the render texture boundary. As @aismann mentioned, the cpp-tests project is the best place to learn how to use this and any other functionality within this game engine. |
Beta Was this translation helpful? Give feedback.
If you check the location of that crash via a debugger, you would see that the crash is from this assert:
It is pointing out exactly what the problem is.
Also, given that you haven't provided any context to your code snippet, we cannot tell where and when you're calling that code. My guess is that you're using it in the
init()
method, which is not the right place for it. The scene would not have finished initializing at that point.The way to fix it is to ensure that you do not call that code until after the scene has finished initializing, and there are many ways to handle this.
For example, you can still use it in
init()
, but you need to schedule it for the next cycle usingscheduleOnce
,…