[SOLVED] FPS drop on Android when moving finger around the screen (legacy)

I’m experiencing HUGE fps drop on Android devices when I begin moving finger around the screen (it might be related to MOUSE_MOVE event I guess but I’m not adding any listeners). The moment I stop moving my finger fps changes to 60, mouseChildren, mouseEnabled and cacheAsBitmap doesn’t seem to change anything. I’m using newest openfl (legacy) and lime.
On Xperia Neo V fps drop is visible after adding 25 sprites, on galaxy s3 after 250.

for (i in 0...50)
{
	var a = new Sprite();
	addChild(a);
	var rect:Sprite = new Sprite();
	a.addChild(rect);
	rect.graphics.lineStyle(3, 0x0D7923, 1);
	rect.graphics.drawRoundRect(0, 0, 50, 50, 10);
	a.mouseChildren = a.mouseEnabled = false;
	a.cacheAsBitmap = true;
	a.x = Std.random(stage.stageWidth);
	a.y = Std.random(stage.stageHeight);
}
this.mouseChildren = this.mouseEnabled = false;
addChild(new FPS(10, 40, 0xFF0000));

Adding bitmap instead of drawing round rect has the same effect.

Same problem on pirate pig example, the moment I begin moving my finger fps drops from 60 to 30 and if I set max fps to 30 it drops to 20-25 : ( It’s really weird because I’ve been using openfl for some time now and I have never noticed this.

I’ve seen similar drops before on Android devices, just in general, I think some hardware does this :frowning:

Yeah, it’s really weird, I’m not noticing fps drop on xperia tipo which is weaker than xperia neo v. I guess I’ll ignore this for now :slight_smile: Hopefully only few devices behave like this.

It’s known bug of older android phones - you must put Thread.sleep() inside onTouch handler.
That how I “fix” this in my android game:

@hcwdikk can you try to put

try {
    Thread.sleep((Build.VERSION.SDK_INT < 8) ? 16 : 1);
} catch (InterruptedException e) {
}

just before return true in onTouch handler in SDLActivity.java ?
https://github.com/openfl/lime/blob/master/templates/android/template/src/org/libsdl/app/SDLActivity.java#L1227

1 Like

or if you use legacy, look at the legacy templates folder for the “GameActivity”, I think

1 Like

I guess it worked, fps now drops to 45-50 instead of 30 :slight_smile: Thanks a lot.

edit: Bigger sleep value decreases fps drop even more.
Also if anyone else would like to add restorer’s fix, onTouchEvent function is located in MainView.java in legacy template folder.

Glad to hear that it helps :success:

Just sent a PR:

Pulled, please let me know, everyone, if you experience any other side-effects from this, such as delayed events of other types, or conflicts with native extensions. In general, dispatching less touch events does seem like the fix here, though