added new method to JSoundSystem to pause music. Previously, "pause" meant kill the music and "resume" effectively restarted the music. iOS will now pause and resume appropriately
modified pc and android impls to ensure new calls are made. These still have the same effective outcome (kill and start) until the equivalent is coded on these platforms to pause and resume the music. fixed bug with iOS sound effects not playing. Forgot to assign the key to the associated music sample
This commit is contained in:
@@ -177,7 +177,7 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopMusic(JMusic *music);
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume playing.
|
||||
///
|
||||
@@ -185,6 +185,14 @@ public:
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ResumeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Pause playing.
|
||||
///
|
||||
/// @param music - Music to be paused.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PauseMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load sound effect.
|
||||
|
||||
@@ -231,6 +231,15 @@ void JSoundSystem::StopMusic(JMusic *music)
|
||||
}
|
||||
}
|
||||
|
||||
void JSoundSystem::PauseMusic(JMusic *music)
|
||||
{
|
||||
StopMusic(music);
|
||||
}
|
||||
|
||||
void JSoundSystem::ResumeMusic(JMusic *music)
|
||||
{
|
||||
PlayMusic(music);
|
||||
}
|
||||
|
||||
void JSoundSystem::SetVolume(int volume)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
@property (nonatomic, retain) AdWhirlView *adView;
|
||||
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
|
||||
@property (nonatomic) NSInteger animationFrameInterval;
|
||||
@property(nonatomic, readwrite) CGPoint currentLocation;
|
||||
@property (nonatomic, readwrite) CGPoint currentLocation;
|
||||
|
||||
- (void)startAnimation;
|
||||
- (void)stopAnimation;
|
||||
@@ -40,4 +40,6 @@
|
||||
- (void)removeAds;
|
||||
- (void)displayAds;
|
||||
|
||||
- (void)destroyGame;
|
||||
|
||||
@end
|
||||
|
||||
@@ -362,6 +362,37 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Game life cycle methods
|
||||
|
||||
- (void)destroyGame
|
||||
{
|
||||
g_engine->SetApp(NULL);
|
||||
if (g_app)
|
||||
{
|
||||
g_app->Destroy();
|
||||
delete g_app;
|
||||
g_app = NULL;
|
||||
}
|
||||
|
||||
JGE::Destroy();
|
||||
|
||||
g_engine = NULL;
|
||||
}
|
||||
|
||||
|
||||
- (void)pauseGame
|
||||
{
|
||||
[self stopAnimation];
|
||||
g_engine->Pause();
|
||||
}
|
||||
|
||||
- (void)resumeGame
|
||||
{
|
||||
[self startAnimation];
|
||||
g_engine->Resume();
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark Gesture Recognizer callbacks
|
||||
@@ -429,6 +460,11 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
|
||||
- (void)handleSingleTap: (UITapGestureRecognizer *) recognizer {
|
||||
[[[recognizer view] layer] removeAllAnimations];
|
||||
if (g_engine->IsPaused())
|
||||
{
|
||||
[self resumeGame];
|
||||
return;
|
||||
}
|
||||
currentLocation = [recognizer locationInView: self];
|
||||
ES2Renderer* es2renderer = (ES2Renderer*)renderer;
|
||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||
@@ -559,14 +595,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
|
||||
//These are the methods for the AdWhirl Delegate, you have to implement them
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
- (void) resumeGame {
|
||||
g_engine->Resume();
|
||||
}
|
||||
|
||||
- (void) pauseGame
|
||||
{
|
||||
g_engine->Pause();
|
||||
}
|
||||
|
||||
- (void)adWhirlWillPresentFullScreenModal {
|
||||
//It's recommended to invoke whatever you're using as a "Pause Menu" so your
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
BOOL bannerIsVisible;
|
||||
}
|
||||
void pauseGame();
|
||||
void resumeGame();
|
||||
|
||||
@property (nonatomic, retain) id eaglView;
|
||||
@property (nonatomic, retain) UITextField *inputField;
|
||||
|
||||
@@ -50,12 +50,28 @@
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
NSLog(@"EAGL ViewController - view Will Appear");
|
||||
|
||||
[self.view resumeGame];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[self.view pauseGame];
|
||||
}
|
||||
|
||||
- (void)pauseGame
|
||||
{
|
||||
[self.view pauseGame];
|
||||
}
|
||||
|
||||
- (void)resumeGame
|
||||
{
|
||||
[self.view resumeGame];
|
||||
}
|
||||
|
||||
- (void)endGame
|
||||
{
|
||||
[self.view endGame];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
|
||||
@@ -118,6 +118,18 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::ResumeMusic(JMusic *music)
|
||||
{
|
||||
[[SoundManager sharedSoundManager] resumeMusic];
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PauseMusic(JMusic *music)
|
||||
{
|
||||
[[SoundManager sharedSoundManager] pauseMusic];
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
{
|
||||
NSString *key = [NSString stringWithCString: music->key.c_str() encoding: NSUTF8StringEncoding];
|
||||
@@ -156,10 +168,13 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
|
||||
{
|
||||
NSArray *components = [[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] componentsSeparatedByString:@"."];
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
sample->filename = fullpath;
|
||||
sample->ext = [[components lastObject] cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
NSString *key = [components objectAtIndex:0];
|
||||
NSString *musicFile = [NSString stringWithCString: fullpath.c_str() encoding:NSUTF8StringEncoding];
|
||||
sample->filename = fullpath;
|
||||
sample->ext = [[components lastObject] cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
if ([key isEqualToString: @""])
|
||||
return sample;
|
||||
sample->key = [key cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
[[SoundManager sharedSoundManager] loadSoundWithKey: key musicFile: musicFile];
|
||||
}
|
||||
return sample;
|
||||
|
||||
@@ -253,11 +253,20 @@
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc removeObserver: self name: @"intializeGame" object: nil];
|
||||
[dnc removeObserver: self name: @"readyToStartGame" object: nil];
|
||||
[dnc addObserver: glViewController selector:@selector(pauseGame) name: UIApplicationWillResignActiveNotification object: nil];
|
||||
[dnc addObserver: glViewController selector:@selector(resumeGame) name: UIApplicationDidBecomeActiveNotification object: nil];
|
||||
[dnc addObserver: glViewController selector:@selector(resumeGame) name:UIApplicationWillEnterForegroundNotification object: nil];
|
||||
[dnc addObserver: glViewController selector:@selector(destroyGame) name:UIApplicationWillTerminateNotification object: nil];
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc removeObserver: glViewController name: UIApplicationDidBecomeActiveNotification object: nil];
|
||||
[dnc removeObserver: glViewController name: UIApplicationDidEnterBackgroundNotification object: nil];
|
||||
[dnc removeObserver: glViewController name: UIApplicationWillTerminateNotification object: nil];
|
||||
[dnc removeObserver: glViewController name: UIApplicationWillResignActiveNotification object: nil];
|
||||
[window release];
|
||||
[glViewController release];
|
||||
[hostReach release];
|
||||
@@ -312,36 +321,9 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application
|
||||
{
|
||||
if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)])
|
||||
[self.glViewController.view stopAnimation];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application
|
||||
{
|
||||
if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)])
|
||||
[self.glViewController.view startAnimation];
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||
{
|
||||
if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)])
|
||||
[self.glViewController.view startAnimation];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)])
|
||||
[self.glViewController.view stopAnimation];
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
if ( [self.glViewController.view respondsToSelector: @selector(stopAnimation)])
|
||||
[self.glViewController.view stopAnimation];
|
||||
[self.glViewController.view destroyGame];
|
||||
}
|
||||
|
||||
- (void)initializeKeyboard: (id) initialState
|
||||
|
||||
@@ -220,6 +220,18 @@ void JSoundSystem::StopMusic(JMusic *music)
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PauseMusic(JMusic *music)
|
||||
{
|
||||
StopMusic(music);
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::ResumeMusic(JMusic *music)
|
||||
{
|
||||
PlayMusic(music);
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::SetVolume(int volume)
|
||||
{
|
||||
SetMusicVolume(volume);
|
||||
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
static string currentMusicFile;
|
||||
static void playMusic(string filename = "", bool loop = true);
|
||||
static void stopMusic();
|
||||
static void pauseMusic();
|
||||
static void resumeMusic();
|
||||
static PlayerType players[2];
|
||||
|
||||
};
|
||||
|
||||
@@ -474,12 +474,12 @@ void GameApp::SetCurrentState(GameState * state)
|
||||
|
||||
void GameApp::Pause()
|
||||
{
|
||||
stopMusic();
|
||||
pauseMusic();
|
||||
}
|
||||
|
||||
void GameApp::Resume()
|
||||
{
|
||||
playMusic();
|
||||
resumeMusic();
|
||||
}
|
||||
|
||||
void GameApp::DoTransition(int trans, int tostate, float dur, bool animonly)
|
||||
@@ -555,6 +555,24 @@ void GameApp::playMusic(string filename, bool loop)
|
||||
}
|
||||
}
|
||||
|
||||
void GameApp::pauseMusic()
|
||||
{
|
||||
if (music && currentMusicFile != "")
|
||||
{
|
||||
JSoundSystem::GetInstance()->PauseMusic(music);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GameApp::resumeMusic()
|
||||
{
|
||||
if (music && currentMusicFile != "")
|
||||
{
|
||||
JSoundSystem::GetInstance()->ResumeMusic(music);
|
||||
}
|
||||
}
|
||||
|
||||
void GameApp::stopMusic()
|
||||
{
|
||||
if (music && currentMusicFile != "")
|
||||
|
||||
@@ -278,8 +278,8 @@ void WCachedSample::Refresh()
|
||||
bool WCachedSample::Attempt(const string& filename, int submode, int & error)
|
||||
{
|
||||
loadedMode = submode;
|
||||
|
||||
sample = JSoundSystem::GetInstance()->LoadSample(WResourceManager::Instance()->sfxFile(filename).c_str());
|
||||
string sfxFile = WResourceManager::Instance()->sfxFile(filename);
|
||||
sample = JSoundSystem::GetInstance()->LoadSample(sfxFile.c_str());
|
||||
|
||||
if (!isGood())
|
||||
{
|
||||
|
||||
@@ -569,6 +569,7 @@
|
||||
12272FC314CD57CF00192DC7 /* SimpleButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleButton.cpp; sourceTree = "<group>"; };
|
||||
12272FC614CD68FB00192DC7 /* InteractiveButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InteractiveButton.h; sourceTree = "<group>"; };
|
||||
12272FC714CD6A3900192DC7 /* InteractiveButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InteractiveButton.cpp; sourceTree = "<group>"; };
|
||||
1235D03C14DE396D00B02B42 /* JSfx.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSfx.cpp; path = android/JSfx.cpp; sourceTree = "<group>"; };
|
||||
12769483144127380088F6D3 /* AIPlayerBaka.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBaka.cpp; sourceTree = "<group>"; };
|
||||
12769484144127380088F6D3 /* AIPlayerBakaB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBakaB.cpp; sourceTree = "<group>"; };
|
||||
12769485144127380088F6D3 /* TestSuiteAI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestSuiteAI.cpp; sourceTree = "<group>"; };
|
||||
@@ -1166,6 +1167,14 @@
|
||||
name = Controllers;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1235D03D14DE397200B02B42 /* android */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1235D03C14DE396D00B02B42 /* JSfx.cpp */,
|
||||
);
|
||||
name = android;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
125C5CF213B09AA200DF2F2C /* Tools */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1845,6 +1854,7 @@
|
||||
CEE232AF128A01F400C34032 /* src */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1235D03D14DE397200B02B42 /* android */,
|
||||
12DCD02B14DBE1AF0023B966 /* ios */,
|
||||
12B8121D1404B9E10092E303 /* zipFS */,
|
||||
CEE232B3128A01F400C34032 /* hge */,
|
||||
|
||||
Reference in New Issue
Block a user