AIR app inactive = lower framerate? - actionscript-3

I'm working in a quite uncomfortable setup and I'm trying to figure out how I can fix it.
I'm developing an AIR app that is receiving TUIO events from a Framework for a fiducial marker based multitouch table. Until yesterday I was faking the events by mouse to work faster, but then I connected everything to a TUIO simulator and the problems appeared.
The TUIO Simulator is a java app. By dragging markers on the simulator you can send OSC messages that I'm forwarding to my AIR app. The problem is that I'm noticing that when I drag something on the simulator, my AIR app lose the focus, and the AIR framerate suddendly drops. If I drag something on my simulator and I switch super fast to the AIR window, everything goes smooth, so it seems the problem is that if my AIR app is not the active app it's redrawn at a lower framerate (I remember reading something about this, not sure).
So my questions are: am I right about the fact that inactive windows in AIR are redrawn at lower framerate? do you have any suggestion/workaround to fix it and to allow me to interactive with the java app without my AIR framerate drops?

Sorry guys, I figured out the solution by writing the question :)
I just added:
this.stage.addEventListener ( Event.DEACTIVATE, onDeactivate );
private function onDeactivate (evt:Event):void {
stage.frameRate = 60;
}
In my main class, and everything is fixed.
I post the answer for people that could have the same problem in the future

Related

Phaser sound stops working only on Chrome for Android

The sound works for the first few minutes but after a while .play() doesn't play any sound. It seems like if there is a huge duration where no sound has played the sound stops working.
It works fine on Desktop, iOS and the generic android browser. I'm just running into this problem specifically on android devices using mobile chrome as the browser.
This turns out to be a Chrome bug that causes web audio to stop playing sounds if no sound has played for something like 30 seconds.
https://code.google.com/p/chromium/issues/detail?id=518863
The fix seems to be to watch
audioContext.currentTime
and when it gets stuck after 30 secs create a new audioContext.
The solution I ended up using is as follows:
Note I am using the phaser library - so this exact solution wont work for you - but it will give you the general idea
//This is run using a timer event every second
//this.game.time.events.loop(1000, this.checkAudioContext, this);
evil.AudioManager.prototype.checkAudioContext=function(){
//work out when the audio context has stopped
if(this.game.sound.context.currentTime-this.last_context_time===0){
//close out the existing context and create a new one
//you will also need new gain nodes if you are using them
this.game.sound.context.close();
this.game.sound.context=new AudioContext();
this.game.sound.masterGain= this.game.sound.context.createGain();
this.game.sound.masterGain.gain.volume=this.volume;
this.game.sound.masterGain.connect(this.game.sound.context.destination);
//now go through every sound and connect them to the new context
//creating gain nodes as we go.
for(var key in this.tracks){
var snd=this.tracks[key].snd;
snd.context=this.game.sound.context;
snd.masterGainNode = this.game.sound.masterGain;
snd.gainNode=this.game.sound.context.createGain();
snd.gainNode.gain.value = snd.volume * this.volume;
snd.gainNode.connect(snd.masterGainNode);
}
}else{
//update out time variable
this.last_context_time=ctx.currentTime;
}
}
What version of phaser and android do you have? For me it seems to play without issues for a 4-minute song i tried. Even if the screen goes of, it continues without any problem when it is resumed. A dirty solution will be to add an loop that plays a silent sound every 2 minutes for example just to "refresh" the sound manager if that solves your problem.

Hold gesture doesn't work without a little move

I ported some code to MonoGame and I got a problem: A hold gesture doesn't happen until I make a move, so in order to get a hold gesture I need press finger/mouse, wait for some time and then move finger/mouse a little bit. This issue reproduces on both Device and Emulator. I don't have this problem when use XNA library on the same device.
The code is simple
while (TouchPanel.IsGestureAvailable)
{
GestureSample originalGesture = TouchPanel.ReadGesture();
...
Is there any common solution except for emulating a hold gesture by processing TouchLocation?
Why not just check the TouchLocation.State for Pressed. If its pressed for more than 1 draw cycle then perhaps assume its a hold gesture?
Thats what I do in my monogame code, check TouchLocation.State for TouchLocationState.Pressed and TouchLocationState.Released.

KEEP_AWAKE, but turn off screen to save battery?

I have built a fun little MP3 player using FlashDevelop and Flash CS5.5 IDE (no Flex).
The app 'emulates' old school style radio by fading tracks from any chosen m3u playlist while interspersing random radio stabs, silly fake ads and dj chatter (much like Flash FM from GTA Vice City).
The app itself works very well, however, if I set SystemIdleMode.NORMAL the app stops when the screen saver kicks in, and when I set to SystemIdleMode.KEEP_AWAKE, the screen never kicks in and the app runs until the battery dies ... which unfortunately doesn't take too long ;)
Is it possible to 'disable' the screen while leaving the app running to help save battery?
If no, can I at least control brightness, and perhaps display a black overlay? Would this have much effect on battery life?
Any suggestions would be hugely appreciated.
Cheers.

Starling pauses when mouse leaves the stage area

I have just started using starling (framework based on stage3d) and i am working on a simple ping pong game.
What my problem is the moment my mouse leaves the stage area everything just stops and resumes working when the mouse enter the area again. I guess this is some feature in the framework but how can i control it... is there some kind of event being fired..?? or is there some way to stop this feature ??
If its relevant i am using the 'TouchEvent.Touch' event and using the 'moved' phase. Any other details if required i am ready to provide....
Thanks. :-)
Ok i finally got the solution from the official starling forums.
As my mouse left the stage my 'touch' was getting null... hence the whole 'pausing' of game code.. I don't know why i didn't get an error of some kind.
Still if someone is facing something similar.. might check ur values are not null...

StageVideo comes on top of everything in Flex Mobile Project

I'm Building a mobile application with Flex (Air 3.3).
For Android there is sum nasty bug with stageVideo.
When I minimize the app when the stageVideo is playing or paused and open it again sometimes the stageVideo comes on top of everything. In my understanding that should be impossible because the stageVideo in a layer above the stage layer but it's happening. I don't have any clue how to fix this. I don't use any masks, I'm only attaching netStream.
Regardless of why, you may be able to fix it simply by re-asserting its index in the DisplayList with addChildAt().
The only question left is when to call the operation. I don't know about AIR, but you'd likely be looking for something akin to Event.ACTIVATE. If you can't catch an event to trigger the check, check periodically with either a Timer or Event.ENTER_FRAME