|
Loading...
|
cocos2d-iphone-discuss@googlegroups.com
[Prev] Thread [Next] | [Prev] Date [Next]
[cocos2d-iphone] Hello & Rendering texture using UIGraphicsBeginImageContext() - works on simulator, fail on device Fraggle Thu Apr 30 18:00:31 2009
Hello,
First, thanks a lot for the great framework. I am currently switching
all my custom UIKit/CoreAnimation/OpenGL code to cocos2d and I'm
_very_ happy. I'll be sure to donate once I'm done with my game.
Obviously, I've got a question for experienced cocos2d programmers.
I really did try to figure it out myself but, at this point, I have
absolutly no idea what's happening...
Here is the pseudo-code (I try to sum up all the relevant part.. i
think):
My director's options are:
[[Director sharedDirector] setPixelFormat:kRGBA8];
[[Director sharedDirector] setDepthBufferFormat:kDepthBuffer16];
I am subclassing Sprite to create a CharacterCardSprite. My goal is to
render the CharacterCardSprite texture on init using Quartz.
Here is my code:
@implementation CharacterCardSprite
- (CharacterCardSprite *) initWithCharacter: (Character *)aCharacter
{
self = [super initWithCGImage: [CharacterCardSprite
textureForCharacter: aCharacter]];
if ( self )
{
self.character = aCharacter;
}
return self;
}
+ (CGImageRef) textureForCharacter: (Character *) aCharacter
{
UIImage *bg = [UIImage imageNamed:@"bg.png"];
UIImage *lvlImage = [UIImage imageNamed: @"lvl1.png"];
UIGraphicsBeginImageContext(bg.size);
// BG
CGContextSaveGState( UIGraphicsGetCurrentContext() );
CGContextTranslateCTM( UIGraphicsGetCurrentContext(), 0,
bg.size.height);
CGContextScaleCTM( UIGraphicsGetCurrentContext() , 1.0, -1.0);
CGContextDrawImage ( UIGraphicsGetCurrentContext(),
CGRectMake(0, 0, bg.size.width,
bg.size.height),
bg.CGImage
);
CGContextRestoreGState( UIGraphicsGetCurrentContext() );
// Level
CGContextSaveGState( UIGraphicsGetCurrentContext() );
CGContextTranslateCTM( UIGraphicsGetCurrentContext(), 25, 114 +
lvlImage.size.height);
CGContextScaleCTM( UIGraphicsGetCurrentContext() , 1.0, -1.0);
CGContextDrawImage ( UIGraphicsGetCurrentContext(),
CGRectMake(0, 0,
lvlImage.size.width, lvlImage.size.height),
lvlImage.CGImage
);
CGContextRestoreGState( UIGraphicsGetCurrentContext() );
UIImage *cardTexture = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cardTexture.CGImage;
}
...
@end
It works perfectly fine in the simulator, but It doesn't show up at
all on the device, no runtime error either. Hard to debug :)
I guess it's somewhat related to some kind of format issue... but as I
said previously, I'm really clueless now...
If someone could point me to the right direction, I'ld really
appreciate it...
Thanks for your time,
Sebastien
--~--~---------~--~----~------------~-------~--~----~
Did you read the cocos2d documentation? http://tinyurl.com/b8cqm3
Please, read it before asking for help. Probably your answer is there.
-~----------~----~----~----~------~----~------~--~---