playcanvas/engine

game-pads.js allocates a new array every frame

Open

#842 opened on 2017年2月3日

GitHub で見る
 (2 comments) (0 reactions) (0 assignees)JavaScript (8,878 stars) (1,325 forks)batch import
area: inputenhancementgood first issue

説明

        update: function (dt) {
            var pads = this.poll();

            var i, len = pads.length;
            for (i = 0;i < len; i++) {
                this.previous[i] = this.current[i];
                this.current[i] = pads[i];
            }
        },
        poll: function () {
            var pads = [];
            if (this.gamepadsSupported) {
                var padDevices = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();
                var i, len = padDevices.length;
                for (i = 0; i < len; i++) {
                    if (padDevices[i]) {
                        pads.push({
                            map: this.getMap(padDevices[i]),
                            pad: padDevices[i]
                        });
                    }
                }
            }
            return pads;
        },

When poll() gets called, it allocates a new array to store the current gamepad state.

コントリビューターガイド