Forum > C++ > Sprites are blurred

Sprites are blurred

By swap Posted 2011-06-04 23:00 Comments 11
swap
  • Posts: 28

Hello friends,

I have a problem with rendering CCSprite sprite :)
I noticed that some of my sprites are blurred. It is more visible on device. But I found out, that if the sprite is near the center of the display it is perfect. So blurred are only sprites that are near to edges.

I tried find information about this, but I found only one suggestion for cocos2d-iphone - it’s autoscale parameter of CCDirector::init() method. But there is no such parameter in cocos2d-x.

Any suggestions?

Thank you very much.

Swap

walzer
  • Posts: 1735
  • Location: Xiamen, China

#1 RE: 2011-06-06 23:29

cocos2d-x has its autoscale mechanism, and it’s different between platforms. ( A little ugly, I admit, aha).
A wiki page is here: How does cocos2d-x support multi-resolution
You situation hasn’t been reported before, so a screenshot or a photo would explain this stuff better. And an unit test, simply hack helloworld to reproduce this bug will be highly recommended!

Less is More. Keep Focus.

swap
  • Posts: 28

#2 RE: 2011-06-07 09:36

Hello,
thanks for answer.

I’ve added the test project (simple with 5 sprites) and two screenshots from the simulator.

It is rather different that I wrote before, because now are blurred sprites in the center (the second image). Zoom the screenshot to perfect view of the defect.
The first image is different. There are blurred sprites at the top and the bottom. Centered one is quite good but not perfect.

I was testing only on ios platform without retina display enabled. I used template from cocos2d-x. I am using XCode4.

Swap

blurred-sprites.zip - test project (348.8 kB)

screen.tiff - example 1 (30.7 kB)

screen2.tiff - example 2 (59.3 kB)

walzer
  • Posts: 1735
  • Location: Xiamen, China

#3 RE: 2011-06-08 20:21

I am tracing this bug, but haven’t resolved it.
The bad thing is that, cocos2d-iphone has the same problem. cocos2d-x inherit this bug.

I use cocos2d-iphone 1.0.0-rc3. and translate your code to

#define WIDTH 320
#define HEIGHT 480

CCSprite* sprite1 = [CCSprite spriteWithFile:@"something.png"];
sprite1.position = ccp(WIDTH/2, HEIGHT/2);
[self addChild:sprite1];

CCSprite* sprite2 = [CCSprite spriteWithFile:@"something.png"];
sprite2.position = ccp(WIDTH/2,HEIGHT/4);
[self addChild:sprite2];

CCSprite* sprite3 = [CCSprite spriteWithFile:@"something.png"];
sprite3.position = ccp(WIDTH/2,HEIGHT/4*3);
[self addChild:sprite3];

CCSprite* sprite4 = [CCSprite spriteWithFile:@"something.png"];
sprite4.position = ccp(WIDTH/4,HEIGHT/2);
[self addChild:sprite4];

CCSprite* sprite5 = [CCSprite spriteWithFile:@"something.png"];
sprite5.position = ccp(WIDTH/4*3, HEIGHT/4);
[self addChild:sprite5];

No matter running on iphone3 simulator or ipad simulator, it looks the same as your tiff pictures.
I run it on iphone4, and get the screenshot

Less is More. Keep Focus.

swap
  • Posts: 28

#4 RE: 2011-06-09 22:51

Hello,

do you have any solution to workaround the problem? I do not understand that anybody does not find the same problems before. The behaviour seems to be random :-(

Thanks.

Swap

walzer
  • Posts: 1735
  • Location: Xiamen, China

#5 RE: 2011-06-16 19:03

Hi, Jiri, I just learn this from Riq.

  1. edit ccConfig.h
  2. #define CC_COCOSNODE_RENDER_SUBPIXEL 0

This will work for you. Have a try!

Less is More. Keep Focus.

swap
  • Posts: 28

#6 RE: 2011-06-17 09:00

Hello,
thanks fo reply. But I think that there is no effect setting CC_COCOSNODE_RENDER_SUBPIXEL to 0 :(

Swap

walzer
  • Posts: 1735
  • Location: Xiamen, China

#7 RE: 2011-06-17 19:32

oops, :( too

Less is More. Keep Focus.

walzer
  • Posts: 1735
  • Location: Xiamen, China

#8 RE: 2011-06-28 19:05

One of my friend met the same problem, and he told me CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D) will fix this, while the default setting is kCCDirectorProjection3D.

Less is More. Keep Focus.

swap
  • Posts: 28

#9 RE: 2011-06-29 10:14

Hello,
thank you very much. It works perfectly now[]()!:)

ex
  • Posts: 26

#10 RE: 2012-02-27 15:57

Hi, sorry to resuscitate this thread, but I think that

CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D

only works if the sprite in pixels are even? odd sizes give me blurred images.
I’m doing something wrong? I am using a RenderTexture and sprites from a big texture map.
Thanks!

feiting_schatt
  • Posts: 11

#11 RE: 2012-05-15 22:17

This is happening on HD for me. The fixes above may help, and try this: add 0.5 or some similar between-1-and-0 value. This is a known issue with the iPhone trying to render halfway between pixels, not just OpenGL. The iOS manuals may provide some help, but I don’t think they’ll provide much for you. In the meantime, try to figure out where/why it’s doing the half-pixel thingy and adjust the scale/width/size

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps