xronn Posted November 22, 2015 Share Posted November 22, 2015 Hi, I want to write my own javascript as part of my game, so I'm loading another js file such as menu.js and then inside that file I want to draw my own image to the canvas so I write the following code; var canvas = document.getElementById('canvas');var ctx = canvas.getContext('2d');var backpackBtn = new Image(); backpackBtn.onload = function() { ctx.drawImage(backpackBtn, 50, 630); }; backpackBtn.src = '././sprites/ui/item_btn.png';But phaser uses the canvas in webgl mode, and a canvas can't have both webgl and 2d, so can i make phaser use 2d so I can write my own javascript along side? Link to comment Share on other sites More sharing options...
tips4design Posted November 22, 2015 Share Posted November 22, 2015 Why don't you use Phaser to draw this image instead of manually calling the drawImage function on the context? Link to comment Share on other sites More sharing options...
xronn Posted November 22, 2015 Author Share Posted November 22, 2015 Yeah I suppose, but how can I call them from an external js file if I want to have say a userInterface.js I'll preload the images then in my game create I'll draw them but then how can I write my own js inside my userInterface.js file. I wouldn't have anyway of calling the ui sprites I've drawn on in the create? Link to comment Share on other sites More sharing options...
jmp909 Posted November 23, 2015 Share Posted November 23, 2015 How about create your UI as a group in UI.js, write your own (phaser) asset loader and dispatch a "complete" event signal back to your main class when everything is loaded. No need to break out of Phaser framework Link to comment Share on other sites More sharing options...
Recommended Posts