How to chang the orientation in sparrow framework!

- (id)initWithWidth:(float)width height:(float)height
{
    if ((self = [super initWithWidth:width height:height]))
    {
        // Support orientation changes
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDetected:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
 
        // MAKE LANDSCAPE RIGHT
        mContents = [[SPSprite alloc] init];
        [self addChild:mContents];
 
        printf("here");
 
        // BACKGROUND
        SPImage *background = [SPImage imageWithContentsOfFile:@"MainMenu.png"];
        [mContents addChild:background];
 
        // Touch Listener
        [self addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
 
    }
    return self;
}
 
- (void)onTouch:(SPTouchEvent*)event
{
    NSArray *touches = [[event touchesWithTarget:self andPhase:SPTouchPhaseEnded] allObjects];
 
    if (touches.count == 1)
    {
        // get touch
        SPTouch *touch = [touches objectAtIndex:0];
        // position
        SPPoint *currentPos = [touch locationInSpace:self.parent];
        printf("%f,%f\n", currentPos.x, currentPos.y);
    }
}
 
-(void)orientationDetected:(UIEvent *)event{
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft)
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:FALSE];
        mContents.rotation = SP_D2R(90);
        mContents.x = 320;
        mContents.y = 0;
        printf("right");
    }
    else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight)
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:FALSE];
        mContents.rotation = SP_D2R(270);
        mContents.x = 0;
        mContents.y = 480;
        printf("left");
    }
}
 
@end
posted @ 2013-01-21 20:43  卡卡之海  阅读(176)  评论(0编辑  收藏  举报