Created
March 30, 2011 04:30
-
-
Save pixelrevision/893868 to your computer and use it in GitHub Desktop.
Quick and dirty frames per second meter for sparrow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SXFPSMeter *meter = [[SXFPSMeter alloc] initWithText:@""]; | |
[self addChild:meter]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "Sparrow.h" | |
@interface SXFPSMeter : SPTextField{ | |
} | |
- (void)update:(SPEnterFrameEvent*)event; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SXFPSMeter.h" | |
@implementation SXFPSMeter | |
- (id)initWithText:(NSString *)text{ | |
self = [super initWithText:text]; | |
self.hAlign = SPHAlignLeft; | |
self.vAlign = SPVAlignTop; | |
self.fontSize = 16; | |
self.color = 0xFF0000; | |
[self addEventListener:@selector(update:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; | |
self.touchable = NO; | |
return self; | |
} | |
- (void)update:(SPEnterFrameEvent*)event{ | |
static int frameCount = 0; | |
static double totalTime = 0; | |
totalTime += event.passedTime; | |
if (++frameCount % 60 == 0){ | |
self.text = [NSString stringWithFormat:@"FPS: %f", frameCount/totalTime]; | |
frameCount = totalTime = 0; | |
} | |
} | |
- (void)dealloc{ | |
[self removeEventListener:@selector(update:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
missing a
self.touchable=NO;