Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / screen scrolling lag/jitter

Author
Message
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 12th Mar 2017 19:28
hello,
i'm working on a shoot em up style game and used setviewoffset() to scroll the screen in all directions. now even on my PC there is some lag/jitter when scrolling sometimes. its not constant, but its not smooth scrolling either. i have a old mobile which is still on android 2.0 and on that device you can really notice it badly. since its a old device i don't care too much, however on my PC this shouldn't happen. i've also tested it on 2 tablets and a friends iphone (via broadcast) and the lag/jitter is always noticeable, although on newer systems it isnt too bad, i would still expect its possible to have smooth scrolling without any lag?
also i've tried various things for example changing to timer based movement as previously i had movement just like in the examples and tutorial (i also find it quite strange that while timer based movement is basically the way to go, that all examples and tutorials don't bother with it).
i've disabled everything so that no enemies would be loaded only a ship and the movement code and i still get the lags. its as if the engine would stutter like everything hangs for a few milliseconds. of course i thought its probably my code, but now that i've tried all kinds of different things and also tested with examples that also had the lag (i.e. the space shooter game) i think it could be something with AGK.

i found this in the forum https://forum.thegamecreators.com/thread/214845 and it seems related i also only get it when using setviewoffset(), if i don't scroll the screen the lag doesn't seem to happen. i've tried using smaller background images and even without any background at all. didn't help.
i'm kind of out of ideas. i don't want to post my whole code, so not sure what part would help rightnow as like i said even with other example code i get the same results. wether i do it timer based or not. it doesnt seem like a lag when the framerate drops, but more like a complete hang for a few milliseconds.
are there any cpu expensive commands i should be aware of maybe that could cause such behaviour? also is there a reason why AppGameKit doesnt have multithreads? as it seems like the main thread hangs from time to time, which is normal when it executes cpu extensive tasks and multithreading could solve that by keeping the main thread active and run expensive code in a new thread. i mean there is an option to use multiple threads on SMP systems, why not lift the limit of 1 thread per core?

sorry for all the questions and vague explaination, but like i said not really sure what i could provide and i dont want to share the source in public, hope you understand!
any ideas what i could try would be appreciated, thanks!
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 13th Mar 2017 01:31 Edited at: 13th Mar 2017 01:32
Are you using tiles or an entire image as background? If it's an image, what is the size? Are you using physics? Would be really helpful if you could share at least the parts where you're loading the sprite and how you are using the setviewoffset() inside the do - loop.
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 13th Mar 2017 02:20
i use an entire image as background, tried different sizes for example 2000x2000, 2048x2048 and some others. yes i do use physics, but even if i disable that part i still notice the problem.
as for setviewoffset() i even tried using it just like in one of the examples.

for example thisone:



not sure if the problem is in setviewoffset() as suggested in the previous post that i've linked to, but the jitter seems to have to do with screenscrolling though.
also you asked how i load sprites, this is how i load the player:



thanks for taking the time to look into this problem!
JohnnyMeek
10
Years of Service
User Offline
Joined: 23rd Apr 2013
Location: Slovenia
Posted: 13th Mar 2017 06:38
Did you try enabling Vsync?

SetVSync( 1)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Mar 2017 07:25
hmm,
1.
physics collisions
2.
loops after condisions
3.
fill rate
https://www.appgamekit.com/documentation/Reference/Benchmarking.htm
4.
background services from other apps
5.
...

AGK (Steam) V2017.02.28 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 13th Mar 2017 12:17
yes i've also tried vsync.

as for the other suggestions:
1. disabled all physics collisions, still happens
2. can you elaborate what you mean with loops after conditions, what are the implications of this ?
3. i don't see anything about fill rate on the benchmark commands
4. that shouldnt affect the game this bad, there are always background apps running on any system..
5. ....

thanks
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 13th Mar 2017 15:30
I just made a simple routine with your code for testing purposes. Looks good to me here. Let us know what you get.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Mar 2017 16:56
Quote: "2. can you elaborate what you mean with loops after conditions, what are the implications of this ?"


something like this. because hit can true or false the frame time varies.
if hit then
for i = 1 to opponentscount
next
endif

you can also memory some values from frame time and render it with lines on screen (visualize) and enable/disable parts of your game to see when it gets constant or not.
GetFrameTime()
AGK (Steam) V2017.02.28 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 15th Mar 2017 01:12
@Richard_6 ..only moving a single sprite works, but when i use the same code to move the background (added it to my intro screen just for testing to let it move the background to the side) it lags/jitters again.
i've tried so much but i can never get smooth scrolling even if i limit everything to say 30 FPS.

ok so i've edited the AGK2 example of timer based movement to include a virtualjoystick and there i also notice the problem, here is the code:


(just take the media files from the AGK2 example project TimerMovement)

now just scroll around a bit and watch the edges of the background image for example (also drop the frame rate to 20 and back).
i notice it especially when scrolling diagonally. tried this example on android 2 and PC and on both i noticed the issue, its not smooth scrolling.
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 15th Mar 2017 03:12
Not sure why, but if you remove the SetSyncRate( 60, 0 ) it runs smoother and the default is already 60fps. Can you test it?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Mar 2017 07:52
I can't remember the exact detail, but there is something about the default 60FPS. Internally it is doing something else to stabilise things. As soon as you override the default 60FPS to...60FPS(!) you lose this internal stabilisation.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Mar 2017 09:04
Quote: "I can't remember the exact detail, but there is something about the default 60FPS. Internally it is doing something else to stabilise things. As soon as you override the default 60FPS to...60FPS(!) you lose this internal stabilisation."

I also agree with this.
I believe that by calling SetSyncRate it'll disable VSync, so you may need to turn this back on.
Signature removed by mod because it's larger than 600x120... please resize and try again.
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 15th Mar 2017 19:05
the problem happens eitherway with or without setvsync(1) or by setting the framerate specifically with setsyncrate(). also when using the default by not using any of these calls
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 16th Mar 2017 03:08
Try this:



Looks smooth here. I'm using a mac here but i don't think there will be much difference in a pc.
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 16th Mar 2017 03:43
thanks, but no didn't help, besides now you cant drop down to 20 frames anymore for testing, since the SetVSync(1) call will use the monitor refresh rate and be back at 60fps again
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 16th Mar 2017 05:03
i mean the "TimerMovement" code is an example of AGK2 and it has this jitter as well, so i'm really wondering if it might be a bug?
all i've added is the virtual joystick
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Mar 2017 06:26
It's not a bug specific to AppGameKit, as it works for a number of people including myself.
It could be a limitation of your hardware or operating system version. For example, if your graphics card cannot handle non-power of 2 images, this could cause a number of problems.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 16th Mar 2017 06:40
Hi 0x7f

Just tested Tip2 from here:
https://forum.thegamecreators.com/thread/213455

And its still perfectly smooth , tested on my oldest slowest android device.

Also try not to mix setvsync and SetSyncRate , example if you use code, SetSyncRate( 30, 0 ): setvsync(1) , you will NOT get the monitors refresh rate but 30 fps , even if you use setvsync(1). So try to only use one of them. I think internally SetSyncRate( 60, 0 ) is AppGameKit default, but 60 do not mean 60 but use the monitors refresh rate.

So on devices that force vsync (ios,android) no matter what AppGameKit does just use: SetSyncRate( 62, 0 ) , nothing else. and on desktop just use setvsync(1).

Sure your code should be able to handle the fps , or you will always get flicker.

best regards Preben Eriksen,
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 16th Mar 2017 15:04
@BatVink well doesnt seem to work for everyone. also as preben suggested the tip2 of that post also notes the flickering and provides a workaround that sounds kinda hackish not really like a clean solution.
also my gfx card is a geforce 845m it shouldnt have problems processing 2d games, afterall even a C64 could handle the type of game i'm working on
like i said i can disable everything and just leave a ship and joystick to fly around and still get the jitter. even with the example code from AGK2 there is the lag that could be reproduced as you can see in the previous posts.
if it was only me, nobody would notice anything.. i just changed the timermovement example code provided by AGK2 to include a virtualjoystick, posted it in this thread and someone else was able to verify the lag,
so its not only my device(s) nor my code since i didnt use my own code but the example from AGK2 lol
i can use setvsync, i can limit the framerate to 30 or 60 fps all doesnt matter ..although if i limit it to lowere fps the lags are much more noticeable.

@preben thanks a lot for the tip, but didnt seem to help. also i don't mix setsyncrate() and setvsync() since as i previously noted it wouldnt make sense
i also get the flickering on PC not only on mobile devices.

0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 17th Mar 2017 01:26
played around even more (not that i havent done enough testing the last weeks) with different setsyncrate settings and i cant get rid of it. even if i dont create sprites at all and only create scrolling text the lag is noticeable..sometimes it works smooth for a little while but then it lags again.
also since i use timer based movement it shouldnt be a problem of FPS dropping? anyways since the problem is present in the official AGK2 example code i assume its a bug with AGK2 somewhere.
its also hard to debug since the debugger included in AppGameKit is very simplistic and only shows variables in use (and even those have to be added manually), nothing else, no call traces no memory details, no cpu usage etc
that being said if not even the example code works properly (tested on multiple devices, win10, android 2.x and 5.x, ios) i somehow doubt its my fault (i thought since weeks its my fault, but if other code has the same issues....) .
also just for the record i may be new to AppGameKit, but not to programming
nickele upgraded
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Birthplace of Democracy
Posted: 17th Mar 2017 11:15
Are you absolutely sure that you run the executable with the geforce 845m graphics?
Notebooks usually select Intel integrated graphics graphics as default when users run apps, and frankly intel chipsets tend to suck in gfx.
This seams to me like a hardware limitation, not AGK's fault.
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 17th Mar 2017 14:15
Just to clear , i have absolutely NO flickering/jitter on my windows laptop or on my slow mac mini , not even on medium mobiles/tables ONLY on old slow mobiles, SetSyncRate( 62, 0 ) can be used to fix flickering/jittering ON OLD mobiles.
0x7f: if you e-mail me your project i will test and see if i also see the jitter, and perhaps im able to see what the problem is, plemsoft@plemsoft.com

best regards Preben Eriksen,
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 17th Mar 2017 17:30
A while back I investigated some jitter which sounds similar to what you mention, and discovered that it was caused by Windows Desktop Composition, which means the app doesn't draw directly to the screen, but to an off screen texture which Windows then uses to compose the desktop. Since then AppGameKit has taken this into account when VSync is enabled so that usually fixes the problem, however there might still be a problem in multi-monitor setups with non-identical monitors, meaning that each monitor might be redrawing at a different rate so VSync may not work properly.

Android would be a different issue since it doesn't use VSync, so you'd have to match the refresh rate to the display.
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 17th Mar 2017 21:19
@preben sent a mail thanks a lot!

@paul thzanks for the insight, however i tried various different settings/framerates and even limiting with ssetsyncrate and then calling setvsync(1) after that as previously suggested, but all didn't help really.
i even tried not creating any sprites just createtext() and let it scroll, even the scrolling text isn't smooth all the time. really out of ideas now
especially since i also get it with example code from AGK2..
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 19th Mar 2017 09:42 Edited at: 19th Mar 2017 09:47
0x7f: Tried you game today , ( great coding and game btw. )

On my mac it run 100% smooth no jitter, same with my ipad.

On my slowest oldest android the FPS is around 20-30 when playing the game , this will produce some jitter , but i found by limiting the "spikes" that comes from the fps drops when the device is doing something else in the background will limit the jitter enough to make it playable even on low fps. code changes:

This is ONLY for real SLOW devices, but can be used on all.
You know where it goes , mainly it use average move values instead of just taking the fps drop/move spike in one go , and limit the max spike.

EDIT: Ohh forgot also changed playerx,y to float.

WINDOWS 10 on my laptop , WELL i sure had jitter even if the game was perfectly able to run above 60 fps , and i had vsync on, Windows10 still jitter , but i found that this is a windows 10 problem. And a simple fix is to let Windows10 know this is a game running , it will then make sure to set all windows timers to allow vsync to work ( and disable ALL the internet info win10 "always" sent all the time, that really gives fps drops ).

Good thing is that Microsoft know this and made this available:

While playing your game in AppGameKit 'press': [WindowsKey] + [G] , and enable the "game bar".

This will enable game mode ( it will remember it ) , and completely removed ALL jitter i had in your game on windows 10. ( i really fell for you, using so mush time for something like this ).

Paul: Due to battery saving they limit timing so mush that gpu sometimes skips frames, so dont think AppGameKit itself can do anything about it, but perhaps you find a way to always enable game mode ?
best regards Preben Eriksen,
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Mar 2017 11:18
Good work Preben
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 22nd Mar 2017 01:04
thanks so much for trying to help me out, but unfortunately it doesn't work for me on win10 nor on android. i didn't test the game bar stuff as i've removed it when installing win10. also its kinda stupid if i would have to tell users they need to first change windows settings
i mean a simple 2d game like that should work on a vanilla windows install without any issues.
also on my old android it still lags and its not the issue of cpu/memory/screen as other (much more gfx/cpu/memory expensive) games work on the device too, or AppGameKit games without scrolling also work fine, but anything that scrolls lags.
i'm about to give up as its obviously not my code that causes the problem (as like shown above the lag also happens in official AGK2 example code and others can replicate the issue aswell).
i also don't think that any compensation of time will work, since it doesn't seem to be a problem witth the FPS dropping that is causing the lags.
it seems as if everything completely hangs for a few milliseconds, not slow down like on framerate drops, so compensating for that time would just keep positions where they should be, but the jitter is still visible.
well this really starts to get frustrating after over a month of trying all kinds of stuff...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2017 06:41
Does this method work on your hardware?
My personal preference is never to have fullscreen moving sprites, I assume in my mind that it will cause issues. In the example in the link, I opted to scroll the UV coordinates, not the sprite itself.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
0x7f
8
Years of Service
User Offline
Joined: 1st Apr 2016
Location:
Posted: 22nd Mar 2017 13:28
yes works better although the background also flickers at times, its much more playable, but thats probably because setviewoffset() isn't used at all and its only fake side scrolling by moving the background.
however in my game you can go into all directions 360° . the jitter is especially visible when flying diagonally. like i said when not scrolling it works fine
BitManip
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Essex
Posted: 7th Apr 2017 20:32
@0x7f you state "afterall even a C64 could handle the type of game i'm working on".

I have not looked at the code but see you are scrolling a backdrop as one image. The c64 would not handle this [well, now it does due to some amazing coding tricks, but never back in the day]. Everything the c64 used to do was character based (8x8 pixels on a 320x200 pixels - screen reduced by 16 pixels in each direction to hide updated chars). This means for full screen scrolling 38 chars x 23 chars (874 chars drawn each raster cycle). Why Am I detailing this...well sinply put, scrolling lends itself exceptionally well to tiled maps as it is both exceptionally memory efficient (especially ob larger backdrops), and tile iteration is fast. Even in tier 1 i can get several full screen tiled maps scrolling independantly and smoothly. AGK's sprite engine is efficient and I would bet more aimed at efficiency at managing numbers over size (batch processing quad lists based upon a binary tree no doubt).

For my late input, used tiled maps...just my opinion.
I control all the juicy in here!
CodeName
7
Years of Service
User Offline
Joined: 30th Dec 2016
Location:
Posted: 8th Apr 2017 14:52
Hi, 0x7f

Taking a guess.. I see you using #x < 20 ect..

Try using #x < 20.0 / /floats with floats

take care, have fun...
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 8th Apr 2017 21:42
Seems like an old thread resurrected but why not post.

I tried the timer example but the sprite scrolled quite fine for me on my macbook and on my android device. These are few years old so not the lowest grade but anyway.

The timer example does not quite work right for me because the sprite movement in this example is scaled different from the view offset. You scale the sprite movement by the frame time (in this example) but not the background movement. So for that reason the speed seems to differ for me at different framerates but it is still "smooth" as far as I see it.

So.. could not quite reproduce with this example.

good luck..

Login to post a reply

Server time is: 2024-04-20 01:24:38
Your offset time is: 2024-04-20 01:24:38