- (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