Cocos2d-x Background image is not displaying properly

主宰稳场 提交于 2019-12-11 18:08:26

问题


i am new to Cocos2dx 3.0 alpha and converting my game from Corona SDK to Cocos2d-x 3.0 alpha. I am displaying a background image like this.

auto sprite = Sprite::create("bg.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite, 0);

But the image is distorted in iOS simulator. I also get these 3 warnings in console. May be 1 warning for each image, as i am displaying 3 images.

libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile

Here are the screen shots.

This is the actual image.

Any help is appreciated.


回答1:


I think it is because your bg.png dimension's ratio does not match with your designResolutionSize ratio. Your bg.png has a dimension of 512x256 while iphone screen has 480x320. So I assume that you set your design resolution size to that of iphone (480x320) hence your background image is not displaying properly. Try changing the design resolution size to the size of your bg.png or resize your bg.png to match your design resolution size. For more info about design resolution size and/or multi resolution support visit this wiki page: click me

Hope this helps.




回答2:


Scale the sprite before adding to layer

sprite->setScale(visibleSize.width / sprite->getContentSize().width, visibleSize.height / sprite->getContentSize().height);


来源:https://stackoverflow.com/questions/20139335/cocos2d-x-background-image-is-not-displaying-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!