CCRenderTexture image position disorder problem in the iphone retina mode


These days, I encountered a very annoying problem on CCRenderTexture. I write my game width cocos2d-x, using CCRenderTexture mainly, in the windows and the iphone simulator can run normal, but in the iphone, which all have a great deal of partial images shift.

This question puzzled me for several days, almost collapsed, but finally I solved it.

At first, I thought it was the bug of cocos2d-x library, so I wrote some test cases to compare cocos2d-iphone and cocos2d-x effect, the effect is found both exactly the same, and there are not problems in the simulator.

Then I see the source code of CCRenderTexture in the two librarys, both is exactly the same.

In testing, I found no change CCRenderTexture of anchorPoint role, it will always be the center point, that ccp (0.5f, 0.5f) as anchorPoint, so I suspect there is CCNode transform a problem. So I’m going to measure this offset, and then do an adaptation, but after testing, I found that the offset is no law that I almost collapsed.

Finally, I asked the library’s author for help, the author let me look at two different test code library, but the two I have seen the library’s code is the same, but I still go back and retesting, but this time I found One of the tests inside a 400 * 240 size images on a 480 * 320 size CCRenderTexture inside, and only takes up very little space, but the image size should be filled with fishes in this region, I suddenly remembered, is because the retina pattern of the reason, so I will place all the relevant places in the pictures the figures are divided by 2, because the animation to load the plist files I resolved, therefore, generated inside the rect CCSpriteFrame should also be halved, Otherwise, there will Huaping phenomenon, after doing so, finally found success running the game up.

Finally, the conclusion that, due to the simulator and the windows above the retina can not be used to develop models, many of which are in accordance with written code to write the image size, but in the iphone retina mode, all the size, location, surrounded by boxes These variables cocos2d-x are multiplied by 2 to help themselves, we do not need to do this deal, or else it will be my very tragic mistake, it would be difficult to know which caused this problem.

Here to thank the author RongHong Huang helping solve the problem, hope cocos2d-x getting larger and larger, becoming more and more good, huh, huh.


hooo, so nice, thank you for your share



I am using CCRenderTexture for collision detection in my project for ios and android. In android it run fine but in iphone i am getting some problem related to CCRenderTexture.
the Texture is shown rotated and in half part of screen,i am not getting perfect collision of sprite in iphone,
please help.