getImagePixelData returns an array filled with zeros

0 favourites
  • 3 posts
From the Asset Store
Platform HTML5 game, where the little Dinosaur must cross the forest, desert and snow forest.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)