Rendering issue in iOS cocos2d-x 3.17

Do you know if this happened in 3.16 or prior? I have a game where the entire scene is generated on the fly preemptively but my math is always based upon the current screen coordinates +/- 1/2 the screen width. I always end up with an int that isn’t really big.

Are you using ParallaxNode by chance?

Are you using any convertToNodeSpace or convertToWorldSpace calls?

I only noticed the issue in 3.17 not prior. Nope not using any of the api mentioned above. I believe issue is as @cc_x mentioned above that I am having precision issue that’s corrupting the triangles as X gets big.

Trying to figure out how to generate the triangles with small X coords. Maybe just simple as subtracting X with an offset to keep it small. On vacation right now so now way to test it.

Drawing hills with an OpenGL triangle strip

@drelaptop do you have any thoughts?

Look forward to @drelaptop thoughts :slight_smile:

It was 4 years ago :slight_smile: code is lost, but basic idea is simple.

Your level has objects and they have some coordinates, your scene scrolls from right to left, but objects coordinates are still high by X, so you need to convert their coordinates using convertToWorldSpace and then convertToNodeSpace, and Node will be your screen and what from right side but not far than 2 x width.
Just main idea is that anything that drawn should have coordinates less than 10000px.

@slackmoehrle does cocos2d-x have a wiki explaining convertToWorldSpace and convertToNodeSpace ? The one below seem to be dead.

http://www.cocos2d-x.org/wiki/Coordinate_System#convertToNodeSpace

@cc_x Thank you for the basic idea!

Thanks!

Never mind found When to use convert to nodespace or convert to worldspace

The Wiki can be downloaded here for legacy reasons: cocos2d-x.org/docs/wiki.tar.gz

We can use this post to document a better solution for future questions.

This can be also shader precision, if you using some.
But you need to create any drawable object in coordinates not large than 10000 pixels by XY axis, better even less.

We are noticing the corruption starts when X is around ~1000. GLProgram::SHADER_NAME_POSITION_TEXTURE is the shader being used. Maybe the issue is with the shader?

I’m not familiar with shaders, I fixed my same problem(but it was starting from 10k pixes) by just using small numbers in XY coordinates of objects.

can you show us some code relating to convertToNodeSpace and convertToWorldSpace?

@Lazy_Gamer I don’t have code in front of me. It’s pretty much

HudLayer
------>GameLayer
----------->Terrain Layer
-----------> Game objects

Inside Terrain update function…

auto p0 = getParent()-> convertToNodeSpace(terrainCoords[i]);
auto p1 = getParent()-> convertToNodeSpace(terrainCoords[i + offset]);

// 1. create triangles with p0 and p1
// 2. and render. See function above in this post.

When calling getParent()-> convertToNodeSpace p0 and p1 are the same.

For example

auto p0 = getParent()-> convertToNodeSpace(Vec2(100, 1000));
p0 end up being Vec2(100, 1000)

Not sure if convertToNodeSpace is working or I am doing it wrong.

If its a issue with precision then you would like to have a coordinate system to display objects in world coordinate system. You should try with convertToWorldSpace() and position them in accordance with world space.

It didn’t worked for you because you are trying to convert child coordinate(position in this case) to parent coordinate space while child is already in parent coordinate space(when i say child->setPosition(Vec2(100,1000)) i am saying put this child in parent space at point(100, 1000)).
Try doing terrainObject->getParent()->getParent()->convertToNodeSpace(Vec2(100, 1000)) and you should see the difference(now casting to grand parent Space). Hope this clears your doubt.

@Lazy_Gamer I very much apologize! I meant convertToWorldSpace not working for me. It seem calling convertToWorldSpace doesn’t do anything. It returns the same input value. Maybe I might be using it wrong.

For example

auto p0 = getParent()->convertToWorldSpace(Vec2(100, 1000));
p0 end up being Vec2(100, 1000)

I will try out below in the morning and get back :slight_smile:
terrainObject->getParent()->getParent()->convertToNodeSpace(Vec2(100, 1000))

Thank you for your patience and help!

Instead of using parent context(getParent()) try using current object context e.g, this->convertToWorldSpace(Vec2(100, 1000)).

this->convertToWorldSpace(Vec2(100, 1000)) returns the same value as input

can you further brake down your hierarchy looks like above posted hierarchy is missing something.

I havent read all the comments. I wanted to add that this behavior also occurs on my Samsung Galaxy S8+