Cocos2dx3. x Image Blur solution, cocos2dx3. x blur
Recently, cocos2dx was developed. Because of the Games running on the window platform, many problems have occurred, and image blurring is one of them.
The following shows my solution (because the image file loaded with cocostudio can only be changed to the source code) (I suggest you do not change the source code)
After the cocostudio file is loaded, the image is put into the cache.
Therefore, we can find the TextureCache class (CCTextureCache) to add a public function to it.
// Add by xxj 11:33:18 // set anti-sawtooth void setAliasTexParameters ();
The implementation code is as follows:
Void TextureCache: setAliasTexParameters () {for (auto it = _ textures. begin (); it! = _ Textures. end (); ++ it) (it-> second)-> setAliasTexParameters (); // sets the anti-aliasing of each image}
OK, complete!
Then we call this function once after loading the ui file to solve the problem:
The call function is as follows:
CCTextureCache: getInstance ()-> setAliasTexParameters (); // sets anti-aliasing
Of course, remember to call this function when we dynamically load a cache!
Learning and communication !!! For reference
Cocos2d-x how to solve the problem of fuzzy image display
For some specific reasons, the program does not use plist to package resources, but now uses small images that are scattered. Some images may be blurred during running. The reason is as follows:
The setAntiAliasTexParameters interface is called by default during texture initialization. This interface sets GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER to GL_LINEAR. When GL_LINEAR is used for rendering, if the pixel points of the arts and sciences field and the coordinates of the display area cannot match one by one (for example, zoom in or out, or the display position is a floating point number ), the four nearby pixels (2*2, 2D display) are used for color mixing, which will make the image look blurred.
Solution: Based on the above analysis, you can use the following methods:
1. Call the setAliasTexParameters interface of Texture. The side effects may cause serious sawtooth when being zoomed in or out. If the display position is a floating point number, the last row (one column) pixel will be truncated.
2. do not use an image with an odd resolution because an image with an odd number is used. If you set AnchorPoint to (0.5f, 0.5f), even if you set setPosition () to an integer, it also causes the image to be displayed in decimal places.
3. if you must use an image with an odd resolution, set the anchor to (0.0f, 0.0f) to ensure that you only need setPosition () the input value is an integer (note that the parent control cannot be a floating point number.
Solution to Blurred Image Compression
The storage method in Photoshop can be changed.