0

I'm creating a game.

There is a profile. The user has an opportunity to change the place of elements with each other.

When the user does that, the keys of images must be changed between each other too.

And here is the problem: I can't do that at all

Here is the code I'm trying to use:

var loader = new Phaser.Loader(game);
loader.image(draggableElement.key, 'path to lying element', true);
loader.image(lyingElement.key, 'path to dragged element', true);
loader.onLoadComplete.add(doSmthq);
loader.start();

there is an error

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'

Thank you in advance! I will really appreciate that =)

vanntile
  • 2,727
  • 4
  • 26
  • 48
weratius
  • 113
  • 1
  • 12
  • Are you sure the draggableElement object is available on the moment the loader starts? Add "debugger;" before the first "loader.image" line and run it again to see what is the value of draggableElement.key at that point. – BdR Jul 05 '15 at 19:34
  • @BdR The value of draggableElement.key is the key of my uploaded image. That's ok. It is 'w5' – weratius Jul 05 '15 at 20:27
  • please write the path to the image including its format ? – Sky Walker Jul 05 '15 at 20:33
  • @skywalker 'img/profile/res/' + playerInfoObject[lyingElementKey].id + '.png?v=9' and 'img/profile/res/' + playerInfoObject[draggableElementKey].id + '.png?v=10' – weratius Jul 05 '15 at 21:30
  • i think you need link like dir/image.png because this link like browser request not image object try to host image on server or use it locally – Sky Walker Jul 06 '15 at 09:42
  • @skywalker that didn't help (I've just tried to use random images from my directory) – weratius Jul 06 '15 at 10:48
  • Have you tried using the state's `preload()` function? If not, try the following: `preload : function() { this.game.load.image('imageKey', 'path/to/image.png'); }` This also invokes Phaser.Loader (but I don't think it's a good idea to invoke it explicitly like you do) and, being in `preload`, is guaranteed to run before everything else you do in `create`. – Kamen Minkov Jul 07 '15 at 07:38

0 Answers0