What's wrong with Core Graphics and UI?
I was having troubles when rendering more that 10 or so "sprites" using CG. So to elminate the possibility that was my game logic, I wrote this test render loop that makes six rows of PNG "creatures" on the screen. It is called from a timer at 30fps. When running on the simulator this is fine. If I run this code on the iPhone, it brings it to it's knees. So much that no the UI stops responding. I cant imagine that Core Graphics cant handle rendering 60 sprites from a CGLayer. I feel like I am missing something obvious.
Code:
testCreature = PNG loaded into CGImageRef
-(void)render
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, kBackGroundHeight);
CGContextScaleCTM(context, 1.0, -1.0);
CGRect creatureRect = CGRectMake (0, 0, kCreatureSize, kCreatureSize);
CGLayerRef creatureLayer = CGLayerCreateWithContext (context, creatureRect.size, NULL);
CGContextRef creatureContext = CGLayerGetContext (creatureLayer);
CGContextDrawImage(creatureContext, creatureRect, testCreature);
// draw creatures
static int move = 0; // just so we see something moving...
CGContextSaveGState(context);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize + move, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextTranslateCTM (context, kCreatureSize, 0);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextTranslateCTM (context, kCreatureSize, 0);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextTranslateCTM (context, kCreatureSize, 0);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextTranslateCTM (context, kCreatureSize, 0);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextTranslateCTM (context, kCreatureSize, 0);
for(int ndx = 0;ndx < 10;++ndx)
{
CGPoint point = CGPointMake( kCreatureSize, kBackGroundHeight - (ndx * kCreatureSize) );
CGContextDrawLayerAtPoint (context, point, creatureLayer);
}
CGContextRestoreGState(context);
CGLayerRelease(creatureLayer);
move++;
if(move > kCreatureSize)
move = 0;
}
If you want to do any sort of drawing that requires constant updates, you are going to need to use OpenGL.
Core Graphics just can't do it. It's main usage on the iPhone is for implementing static imagery for UIView subclasses.
Core Graphics just can't do it. It's main usage on the iPhone is for implementing static imagery for UIView subclasses.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Core Animation Architecture in Games | Mattonaise | 3 | 4,545 |
Apr 6, 2011 03:56 PM Last Post: Mattonaise |
|
| OpenAL, i am doing it wrong or is it broken on iPad simulator? | AdrianM | 3 | 3,362 |
Apr 23, 2010 11:18 AM Last Post: Rasterman |
|
| Wrong x,y coordinates with Texture2D class | Minishlink | 2 | 2,789 |
Feb 12, 2009 11:37 AM Last Post: Minishlink |
|
| 2D Game/App, Core Graphic | matax | 1 | 3,146 |
Aug 26, 2008 06:36 AM Last Post: ThemsAllTook |
|

