Rendering issue in iOS cocos2d-x 3.17

Anyone have any ideas why the terrain get degraded when getting further to the right X axis? I feel like it’s a floating point issue when X gets bigger. This happens on iOS and Android works fine. Any help or suggestions would be greatly appreciated!

Are you running in a simulator or on hardware? What simulator or what hardware?

Have you tried looking at instruments and also checking Xcode while your app is running to see how it is performing? I’ve seen something like this before when resources were starting to run scarce.

One my old game had such issue. It’s can be easily fixed.

So, it’s ES texture interpolation precision. Your level by X starts at 0 and ends at say 10000px? So the triangles already corrupted at the end due to precision.
Just don’t use big numbers, always create terrain in screen coordinates, so it’s X values will no be higher that say screen_width x 2.

I see you want to help, but asking non relevant questions just bring nothing than mindless gestures. You know additionally you can also ask what version of iOS device or Xcode version.

And again more, whats performing exactly? Describe exact steps in Profiler what should be checked?

@slackmoehrle it’s running on hardware with plenty of resources.

I suspect it’s a precision issue as X gets big like @cc_x suggested. Wondering why this precision issue doesn’t happen in Android :thinking:

@cc_x Not sure how to always create terrain in screen coordinates. Do you have any sample code? Any help be greatly appreciated!

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!