Relative Content

Tag Archive for javascriptcanvas

Adding a playerMove function in JS game. “keyDown” input and method not working

First question here. Im trying to create a small game and i have my character object containing some attributes as well as functions. When trying to implement a playerMove function to get my rectangle to move, i’m getting the “playerMove” is not defined error from the addEventlistener call to the function. What am I doing wrong here?
Is my way of thinking even possible? Should the eventlistener be in the main game file and pass the event to the character function instead?

Is createImageBitmap made obsolete by OffscreenCanvas?

I was attempting to use createImageBitmap to resize image elements into an ImageBitmap and was not satisfied with the results. Despite having an asynchronous interface, it seems (on Chrome at least) to tie up the main thread, leading to frame times being exceeded. Meanwhile, OffscreenCanvas can also be used to resize image elements into an ImageBitmap, and with a synchronous API. Despite that, it seems to be tying up my main thread less than createImageBitmap. I found some bug reports for Chromium pertaining to createImageBitmap performance which have been open for years with no progress. Is it recommended to just use OffscreenCanvas from now on?