iOS Question how to make a game via canvas?

ilan

Expert
Licensed User
Longtime User
hi

i tried to make a game just using a canvas but it seems like it is impossible.
when i draw 2 bitmaps to the canvas i already get a fps of 25-27
(bitmaps size are very low! less then 1kb)

drawing 10 bitmaps will get me 5 fps (RELEASE MODE)

is there a way to turn on hardware acceleration?

i really would like to understand how he did it: https://www.b4x.com/android/forum/threads/pitch-up-game-approved.59382/#post-374125

such a smooth game only via canvas?? how??
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
upload_2016-8-31_9-33-7.png


I did some tests. On iPhone 5s it looks good with 40 circles or 15 bitmaps. Tested in Release mode.
 

Attachments

  • Smilies.zip
    6.9 KB · Views: 290
Upvote 0

ilan

Expert
Licensed User
Longtime User
indeed your example runs well. with canvas drawing (no bitmaps) you get very easily 60 fps. when you switch to smiley (40 bmp) it goes down. but this is still not so bad. you get about 40 fps

but when i draw only 2 bitmaps (background + a turning object) i get already 27-30fps and from here i cannot do anything more. drawing another 2-3 bmp i get maybe 10 fps.

do you know what is the factor that makes my example run on a low fps? is it maybe the png files?
i am using only 2 bmps and get down to 27-30fps

thank you very much for your support :)
 

Attachments

  • Smilies.zip
    19.6 KB · Views: 253
Upvote 0

sorex

Expert
Licensed User
Longtime User
I mentioned it before but couldn't find the post.

bitmap operations are a lot slower on IOS than Android.

In my first IOS port I noticed this when I tried to use the same sprite sheet method as the android version was using.

This was slow as hell so the only option I had to increase the speed was using seperate(d) images loaded into imageviews.

And this was just an initial spritesheet to image code that happend once at startup, not even in the gameloop.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
1. Don't draw the background each cycle. Use a background ImageView instead.
2. Use an ImageView for the moon and call RotateView to rotate it: https://www.b4x.com/android/forum/threads/animations.46156/#post-338075

After these changes it runs in 60fps.

ok, i understand what you mean erel. so you recommend to use views and not draw everything to the canvas.
when i created Mr. Bucket (2 years ago) i did it the same way. i tried first using canvas but get very bad performance so i switched to views.
but i dont understand why it is like this.

i could use ispritekit for that game but it should be a very simple game so i thought i would do it via canvas. it would be great if we could create
games only via canvas and get good performance. i dont expect 60 fps but at least 40.

anyway thank you for taking time and create those project for us so we can understand better. it is very much appreciated. :)

i will use the View-technique for my game and leave canvas until someone create something similar to Accelerated surface like we have on android where we
can use simple tools like canvas and still get great performance.

thanx a lot, ilan
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
haha, its going well until now. need to add more obstacles and menu + sound ... (soon will be finished)

i am using only views and for now i draw the dust via canvas (when the guy is running) and still everything is in 60fps :):):)

 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
After some more tests, there is no doubt that it is best to use ImageViews as sprites. With ImageViews you can show 100+ bitmaps and it is all very fast.

Yes this is indeed the right way for ios.
Trying your canvas example on imageview did improove a little the performance but still if u start drawing a lot bitmaps and need to do physics calculation and collisions calc it will get very slow. But using only views without canvas i still get 60 fps and i am already doing a lot in the timer tick event. ';)
 
Last edited:
Upvote 0
Top