NativeScript / canvas

Apache License 2.0
88 stars 18 forks source link

Performance in 2d #78

Closed W84Soft closed 8 months ago

W84Soft commented 2 years ago

Hi, I'm new in NativeScript, I'm trying to port my 2d game engine to NativeScript Android app and I have some issues with performance. When I tried to add text with fps counter, my canvas is jumping between old draw and new draw (link with video down below). I tried older version nativescript/canvas and I saw that the performance is better, but when I minimize and open app my canvas is speeding up. My loop code looks like this, I have fps limiter maybe that's the problem, but in browser works very fine.


let raf=requestAnimationFrame;

        let fps={
            now:0,
            time:0,
            lap:0,
            update:0
        };

        let time=0;
        let speed=0;
        this.render=function(timestamp,max,update,render){
            let elapsed=timestamp-time;
            if(elapsed>1000/max){
                time=timestamp-(elapsed%(1000/max));
                render();
                let i=Date.now();
                fps.now=1000/(i-fps.time);
                fps.time=i;
                speed=Math.floor(max/fps.now*100)/100;
            }

            let elapsedFPS=timestamp-fps.update;
            if(elapsedFPS>=1000){
                fps.lap=fps.now;
                fps.update=timestamp;
            }
            raf(update)
        }

https://drive.google.com/file/d/16EXsUSlQ_3j7eNdx8JaW7ydjO2_L1awu/view?usp=sharing

Tested on version: 1.0.0 and 1.0.0-alpha.13 Android: 9 lineageos 16.0 on Xiaomi Redmi 4X 3/32gb @nativescript/core: 8.2.0 @nativescript/android: 8.2.2

EDIT: From version 1.0.0-alpha.18 function .fillText slowing down my app and from version 1.0.0-alpha.17 and down: after clicking back button and reopen couple of times, my app speeding up.

triniwiz commented 2 years ago

Thanks for the info , the interesting thing is I'm currently working on the next major update which aim's to improve the performance similar to the browser or better 🤞🏽 😁 🤞🏽

triniwiz commented 8 months ago

This has been resolved, please upgrade to the v2 beta