I used the Zwoptex Flash version to generate:
A .png texture file with -hd suffix (double sized images)
A .png texture file without -hd suffix (normal sized images)
A .plist file with -hd suffix.
A .plist file with -hd suffix.
I have checked the files and everything seems to be there alright.
In my game, first I added the .plist file to the cache:
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:#"ParticleAnimations.plist"];
And then I created my CCSpriteBatchNode:
spriteBatch = [CCSpriteBatchNode batchNodeWithFile:#"ParticleAnimations.png"];
[self addChild:spriteBatch z:0];
And finally create my CCSprite, with the filename of an image found in my textures:
CCSprite *particle = [CCSprite spriteWithSpriteFrameName:#"Particle1.png"];
[spriteBatch addChild:particle z:0];
Now, I run this on the simulator (iPhone), and it runs just fine.
Then, I change the Hardware option and set it to "iPhone (retina)", which transforms the simulator on a 960x640 screen. But then, my gane crashes. Within the log, here are these entries:
cocos2d: CCSpriteFrameCache: Trying to use file 'ParticleAnimations.png' as texture
cocos2d: CCSpriteFrameCache: Frame 'Particle1.png' not found
Which I don't quite understand. First of all, why is it using ParticleAnimations.png instead of ParticleAnimations-hd.png, since it is in Retina Display mode? And, of course, why is it looking for Particle1.png instead of Particle1-hd.png?
To begin have you think to uncomment these lines into you appdelegate:
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
It'll enable Cocos2d to use the -hd files.
Then your sprite names must be exacty the same into your spritesheets. Just the plist and texture files must have the "-hd" suffix. For example if you have sprites named toto.png, titi.png, tata.png into your spritesheets named mysp it should look like that:
// Normal
- mysp.png
- mysp.plist
|- toto.png
|- titi.png
|- tata.png
// Retina
- mysp-hd.png
- mysp-hd.plist
|- toto.png
|- titi.png
|- tata.png
For more information, you should refer to the official documentation here: RetinaDisplay in cocos2d
I hope it'll help you!
Related
In cocos2d 2.x we change the image of a CCSprite using CCTexture. But in cocos2d 3.x CCTextureCache seems to be deprecated as Xcode warns me : "undeclared identifier 'CCTextureCache'". Or may be am I miss something as I'm new to cocos.
So how can we change the image of a CCSprite in v3 ??
Thank you.
I think I know how to do.
We have to use a spriteSheet built with TexturePacker [note : may be it's wrong to speak about external resources like it on SO] for example (let's say we have 2 images : monster_01.png and monster_02.png).
We add the .plist and the .png into xCode
We put the spritesheet in cache
and then we can create a CCSprite with a frame using a item of the spritesheet.
This image can be changed.
Some code :
3) We put in cache
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"monsterSpriteSheet.plist"];
4) We create the sprite
CCSprite * mySprite = [CCSprite initWithSpriteFrame: [CCSpriteFrame frameWithImageNamed: #"monster_01.png"]];
5) To change image :
[mySprite setSpriteFrame:[CCSpriteFrame frameWithImageNamed: #"monster_02.png"]];
This works perfectly with cocos2d v3.
I spent 6 hours to have this process. Sometimes I feel stupid.
You can do it by using this
CCSpriteFrameCache and after that you can change you sprite by using function setSpriteFrame of ccsprite.
I'm using TexturePacker to generate sprite sheets. I have images sized perfectly for retina iPhone, I'm using AutoSD feature in TexturePacker to pack them to sprite.png and sprite-hd.png. Both png files look sharp. When I test my game in retina emulator it looks crisp, everything's fine. However when I run 480x320 iPhone in emulator and my regular sprite.png loads - sprites look blurry.
When I manually resized all my individual sprite files and created a sprite sheet from them using TexturePacker it looked fine too.
I was hoping TexturePacker would save me some time doing things manually, and I can't understand why my sprites look blurry. Please help.
Recently I migrate my project to Kobold2D 1.1 with Cocos2D 1.1beta2 inside for iPad Retina Display. But when I run my project and try to put a TMX tile map, the program hung up. The problem is CCTexture2D is call in InitWithImage and there's no Case for texture format AI88. Because of that, program goes to default and hang up.
I add to the code:
case kCCTexture2DPixelFormat_AI88:
data = malloc(POTHigh * POTWide);
info = kCGImageAlphaOnly;
context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
break;
Is the same config as kCCTexture2DPixelFormat_A8 and now code works. I used a TMX made with Tile Editor 0.8 and uses a simple PNG not in any texture packer. The name inside TMX is fondomaze.png but in the project I must rename to fondomaze-ipad.png.
Hope you find useful. Now I can breathe relax with my project still working!
Discover a workaround for Retina Display iPad... Must to increase malloc by 4.
data = malloc(POTHigh * POTWide * 4);
Hope helps people who want to work with RD iPad.
I'm new to cocos2d. I've been following a tutorial which I've got working but when I updated the image I used to shoot fireballs by deleting and replacing it from the resources folder, the image no longer renders. What do I have to do when replacing an image?
Before I swapped the images:
CCSprite *projectile = [CCSprite spriteWithFile:#"Projectile.png"
rect:CGRectMake(0, 0, 20, 20)];
After swapping images:
CCSprite *projectile = [CCSprite spriteWithFile:#"Fireball.png" rect:CGRectMake(0, 0, 20, 20)];
Do I need to delete the cache somehow and re-add the image?
EDIT:
I added this line below my code and it worked:
[projectile setTexture:[[CCTextureCache sharedTextureCache]
addImage:#"Fireball.png"]];
Strange how I have to add a new line of code to replace an image.
I find that sometimes i need to clean and build for the updated texture to finally make it to the app's bundle ... (I suspect this happens when i change a resource while the app is running, but frankly i have lost too much time with this to investigate). Now i de-facto clean and build when changing resources.
I am not certain this is a 'cocos2d' discussion, but rather an Xcode one. The cocos2d texture cache is entirely constructed in memory, during the execution of your app. It is a mechanism that 1) helps keep the memory footprint smaller, and 2) also boosts performance since a texture file is only loaded once if you dont clear the cache. Xcode on the other hand keeps copies of all your files in multiple places. By 'cleaning' a build, you ensure that previous versions of files are removed, and all the current resources (including textures) are placed in the appropriate places for the development environment to function properly.
I'm confused about how to properly use emitters made in Particle Designer with Retina displays in cocos2d. I have tried using an emitter with a non-hd texture (fire.png for example) saved as "particle.plist" with and without the texture embedded and I get a warning of some kind either way. I then made another emitter with fire-hd.png and the name "particle-hd.plist", and I get the same types of warnings, stuff like, cocos2d: Filename(fire-hd.png) contains -hd suffix. Removing it. See cocos2d issue #1040
Searching for issue #1040 yields a little info, but not enough for me to fix this.
A little enlightenment?
You need to prepare these files.
particle.plist (it uses texture 'fire.png' with or without the texture embedded)
fire-hd.png
CCParticleSystem searches -hd texture file first, then non-hd texture file, and then embedded texture data.
hd / retina partcle systems
EDIT
"Warning HD file not found" for Particle plist is false warning. You can use CCParticleSystem initWithDictionary method without any warning in this case.
NSString *path = [[NSBundle mainBundle]
pathForResource:#"particle1_traile" ofType:#"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
CCParticleSystem *particle = [[[CCParticleSystemQuad alloc]
initWithDictionary:dict] autorelease];