开发者

iPhone [NSString drawAtPoint: withFont:] Always Draws a Zero

I am learning iPhone game programming from a book by Paul Zirkle and Joe Hogue except I have changed things up a bit. Chances are you don't know that book, so I'll explain to you the structure of my app. I have one xib, MainMenu.xib, which has only a window. No other xib's. Then I have a view controller and at the moment one subclass of UIView. (And of course my app delegate) Right now the app should be turning the screen blue and drawing the FPS (29) in black. Here is what's going on:

http://img27.imageshack.us/img27/6918/screenshot20110621at100.png (I couldn't embed it, the forum wouldn't let me)

Uh oh! The FPS in my console says 29! And there is a little zero in the bottom left corner of the screen. Here is my code for the currently-being-drawn UIView:

#import "MainMenuState.h"

@implementation MainMenuState

- (void)drawRect:(CGRect)rect
{
    g = UIGraphicsGetCurrentContext();
    [self render];
}

- (void)updat { // yes, updat

}

- (void)render {
    //NSLog(@"render called (MainMenuState)");
    UIGraphicsPushContext(g);
    if (g == nil)
        NSLog(@"g == nil"); // Doesn't print b/c it shouldnt
    if (UIGraphicsGetCurrentContext() == nil)
        NSLog(@"UIGraphicsGetCurrentContext == nil"); // also doesnt for same reason
    // fill ba开发者_JS百科ckground with blue
    CGContextSetFillColorWithColor(g, [UIColor blueColor].CGColor);
    CGContextFillRect(g, [self bounds]);

    // Let's draw the FPS now
    int fps = [[[UIApplication sharedApplication] delegate] getFPS];
    NSLog(@"Received FPS of %d (MainMenuState)", fps);                          // prints 29
    NSString *fpsString = [NSString stringWithFormat:@"%d", fps];
    NSLog(fpsString);                                                           // prints 29
    CGContextSetFillColorWithColor(g, [UIColor blackColor].CGColor);
    [fpsString drawAtPoint:CGPointMake(30.0, 60.0) withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
    UIGraphicsPopContext();
}


- (void)dealloc
{
    [super dealloc];
}

@end

I put a couple notes on the far right, I think you have to scroll over in the code view to see them. Anyway It should be displaying 29 instead of zero. What's going wrong?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜