I have a sound which is started with a loop method. When I temporarily exit the game by pressing the HOME button the game calls a pause method that pauses this sound. When I re-enter the current instance of the game the sound should not resume automatically because I do that in the click button event method of my Pause Menu; the problem is that it does resume automatically even though the resume method for this sound is not called. why does this happen? what am I missing?
This only happens on the phone not on desktop. If I click outside the DesktopLauncher window and then return to the game I don't hear the sound playing.
Related
So I'm trying to use the timer class in a Flash CC AS3 script.
When the SWF loads, it plays this looping video. When the user clicks the video, it goes to the next frame where there are 4 buttons which play movies, and a timer.
The timer is there so that if the user doesn't click after a few minutes (in this case a couple seconds) the SWF returns to frame 1 and plays the looping video, once again, until the user clicks.
After adding this to my COMPLETE and MOUSE_EVENT event listeners...
this(root).attractTimer.start();
when I click on the video, it removes it from stage and I'm again presented with the 4 buttons.
It's at that moment I need it to start the timer once again. If the timer runs out, it needs to gotoAndPlay(1).
I'm banging my head on the desk with this right now.
Looks like I got it working.
The buttons that fire off the video, I was using...
this(root).attractTimer.star();
I didn't need to use 'this'
instead I used
attractTimer.start();
I am trying to figure out how to implement a pause screen on background. In my game scene I have a method called pauseGame. I set this up so that the user can click on pause button while playing and menu comes up asking them if they want to resume or go to main menu. Now when the phone goes into the background I want to also call this same function in my game scene so that it will show that menu so that when the user comes back to the app they will be able to resume instead of it automatically starting. I have googled for hours now and tried a few things but the only thing I am able to come up with is to call the directors pause() method from the app delegate. Which is what is happening any way but I need to call the pauseGame method of my game scene. Is there an event that I can listen for in the game scene or is there a way to call my pause from the appdelegate. I just cant seem to find an answer for this one.
App Delegate has this function, void AppDelegate::applicationDidEnterBackground(), which gets called every time app enters background.
You can access current scene by using this,
Director::getInstance()->getRunningScene(); cocos2d-x 3.0
CCDirector::sharedInstance()->getRunningScene(); cocos2d-x 2.x //Not entirely sure of the syntax, pls to check
After right typecasting and importing the appropriate header file, you can call required function from here.
Also,
AppDelegate also has, void AppDelegate::applicationWillEnterForeground(), which gets called every time app enters foreground.
I have made a simple game in flash. It includes a timer, falling objects and an object controlled by using swipe. So is there a way to stop every activity with the pause button and start it back again with the play button. Basically I want the whole stage to pause and play using buttons.
There is no way to do it automaticaly. You could base your entire game on a timer (even for animations and physics) and pause this timer. But this is a feature you have to think about during the very design of your game. Now I guess you just have to pause every movieclip, cancel your listeners to ENTER_FRAME and pause your timer.
Many game engines such as Flixel or FlashPunk include this feature
The way I do this in as3 is to run two timers, one that always runs at about 500ms and another that runs at framerate that varies with the speed of the game. Something like
public var speedControl:int = 15;
public var tick:Timer;
public function timers():void{
tick = new Timer(1000/speedControl);
tick.addEventListener(TimerEvent:TIMER,tickd);
tick.start();
}
public function tickd(t:TimerEvent):void{
// the timer has ticked
}
public function pause():void{
tick.stop();
}
public function play():void{
tick.start();
}
This is a basic example of course created on the fly, but you can call the pause or play button with a standard event listener. If your whole stage runs off of the timer, it will all stop. I use a second timer however that doesnt get stopped and started with the functions also. You really do want some things to run all the time.
If you wouldn't mind using the FP 11.8 Beta, it has that feature nativly to stop all movieclips recursively. Check it out here:
http://labs.adobe.com/technologies/flashruntimes/flashplayer/
When creating an AS3 project and adding audio what I usually do is drag the audio I want to use (for a game menu for example) and when I want to stop the audio I enter
SoundMixer.stopAll();
I do this because if I say go to the about game frame in this menu then I will have the audio, but if I come back to the main frame where I originally had the music it sorta doubles in and the two different timings of the music are playing at the same time.How do I stop this without having to disable the audio when I change frame?
In these cases, it is easier to start and stop the sound directly via code. First, right click the sound clip in your Library panel, and select Properties. In the ActionScript tab, check "Export for ActionScript", and give it a class name of, say, Music. Then, to play and stop this clip, you can use this code:
import flash.media.Sound;
// create the music Sound object so that we can start playing
var music : Sound = new Music();
var musicChannel : SoundChannel;
// play the music
// the play() method returns a SoundChannel,
// which you can later use to stop the music
// notice that we first check to make sure musicChannel is null
// if it isn't null, music is already playing, so don't play it twice
if(musicChannel != null) musicChannel = music.play();
// when you switch screens, stop the music
// clear out the channel, so that we know that it is safe to start the music again
musicChannel.stop();
musicChannel = null;
Alternatively, if you play music and sounds by placing them on the timeline, you can stop it by using the Sync setting of the frame. On the timeline, create a keyframe where you switch screens and want the music to stop playing. Select that frame, and drag the sound clip you want to stop onto that frame. In the Properties panel, change the Sync option to Stop. This will cause only the selected sound to stop playing.
Yet another method is to create an empty MovieClip with the sound placed inside of it. Change the Sync setting to Stream, and pad the clip out with empty frames so that it will play the entire clip. Then, if you place this clip on your main menu screen, then it will only play during the main menu. Stream sounds only play the sound for as long as the MovieClip exists and is playing. Compare this to normal Event sounds, which will play the entire sound regardless.
The latter methods are more old-school and movie-centric. If you are programming a game, it would be more appropriate to use the former method to give you more control of the audio in code.
I have an air app for iOS that plays a continuous sound to the user and there are settings to allow the app to periodically vibrate if audio is playing (notify the user if their volume is down basically). The app is able to continue playing the audio in the background however the timer event which is just a simple setinterval doesn't continue or pause.
So for example, the user will start play back, 10 seconds the device will vibrate, 10 seconds later another vibrate etc. If the user puts the app into the background (goes to their home screen etc) the audio continues which is great, but then in say 30 seconds they return to my app, the device will vibrate 3 times as it seems to store the amount of intervals have passed.
I guess my questions are:
- Can I have the app vibrate while in the background too?
- Can I have the app pause the interval when app loses focus and resume when it gets focus back?
If neither of the above are possible I will just have to exit on suspend.
Thanks
You can pause the setInterval on Deactivate and resume it on ACTIVATE, for that you have to add two event listeners. And you can code for your setinterval in that section accordingly.
Event Listeners :
stage.addEventListener(Event.ACTIVATE, appActivateHandler);
stage.addEventListener(Event.DEACTIVATE, appDeactivateHandler);
in deactivate listener you have to set :
stage.focus = null;
try it, this can help you.