Highlighted

Game continued Scrolling LAG Air For Android

Explorer ,
Dec 07, 2017

Copy link to clipboard

Copied

Hello,

I develop a game for android and ios with animate cc and i have red a lot of discussions to improve performance on mobile but i have still a lag (drop framerate) when scrolling.

View my game like Flappy Bird or like a Runner game, obstacles which are scrolling continued to the left and a character wich jump.

FPS = 60 and i use last version of AIR SDK.

The game works perfectly on PC, on Galaxy S6 it works almost perfectly, but on Galaxy S4 and Smartphones less powerful, there are lags while scrolling.

So, i have made a test, with just two elements :

- An image (PNG)

- A button (made with PNG image)

When i tap on the button, the image move to the left by 5px each frame with "EventEnterFrame" .

With this test, the problem is the same. On Galaxy S6 no lag but on Galaxy S4 a random lag during the scroll.

test.jpg

Here is the simply code :

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// imports and settings

import flash.display.BitmapData;

import flash.display.Bitmap;

Multitouch.mapTouchToMouse = false;

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

stage.align = StageAlign.TOP_LEFT;

// create a bitmapdata with my image on library and place it on right of the screen

var bmpData:BitmapData=new MyImagePNG();

var bmp:Bitmap=new Bitmap(bmpData);

addChild(bmp);

bmp.y=200;

bmp.x=600;

// Add button listener

btn.addEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

// function for the button

function buttonFunction(e:Event)

{

     btn.removeEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

    // add a enterFrameEvent to move image

    addEventListener(Event.ENTER_FRAME, moveImage);

}

// moving image

function moveImage(e:Event)

{

    bmp.x-=5;

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I don't understand why with just two elements the scrolling doesn't work perfectly...

Have you an idee or a trick to solve this ? Because Galaxy S4 is not so old and a lot of mobiles are less peforming than his, so the game will not problably work very good on a lot of mobiles...

Thanks !!!

TOPICS
Development

Views

1.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Game continued Scrolling LAG Air For Android

Explorer ,
Dec 07, 2017

Copy link to clipboard

Copied

Hello,

I develop a game for android and ios with animate cc and i have red a lot of discussions to improve performance on mobile but i have still a lag (drop framerate) when scrolling.

View my game like Flappy Bird or like a Runner game, obstacles which are scrolling continued to the left and a character wich jump.

FPS = 60 and i use last version of AIR SDK.

The game works perfectly on PC, on Galaxy S6 it works almost perfectly, but on Galaxy S4 and Smartphones less powerful, there are lags while scrolling.

So, i have made a test, with just two elements :

- An image (PNG)

- A button (made with PNG image)

When i tap on the button, the image move to the left by 5px each frame with "EventEnterFrame" .

With this test, the problem is the same. On Galaxy S6 no lag but on Galaxy S4 a random lag during the scroll.

test.jpg

Here is the simply code :

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// imports and settings

import flash.display.BitmapData;

import flash.display.Bitmap;

Multitouch.mapTouchToMouse = false;

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

stage.align = StageAlign.TOP_LEFT;

// create a bitmapdata with my image on library and place it on right of the screen

var bmpData:BitmapData=new MyImagePNG();

var bmp:Bitmap=new Bitmap(bmpData);

addChild(bmp);

bmp.y=200;

bmp.x=600;

// Add button listener

btn.addEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

// function for the button

function buttonFunction(e:Event)

{

     btn.removeEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

    // add a enterFrameEvent to move image

    addEventListener(Event.ENTER_FRAME, moveImage);

}

// moving image

function moveImage(e:Event)

{

    bmp.x-=5;

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I don't understand why with just two elements the scrolling doesn't work perfectly...

Have you an idee or a trick to solve this ? Because Galaxy S4 is not so old and a lot of mobiles are less peforming than his, so the game will not problably work very good on a lot of mobiles...

Thanks !!!

TOPICS
Development

Views

1.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 07, 2017 0
Explorer ,
Jan 19, 2018

Copy link to clipboard

Copied

No one to help me ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 19, 2018 0
Engaged ,
Jan 20, 2018

Copy link to clipboard

Copied

You are using the classic displayList which was built long before mobile was a thing.

Stage3D was created (5+ years ago) to render on the GPU which better suits mobile devices.

You should look into using Starling which is an AIR framework which provides an API around Stage3D - you will achieve much better results.

https://gamua.com/starling/

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 20, 2018 0
Advocate ,
Jan 22, 2018

Copy link to clipboard

Copied

Those type of game usually require top graphic performance so they are usually done with DIRECT mode and Stage3D based frameworks but this does limit your support for low end/old devices. The only other option with less overall performance is GPU mode and NO vector graphics (only bitmaps), if you can achieve a good performance in this mode you can usually expect a fair to good performance on low end/old devices. Besides those 2 options there are none that will give you a satisfactory performance.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Adobe Community Professional ,
Jan 20, 2018

Copy link to clipboard

Copied

As an alternative to learning Stage3D or Starling, you can set the rendermode to GPU. Then the regular displaylist graphics are handled by the GPU, and you can get 60 fps scrolling.

It wouldn't be very hard to try loading so many images that the GPU gets filled up, and the app could crash. But that would be true with Starling as well.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 20, 2018 0
Explorer ,
Jan 22, 2018

Copy link to clipboard

Copied

Hello everyone,

Thanks for your answers !!

Sorry, i have not been enough accurate in my post but i'm already in GPU mode with only bitmaps. I have red a lot of discussions to improve perfomances and my game is not so bad, there is just this lag which is problemactic...the rest works very well even with animate CC.

For information, i have already test with Starling and the problem is the same...

But, after your answers, i have decided to make tests again and what i have discovered is VERY STRANGE...

At begining, i thought this was a performance problem, that is why i have made this test with just a button and a bitmap to verify that was not my game which was too massive.

After the test (button + bitmap), i had doubts because the lag was present with just two elements too...

Today, i have installed "DU RECORDER" app to record a video capture of my test in GALAXY S4 to show you the problem in video to make it easier and guess what ? With the video recorder activated in the mobile during the game, the lag is gone !!!

it's just amazing !! The only one explication that i see is that the lag is caused by a bug in the management of framerate and ressources...

I had ever seen in Adobe Scout that sometimes the framerate drops because a wait of gpu...furthermore, my game is at 60fps because i have not succeeded to make it fluid at a lower framerate.

I don't understand why the framerate is more stable at 60fps than at 30fps...

Here you can see the charts of just a rectangle in the scene at 30 and 60fps in adobe scout :

Capture_30.PNG

30 fps, we can see that the framerate is not stable...

Capture_60.PNG

And at 60fps, the framerate is more stable....

Now, it only remains to me to find the solution...if i follow the reasoning i have to weighing my game to simulate a second app that works in the same time ha ha !!

I will post videos as soon as possible, one video capture with my mobile camera and one with "DU RECORDER" to show you the difference...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Adobe Community Professional ,
Jan 22, 2018

Copy link to clipboard

Copied

There is a historic issue to do with browser plugins, where setting 31 fps was a lot better than 30 fps. I could imagine something like that going on.

But another culprit could be timers. With a timer anything that is done in the timer handler will delay the time to the next timer event. For example, if you had a timer at 30 fps (every 33 milliseconds), and the work it needed to done took say 17 milliseconds, your final frame rate would be 20 fps. With a timer at 60 fps the final frame rate would be 30 fps.

The easy fix to that is to do everything you possibly can on enter frame. You could have a 30 fps animation, and 33 milliseconds worth of stuff to do on every enterframe, and you would still get 30 fps, because all of that work is done during the period that the frame is being shown.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Explorer ,
Jan 23, 2018

Copy link to clipboard

Copied

Thank you for your answer !

I think this is an issue of this style, i have tried with a framerate at 59 instead of 60 and the lag is amplified...

But now, the question is how to resolve this ? 60fps is the max, so i can't increase it. How to have exactly the necessary time in each frame ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Advocate ,
Jan 23, 2018

Copy link to clipboard

Copied

Well you can't have the necessary time in each frame, that's beyond your control. What you can do is compensate with time based motion/animation, instead of doing myobject.x += speed it needs to be myobject.x += speed * timecompensation where timecompensation is the result of calculating the time spent since last frame and the amount to move your objects based on that. If you don't do time based motion/animation then the fps is in control of all that (and any drop in fps might result in choppy animation), if you do time based motion/animation then you are in control of it (and drop in fps will be compensated for).

Here's a simple example:

With your app set at 60fps you move an object by 1 pixel for 120 frames: you expect the object to reach 120 pixels motion in exactly 2 seconds, it won't because of fps being not linear and maybe dropping to 50 ect ...

So instead of moving your object by 1 pixel you move it based on time: time base = 2000 milliseconds (2s), goal = 120 pixels, this gives you a 0.06 pixel ratio (120/2000), for each millisecond spent, your object must move by 0.06 pixel. Now you keep track of time (getTimer()) on each frame then calculate how many milliseconds went between 2 frames. Example, last frame time - this frame time (at around 60 fps you might get 16ms) but let's say you got fps drop and spent 25ms time since last frame, you just move your object 25 * 0.06. Now with this time based motion you will reach your 120 pixel goal in exactly 2 seconds and you will compensate for drop of frames.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Explorer ,
Jan 23, 2018

Copy link to clipboard

Copied

Thanks for your answer !

Your approach is correct but i have tested it and the problem is more visible than with just enterframe...always this jerks...

This is my code for the test with a button and a bitmap, tell me if something is incorrect :

================================================================================

import flash.events.Event;

import flash.utils.getTimer;

Multitouch.mapTouchToMouse = false;

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

var lastTimer:Number=0;

var newTimer:Number=0;

var diff:Number=0;

var nb:Number=0;

btn.addEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

function buttonFunction(e:Event)

{

  btn.removeEventListener(TouchEvent.TOUCH_TAP,buttonFunction);

  lastTimer=getTimer();

  seq.addEventListener(Event.ENTER_FRAME,move);

}

function move(e:Event)

{

  newTimer=getTimer();

  diff=newTimer-lastTimer;

  // 0.3 = pixel / millisecond

  nb=diff*0.3;

  seq.x-=nb;

  trace(nb.toString());

  lastTimer=newTimer;

}

================================================================================

I think it's good to move bitmap exactly of a number of pixel by second (ex : 120pixels in 2 seconds as in your example) but when

you have for example a frame time at 30ms instead of 16ms (60fps) and next frame at 10ms, you move the bitmap of 9px and then of 3px, so it's visible and make the application not fluid....

Here is the captures of AdobeScout with my game without and with video recorder activated :

1) Without recorder

game1.PNG

Sometimes, no problems, this is fluid....

game2.PNG

But sometimes, you can see the gray bars very high....theses gray bars mean in adobe scout "wait for GPU" or "Wait for the next image".

For example, the gray bar with number 1 = Wait for GPU, 51ms !!

2) And now, the chart with video recorder activated :

game3.PNG

Always with this style of gray bars, never very high gray bars....

What do you think of that ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Advocate ,
Jan 23, 2018

Copy link to clipboard

Copied

Are you moving vector objects? Is there any vector graphics involved?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Explorer ,
Jan 23, 2018

Copy link to clipboard

Copied

No, just bitmaps...

I know the problem with vector and i have followed all recommandations about performance issue.

You can see in my charts that the green bars are not very high...

I don't understand why with the video recorder activated the game and the chart are best than without it...this should impact the performance in the  contrary direction lol

I have found an older similar discussion on the starling forum but without solution...

I have sent a message to his author to know if he has found the solution...

https://forum.starling-framework.org/topic/starling-waiting-for-gpu-waiting-for-next-frame-when-inte...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Explorer ,
Jan 23, 2018

Copy link to clipboard

Copied

I have found this post with a similar issue wich show that i'm not crazy ha ha

Oscillating performance problem in AIR for desktop

Rechut says :

One FASCINATING thing I have chanced upon is:

if I have chrome browser open in the background, everything is super smooth.

it is as if chrome (32 bit) opened up some mesterious proces that air is able to exploit

strange!!!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Advocate ,
Jan 24, 2018

Copy link to clipboard

Copied

Yeah but this is from 2013, so much has changed since then. You need to accept first that what you experience is not what everybody else experiences, if it was, AIR would have been dead long ago. If you can accept that then you can start to narrow down your problem and figure things out. I've seen people having all kind of problems with AIR and blaming AIR for this and that until they tried their build on another computer, and then another and then another, ect ... only to realize their computer was the sole problem all along.

My advice is this: Don't go for the easy blame (it's not a coincidence this is also what would requires the less work from you) and try to find clues as to blame AIR for your problem, turns out in most cases AIR is not to blame for coders' problems. Do a real investigation, do real comparisons and keep in mind everybody can do smooth motions/animations using AIR, everybody so it's simply near to impossible you have suddenly discover that AIR can't move object on screen smoothly while the thousands of developers that have used AIR in the past 10 years did not notice it.

It's just a fact AIR can move ONE object across the screen smoothly, period, the fact that you can't only means there's something in your code doing this or something related to your computer doing this. Again if AIR couldn't do that it would have been dead long long ago.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

I agree, but i think it would be good if we can question directly an expert of adobe instead of searching during days while this is maybe a thing that can be resolved in 5 minutes...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 23, 2018

Copy link to clipboard

Copied

i have maybe found a solution, but for complete it, i need to know the time of execution of each frame.

does it exist an event in as3 or a method to know when the frame has executed the code and the rendering is finish ?

If you see a chart of adobe scout in one of my previous posts, this is the time of color bars that i want to know, before the gray bar and so the suspend time happens...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Adobe Community Professional ,
Jan 23, 2018

Copy link to clipboard

Copied

enterframe is what happens immediately after things are rendered. That's why I was saying to do everything you can in the enterframe listener function, because you get an entire frame's worth of time to do things. What you change during that time will be seen just before the next enterframe.

Timers and mouse events could happen at any time I think, which means there is a chance that you're doing code at the end of the frame's duration. In cases like that you extend the current frame, delaying the render, and making the frame rate slower.

I haven't gone this far with the idea, but thinking about it, if a mouse event might lead to a lengthy function that has to run, instead of doing that right away, just make a note that it needs doing, and do that in the enterframe function as well.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

Colin, thanks for your answer

Yesterday, i have made a new test with your approach. I think that the problem is caused by the standby "Waiting for GPU" and "Waiting or next frame". I imagine that to wake up the processus there is a little time...this is why when i run the app with video recorder too, the GPU is almost never on standy...

So, my goal is to fill all the frame budget (17ms for 60fps). But this is here that i have a problem.

I want to make a script in the enterframe event with a "for" wich turn while the frame budget is not reaches.

This is my code :

===============================================================================

import flash.events.Event;

Multitouch.mapTouchToMouse = false;

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

import flash.utils.getTimer;

var BeginFrameTimer:Number=0;

var EndFrameTimer:Number=0;

var nb:Number=1000000;

var i:Number=0;

var frameBudget:Number=13; // for the test i put 13 instead of 17 because it begin after enterfram event

btn.addEventListener(MouseEvent.CLICK,buttonFunction);

function buttonFunction(e:Event)

{

     btn.removeEventListener(MouseEvent.CLICK,buttonFunction);

     seq.addEventListener(Event.ENTER_FRAME,move);

}

function move(e:Event)

{

     BeginFrameTimer=getTimer();

     seq.x-=5;

     for (i=0;i<nb;i++)

     {

          EndFrameTimer=getTimer();

          if (EndFrameTimer-BeginFrameTimer>=frameBudget)

          {

              i=nb;

          }

     }

}

====================================================================================

For just this test, it correct the problem of lag so the approach is good, but the time of execution code in loop is always the same. I still have a problem  to calculate the time between the begin of rendering and end of rendering.

With your information, now i know that the enterFrame event is the end of rendering (and i have confirmed that with a test).

So i have the time of end of rendering, now it miss just the time of the begin of rendering.

Here is a capture of AdobeScout to be more understandable :

adobescout.png

So, in 2 after the red and green bars, this is the enterFrame event. I would like to know the time between 1 and 2 in enterFrame.

But which event is ? I think if AdobeScout can calculate it, we can too...

Can you help me ?

Thanks !!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Advocate ,
Jan 24, 2018

Copy link to clipboard

Copied

The only conclusion I can draw from all this is this: Your s4 (already fairly slow tablet) is causing this lag due to some system problem/apps OR your code is causing this and the s6 is powerful enough to not show it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Adobe Community Professional ,
Jan 24, 2018

Copy link to clipboard

Copied

Just to confirm, with enterframe you now have no lag, and can do what you were doing before. But now you want to do more than before, to fill up all the available time?

Changing what you have to this might be better:

var BeginFrameTimer:int = getTimer();

var frameBudget:int=13;

function move(e:Event) {    

     seq.x-=5;

   while((getTimer()-BeginFrameTimer)<frameBudget)  {

        //do what you want to do lots of...

     }

    BeginFrameTimer =  getTimer();

}

Notice that the two variable are 'int', as they are integers. The code inside the while loop will run as many times as it can in 13 milliseconds.

Exactly like that you will have the issue that BeginFrameTimer will be much earlier than getTime(), and so the first 'while' won't achieve anything. But there's ways around that, if it matters.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

ASWC  a écrit

The only conclusion I can draw from all this is this: Your s4 (already fairly slow tablet) is causing this lag due to some system problem/apps OR your code is causing this and the s6 is powerful enough to not show it.

No, i don't agree with that, because on S6 the lag is present too but less visible because of the power of S6.

Further more, i have test my game on Galaxy J3 and above all on IPHONE 6 PLUS, so i think there is a problem independent of the mobile...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Advocate ,
Jan 24, 2018

Copy link to clipboard

Copied

Well then it's the code that creates that lag, as I said prior, it is a fact that there's no lag whatsoever when running a AIR app and moving something across the screen, this can be confirmed by all AIR developers, is this is something you disagree with then your testing should start there, if you agree with that then your testing and investigation should start with your code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

The problem is the same on J3 and Iphone 6 plus wich is a recent and powerful mobile...

And, you can see that this is though strange that when i fill the frame budget or i run video recorder the game works better.

I have download the source of "Hungry heroe" that has been created by a professional and which is a reference of starling.

When i will have the time, i will compiled it and run into the galaxy S4 to see...

Furthermore, we can't tell that the problem is my game because with just two basic elements there is a lag too even with starling.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

ASWC  a écrit

Well then it's the code that creates that lag, as I said prior, it is a fact that there's no lag whatsoever when running a AIR app and moving something across the screen, this can be confirmed by all AIR developers, is this is something you disagree with then your testing should start there, if you agree with that then your testing and investigation should start with your code.

Yes, i would like to be agree with you, but you have see my script for the test with two elements ? just few lignes of code...

I would like to believe that this is not AIR the problem, but in this case, tell me what is wrong with this code ?

is it so difficult to make a correct enterFrame event ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Advocate ,
Jan 24, 2018

Copy link to clipboard

Copied

I understand that, but the translation of what you are basically saying is that the problem is from AIR itself that is according to you unable to move correctly a couple of object across the screen. The 10+ years of AIR being around is my first clue for concluding this is highly unlikely, see what I'm saying?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Colin+Holgate  a écrit

Just to confirm, with enterframe you now have no lag, and can do what you were doing before. But now you want to do more than before, to fill up all the available time?

Changing what you have to this might be better:

var BeginFrameTimer:int = getTimer();

var frameBudget:int=13;

function move(e:Event) {    

     seq.x-=5;

   while((getTimer()-BeginFrameTimer)<frameBudget)  {

        //do what you want to do lots of...

     }

    BeginFrameTimer =  getTimer();

}

Notice that the two variable are 'int', as they are integers. The code inside the while loop will run as many times as it can in 13 milliseconds.

Exactly like that you will have the issue that BeginFrameTimer will be much earlier than getTime(), and so the first 'while' won't achieve anything. But there's ways around that, if it matters.

Colin,

"Just to confirm, with enterframe you now have no lag, and can do what you were doing before. But now you want to do more than before, to fill up all the available time?"

No, i have always this lag with enterFrame except when i fill up all the available time.

So i would like to know the time of rendering before enterFrame (the chart of adobeScout in my previous post, red an green bars).

With the actual "while" loop, i get the timer on the begin of enterFrame, for example 1200.

As my fps is 60, i have a available time of 17ms by frame.

So, with this actual code and while loop, the enterFrame code take 17ms and getTimer=1217.

But the enterFrame Event arrives after rendering, so finally the while loop take 17ms but this should be 17-timeOfRendering for really make a 17ms frame time.

Here, this is finally 17 + timeOfRendering...

This is why i want to know if i can get the timer before rendering.

Capture_10.PNG

When i get the first timer in enterFrame, i'am already in point 2, so if i add 17ms of code, necessarily this exceeds the 17ms of available.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Adobe Community Professional ,
Jan 24, 2018

Copy link to clipboard

Copied

The getTimer() is effectively helping you to measure the rendering time. You know that a frame should be 17 milliseconds long, if getTimer()-BeginFrameTimer has a first reading of say 3, and your budget is 13, then 10 things will happen, and not 13 things. It will be done in time to keep up the frame rate.

Would you be able to post the smallest test that shows what you are seeing, so that we all can try out ideas on the same code?

By the way, how does the app play if you're not using Scout?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 24, 2018

Copy link to clipboard

Copied

Colin,

By the way, how does the app play if you're not using Scout?

Without Scout the result is the same. I have rightly installed Scout to resolve this problem.

The getTimer() is effectively helping you to measure the rendering time. You know that a frame should be 17 milliseconds long, if getTimer()-BeginFrameTimer has a first reading of say 3, and your budget is 13, then 10 things will happen, and not 13 things. It will be done in time to keep up the frame rate.

This is right, but the BeginFrameTimer is the time of the begining of my code in EnterFrame. So the second GetTimer() gives the time after execution of just bitmap.x-=5px.

With the test, i have note that the timer in enterFrame just get the time of execution of actionScript in the EnterFrame.

So when i get the BeginFrameTimer, the other processus ( memory, display, etc) that are in red and green in the chart have already

consumed a part of the 17ms available...and me i add again 17ms of code so i exceed the available time.

So that i want is to know the time of execution of red and green bars...

(ps : i have put 13 in the test to not exceed the time but it's logically 17).

Would you be able to post the smallest test that shows what you are seeing, so that we all can try out ideas on the same code?

Yes, of course !

What do you want to see exactly ? A video of the lag ? Or the fla file ? Or both ?

Tell me what is useful for you ?

Thanks for your help

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Adobe Community Professional ,
Jan 24, 2018

Copy link to clipboard

Copied

Just the FLA and any external code files would do.

About what you just said: "the BeginFrameTimer is the time of the begining of my code in EnterFrame", yes it is in your version, but it isn't in my one. In mine the BeginFrameTimer is set at the end of the enterframe, and so should give a useful value of getTimer.

Here's what I suggested:

var BeginFrameTimer:int = getTimer();

var frameBudget:int=13;

function move(e:Event) {   

     seq.x-=5;

   while((getTimer()-BeginFrameTimer)<frameBudget)  {

        //do what you want to do lots of...

     }

    BeginFrameTimer =  getTimer();

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 24, 2018 0
Explorer ,
Jan 25, 2018

Copy link to clipboard

Copied

About what you just said: "the BeginFrameTimer is the time of the begining of my code in EnterFrame", yes it is in your version, but it isn't in my one. In mine the BeginFrameTimer is set at the end of the enterframe, and so should give a useful value of getTimer.

Yes, i had thought to put the BeginFrameTimer at the end too, but there is a problem too.

Here, this the captures of Scout with BeginFrameTimer at the begining and at the end. (this is the pc version but the idee is the same).

1) Timer at begining :

begin.PNG

We know that this doesn't work because the BeginFrameTimer start at point 1 after the red and green bars, this add 17ms in addition to red and green times...so the total of time exceeds available time. This is why in the chart this exceeds the red line.

2) With your idee and BeginFrameTimer at the end

end3.png

This is better, but there is problem again. We get the time between 1 and 2, so logically the time of green and red bars that i would like to get but when there is a grey bar (waiting for gpu or next frame at point 3), the timer retrieve in 2 is distorted because we get the time of wainting too and you can see that the next blue bar (after point 1) don't rise to the red line. So instead of get the time of red + green bars we get the time of red + green + GRAY bars.

Finally, this is the time between 4 (or 5) and 2 that i would like to get. but how ??

Here, the links to the tests file (fla) :

1) normal test (the lag occurs only on mobile)

https://www.cote-clic.com/clients/test/normal_test.fla

2) timer test (the script is for mobile, but just change the TAP Event in Mouse Event to test on PC).

https://www.cote-clic.com/clients/test/timer_test.fla

Don't worry about the domain this is my web server.

Thanks again

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 25, 2018 0
Advocate ,
Jan 26, 2018

Copy link to clipboard

Copied

I did test it with some modification on S4:

stage.frameRate = 60;

var direction:Number = -1;

addEventListener(Event.ENTER_FRAME,move);

function move(e:Event)

{

mybitmap.x += 5 * direction;

if(mybitmap.x < 0 && direction < 0)

{

direction *= -1;

}

else if(mybitmap.x > 600 && direction > 0)

{

direction *= -1;

}

}

Yep it's looping the motion, which does make a big difference since after the first hickups you noticed the motion runs smoothly.

Now if I put a 10 second delay before start:

var timer:Timer = new Timer(10000, 1);

timer.addEventListener(TimerEvent.TIMER, handleTimer);

timer.start();

function handleTimer(e:Event)

{

addEventListener(Event.ENTER_FRAME,move);

}

Then the hickups are gone and the motion runs smoothly right from the start.

So what gives? AIR never truly starts at the designed FPS, on desktop this might not be noticeable but on mobile it is. So if your app is meant to run at 60fps it will take some time for the device to reach that framerate. If you run anything before the fps becomes stable then you get hickups. Solution: When your app starts, start by monitoring the FPS, once the fps is stable (does not mean on target, only means stable) start your app logic. And yes this is something I do in all my mobile based app but it's done by my underlying engine that fires a FRAMERATE_STABLE event.

On that fps note: Even if you ask your app to run at 60fps, remember that some device might only give you 30 or even less, now if you check for stable fps you need to check when the fps stays stable for a while not if the fps reach the value you ask for. Also this is why time based motion is preferable since the user experience on device with low fps might really be poor due to the bizarre animation and timing the low fps and non time based animation/logic produces.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2018 0
Adobe Community Professional ,
Jan 26, 2018

Copy link to clipboard

Copied

Long ago, when trying to get an app to perform ok on iPad 1, I found that off-stage objects would stutter as they came onto the stage. I worked around the issue by having at least a pixel's worth of the upcoming objects on the stage, before when they were needed. The objects could even be behind the currently featured objects. Then it all play smoothly from the start.

My conclusion was that AIR only send things to the GPU when they are over the stage, and that sending them can take some time.

Not sure why a timer would have helped, unless all of the objects were already on the stage, and you've already set it animating.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2018 0
ASWC LATEST
Advocate ,
Jan 26, 2018

Copy link to clipboard

Copied

There's definitely a few things starting up during that period where the fps grows to its final rate but in my experience all this fires whether you display something or not. As soon as the fps is stable everything seems to be ready to go at least that's what I seem to experience even back then with Ipad1. Timer are linked to fps and vice versa, that's one of the weird thing about them.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2018 0