Cocos2D 0.99.5 CCDirector pixel format? - cocos2d-iphone

I'm trying to set the pixel format in my CCDirector but i can't find the method.
It seems to me that my version of cocos2d doesn't have that method??
Strange

In your app delegate, look for this line:
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
or search for
EAGLView *glView
and you will find it..

Related

CCRepeatForever doesn't exists in cocos2d-iphone 3.0?

Im trying to create sprite animation in cocos2d 3.0.
In all tutorials that i read there is a class named CCRepeatForever. But in cocos 3.0 it doesn't exists anymore. How can i replace it?
This is my code:
self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim]];
PS Sorry for my english.
The class is now named CCActionRepeatForever.
Replace it with:
[CCActionRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];

how to create menu using a sprite sheet in cocos2d-x

I just started learning cocos2d-x.
I am trying to create menu using sprite sheet, below:
CCSpriteFrameCache::sharedSpriteFrameCache()>addSpriteFramesWithFile("my_menu.plist");
CCMenuItem *play = CCMenuItemImage::create("play.png", NULL,NULL,this , menu_selector(StartScene::clickStart));
CCMenu *pMenu = CCMenu::create(play,NULL);
addChild(pMenu);
I got error message:
get data from file (play.png) failed.
I realise something wrong with my create function. I am just wondering how to get the image from sharedSpriteFrameCache?
OK, I just figure it out:
CCMenuItemSprite *play = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("play.png"), NULL,NULL,this ,menu_selector(StartScene::clickStart));
spriteWithSpriteFrameName is deprecated, instead, we can use:
CCSprite::createWithSpriteFrameName();
u need to take the plist file in a ccspritebatchnode object and manipulate it using this object.
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"AnimBear.png"];
[self addChild:spriteSheet];

Issue with shadows/Opacity on sprites in cocos2d (.png format)

I'm having trouble understanding why sprites with shadows (%opacity layer) looks different in ps and on screen. Here is the comparison:
This is simply because of image formate you set. I guess you set RGBA4444 in code or while exporting spriteSheet. Also remove checkmark Premultiply alpha in texture packer.
Also check in AppDelegate Class:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 //Guru - replaced kEAGLColorFormatRGB565 with kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

Cocos2d - retina images not displaying

Simply trying to test retina display. I setup the director like this:
CCDirectorIOS* director = (CCDirectorIOS*)[CCDirector sharedDirector];
director.wantsFullScreenLayout = NO;
director.projection = kCCDirectorProjection2D;
director.animationInterval = 1.0 / 60.0;
director.displayStats = YES;
[director enableRetinaDisplay:YES];
I create two versions of the file in Photoshop - outline-hd.png and outline.png. I color the HD version red so I can tell if it's being displayed.
Display code:
CCSprite *border = [CCSprite spriteWithFile:#"outline.png"];
[self addChild:border];
Yet it is the non-hd image that gets displayed on my iPhone5. Why?
I came across this question while trying to solve the exact same problem in my own project. Had to dig around in the cocos2d source to figure it out. The problem is that the director's enableRetinaDisplay:YES method doesn't work unless the director's view is set. So, it needs to be called after the glView is set up, and you've called setView on the director:
CCGLView *glView = [CCGLView viewWithFrame:aFrame
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[[CCDirector sharedDirector] setView:glView];
NSLog(#"glView is set, enable retina...");
[[CCDirector sharedDirector] enableRetinaDisplay:YES];
This should fix the problem for you!
May be you forgot:
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];
[sharedFileUtils setiPhoneRetinaDisplaySuffix:#"-hd"];

Cocos2d 2.0 issue loading HD images in Retina Display

I have been working for an iPad game using Cocos2d 2.0, I am facing a problem while loading HD images for the new iPad (Retina Display). But I can't figure out why HD images are not being loaded automatically while executing the code:
Even after adding [director enableRetinaDisplay:YES]; it is still not working. Here is the code sample of when loading image :
MainBG = [CCSprite spriteWithFile:#"menuBackground-ipad.png"];
CGSize ScreenSize = [[CCDirector sharedDirector]winSize];
MainBG.position = ccp(ScreenSize.height/2,ScreenSize.width/2);
[self addChild:MainBG z:0];
I have another image menuBackground-ipadhd.png in the project resources (I can see it from Xcode as well).
Anyone can help ?
For me it is working in cocos2D 2.0
Change that menuBackground-ipad.png to menuBackground.png
Make sure all these lines r found in ur appDelegate and pushScene at the end. Also use onEnter instead of init in layer class.
if( ! [director_ enableRetinaDisplay:YES] )
{
CCLOG(#"Retina Display Not supported");
}
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:#"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:#"-ipad"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:#"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"
[director_ pushScene: [IntroLayer scene]];
//In Layer..
-(void)onEnter
{
[super onEnter];
MainBG = [CCSprite spriteWithFile:#"menuBackground.png"];
CGSize ScreenSize = [[CCDirector sharedDirector]winSize];
MainBG.position = ccp(ScreenSize.height/2,ScreenSize.width/2);
[self addChild:MainBG z:0];
}
Do not specify the ipad/hd/etc file suffix when loading files. Your problem is caused by using the -ipad suffix here:
MainBG = [CCSprite spriteWithFile:#"menuBackground-ipad.png"];
Remove the suffix to allow cocos2d's do it's job in selecting the correct image:
MainBG = [CCSprite spriteWithFile:#"menuBackground.png"];