Hello, I have a Drawing Canvas in my scene where I draw lines that I want to get the pixel data from. I use the following code to get the pixel data from two canvases:
// Load the pixels of the player Drawing Canvas asyncronously and then proceed to load the computer Drawing Canvas pixel data function loadPlayerData(playerImage, computerImage) { playerImage.getImagePixelData().then(playerData=>loadComputerData (playerData,computerImage)); } function loadComputerData (playerData, computerImage) { computerImage.getImagePixelData().then (computerData=>compare(playerData, computerData)); }
The data returned is the correct length but no matter what I draw on the player canvas it's filled with zeros. Am i doing something wrong here? The computer canvas seems to work just fine and I'm pasting a sprite on it.
Develop games in your browser. Powerful, performant & highly capable.
You need 'await' in front.
await sdk.GetImagePixelData().then(a=>
No, you should not mix await and .then - you should choose one or the other (and await is much more convenient).
await
.then
It's hard to say more from such a small code snippet, it should just work. As always sharing a project is easier to help.