Hi everybody.
I made a game in GLBasic 10, a kwirk clone. I compilled both to windows and Android. In windows everything is ok, but the Android users report big perfomance problems, mainly, the need for press several times in buttons, to the event be accepted...
Check the two versions, both free:
win: galiksoft.is-great.org/kwirkfree.zip (copy and paste in url space of the browser)
android: https://play.google.com/store/apps/details?id=com.galiksoft.kwirkfree
The code structure is something like that:
gosub openlevel
gosub play
...
sub play:
while quit=0
gosub checkinput
gosub showgraphics
wend
endsub
...
sub showgraphics:
//draw everything
showscreen
endsub
...
sub checkinput:
local mx,my,b1,b2
mousestate mx,my,b1,b2
if b1>0
if mx>... and mx<... and my>... and my<... //test is the button area was pressed, example: up button
move(0,-1)
endif
endif
endsub
...
function move: %xx, %yy
//check if the character can move
//if it can move, refresh positions, move blocks or turn pieces if aplicable...
endfunction
Apparently this is the fine way to do, and in windows there is no problem.
But it Android, the game runs very slow...
I tought the problem would be in play sub, in the loop because the game is allways redrawing the screen and present it. I tried just redraw if there is a move, but that cause game crash in checkinput sub because of the mousestate command...
How can I improve the perfomance in Android?
i don't have an Android device but I got the same slow gameplay (with problems in accept button press) in Android Virtual Device, after compillation for Android.
Thank you in advance!
Runs fine on my Galaxy S2 but is a bit slow on my ZTE Blade
You have to press the move buttons a few times feels very unresponsive
The whole game is slow including the animation of the character
From what you say you seem to be doing everything right
You should be redrawing every loop
Maybe make sure your not loading images or levels in the main loop by accident
That isn't problem of Android but more likely not properly written code. On my dual-core pc, controls are responsive but game takes 50% of cpu power, it shouldn't happen.
You should use at least Limitfps and Sleep commands:
sub play:
Limitfps 30
while quit=0
gosub checkinput
gosub showgraphics
sleep 25
wend
endsub
Or your main loop can be more sophisticated:
sub play:
Limitfps 30
while quit=0
curr_time# = GETTIMERALL()
IF (curr_time# - last_time# >= 33)
gosub checkinput
gosub showgraphics
last_time# = curr_time#
ENDIF
sleep 20
wend
endsub
I don't have experience with current version of Android emulator, but add these changes and test how it will work.
Edit: Or maybe your drawing routines are messed up.. for example If your graphic covers whole screen don't use 'clearscreen' command, just draw new graphic over previous.
I've tested the Game on my Archos 101-Tablet and my Windows PC. On both platforms I had no speed-issue. The only thing i recognized was that the GPU-Usage on the PC was for this kind of game rather high. Maybe an OpenGL problem on some Android-Devices?
I can confirm, unfortunately, that on the Nexus 7 it's running very poorly, taking about a second a move.
Quote from: dreamerman on 2012-Jul-25
That isn't problem of Android but more likely not properly written code. On my dual-core pc, controls are responsive but game takes 50% of cpu power, it shouldn't happen.
You should use at least Limitfps and Sleep commands:
sub play:
Limitfps 30
while quit=0
gosub checkinput
gosub showgraphics
sleep 25
wend
endsub
Or your main loop can be more sophisticated:
sub play:
Limitfps 30
while quit=0
curr_time# = GETTIMERALL()
IF (curr_time# - last_time# >= 33)
gosub checkinput
gosub showgraphics
last_time# = curr_time#
ENDIF
sleep 20
wend
endsub
I don't have experience with current version of Android emulator, but add these changes and test how it will work.
Edit: Or maybe your drawing routines are messed up.. for example If your graphic covers whole screen don't use 'clearscreen' command, just draw new graphic over previous.
I made all these modifications and the game runs slow yet in Android Emulator....
Because in Android there are multiple resolutions I use stretchsprite commands instead of drawsprite. Is stretchsprite command so slow in Android to make the game been slow? As you can imagine, I use many times the command in the drawing sub. The cause would be that?
But does it still consume so much cpu/gpu power on pc? First extensively test your code on pc, with all possible trick's then, check how much speed it gained on emulator/real devices. Use 'LimitFps -1' to unlock fps limiter, and see how many fps you will get on pc with particular changes.
'StrechSprite' shoudn't be used many times, specially on mobile devices. There can be also other small issues, for example float calculations # are of course slower than integer %, so they should be used only when necessary.
When it comes to drawing, you probably should use other commands than strechsprite for example:
1. draw all graphic at desired res (let say 320x480) to offscreen texture (UseScreen cmd)
2. render that texture (with all game graphic) to screen with one strechsprite/polyvector
Of course also mouse position should be recalculated also..
Or use some already made custom functions like these from 'Z Project' by Ampos -> LINK (http://www.glbasic.com/forum/index.php?topic=7145.0)
Galiksoft, can you test your game with different Android-Versions on the Emulator? My Archos has 2.2 and I have no speed- or control-problems by playing your game. Maybe there is only a problem with some Android-Versions.
The Android emulator is extremely slow (as it's Java), so shouldn't be used as a guide to how GLBasic performs on Android.
You need either a proper machine or use Bluestacks, which emulates Android but at the proper speed (plus you can choose different display forms). The only downside is that you must sign your application as it won't allow unsigned ones.
I've tested Kwirk on BlueStacks and it is way too slow. Also the controls are sluggish and the player-sprite is wobbling. I've testet Angry Birds Space too and there was no problem with speed or controls. Both Games had the same CPU-Usage. I don't know which Android-Version Bluestacks uses, so I can't say the behavior is because of the Android-Version.
Quote from: dreamerman on 2012-Jul-25
But does it still consume so much cpu/gpu power on pc? First extensively test your code on pc, with all possible trick's then, check how much speed it gained on emulator/real devices. Use 'LimitFps -1' to unlock fps limiter, and see how many fps you will get on pc with particular changes.
'StrechSprite' shoudn't be used many times, specially on mobile devices. There can be also other small issues, for example float calculations # are of course slower than integer %, so they should be used only when necessary.
When it comes to drawing, you probably should use other commands than strechsprite for example:
1. draw all graphic at desired res (let say 320x480) to offscreen texture (UseScreen cmd)
2. render that texture (with all game graphic) to screen with one strechsprite/polyvector
Of course also mouse position should be recalculated also..
Or use some already made custom functions like these from 'Z Project' by Ampos -> LINK (http://www.glbasic.com/forum/index.php?topic=7145.0)
Today, I made that. Now I'm using only drawsprite commands, createscreen, usescreen, and finally only one stretchsprite to present graphics to real screen. In windows all ok. In Android, simply doesn't work. When I start the level, I get only a full black screen. I press the top-right corner, where I know the exit button should be, and I go back to inicial menu...
So, I can't see graphics, neither conclude if now the buttons are responsive...
Are you using a generic Chinese device ?
One thing that will be worth trying is https://play.google.com/store/apps/details?id=com.unmap.test3dspeed&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS51bm1hcC50ZXN0M2RzcGVlZCJd (my 3D speed tester)
There should be no control problems (at least until you start using models with lots of vertices - but thats the whole point of the program).
I had no control problems with your program. However, the characters sprite does seem to move strangely...
Quote from: MrTAToad on 2012-Jul-26
I had no control problems with your program. However, the characters sprite does seem to move strangely...
If you refer to character moving up and down, it is right. I made that as simple and stupid animation, I think it is better than be parked...
replace all the sprite commands with polyvector.
i did this in my games and got a decent speed increase.
Quote from: quangdx on 2012-Jul-31
replace all the sprite commands with polyvector.
i did this in my games and got a decent speed increase.
I did that and I don't see any improvement...
I conclude that GLBasic can't be used to make a decent game for Android. I will try another engine/language, maybe unity, or java itlsef...
Lots of other people have managed it! However, it does depend on the device - some are better than others. If a device is slow, there isn't much you can do about it.
You must be doing something wrong somewhere.
It runs terrible on my ZTE Blade, but Wapus's PowFish runs fine
http://www.youtube.com/watch?v=sypniIfZ5II&feature=player_embedded#!
and Minion's Earth Invasion runs fine and he's got 50 aliens moving about on screen
with fancy explosions.
There has to be an major bottleneck somewhere. Just has to be. To find out where it is you could use timers or the GLBasic's app profiling feature to discover where things get real slow. Once that is established you won't have to make guesses about what the problem could be. You'll know. Much easier to fix.
Fun game btw.
Quote from: Wampus on 2012-Aug-02
There has to be an major bottleneck somewhere. Just has to be. To find out where it is you could use timers or the GLBasic's app profiling feature to discover where things get real slow. Once that is established you won't have to make guesses about what the problem could be. You'll know. Much easier to fix.
Fun game btw.
FINALLY I FIXED IT!!!
The problem is in drawing the walls ouline. Not the drawing process itself (I think), but the lot of condition test I use to know where to draw the line.
The outline is not necessary at all, so I removed this part, and now the buttons are responsive and the character move as it should do.
Check it again (kwirk FREE): https://play.google.com/store/apps/developer?id=GALIKSOFT
For people who had reported control and move problems, please test it now again.
I uploaded the new package (version 1.5) and I'm waiting right now for the refresh. If it is not version 1.5, do not install yet.
Yeah, running fine here now.