Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

Crafty wont display in Electron

Open ExperiBass opened this issue 5 years ago • 6 comments

Hello again :wave: I have a issue with running crafty without Beefy+Browserify. I need my game to run in Electron, and the only issue i have right now is that i cant figure out how to run the game in a html page. Heres my code+markup:

// Relevant code
Crafty.scene('main', function() {
  Crafty.init(500,500, document.getElementById('game'));
// rest of 'main' here...
}
window.onload = function() {
Crafty.scene('main') 
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Overtime-game</title>
  </head>
  <body>
    <div id="game"></div>
    <script type='text/javascript' src='./node_modules/craftyjs/dist/crafty.js'></script>
    <script src='./Level1.js'></script>
  </body>
</html>

ExperiBass avatar Dec 17 '18 17:12 ExperiBass

Hi @GingkathFox, what error do you get? :)

kevinsimper avatar Dec 18 '18 17:12 kevinsimper

@kevinsimper TypeError, Crafty.scene is not a function

ExperiBass avatar Dec 18 '18 18:12 ExperiBass

Uncaught TypeError: Crafty.scene is not a function
at Level1.js:4

ExperiBass avatar Dec 18 '18 18:12 ExperiBass

Looks like either the code is not loaded, as the code for scene is correct. Can you create a codepen that shows the error, I can't sadly help you without having all the code available.

You can see the actual code Crafty.scene is https://github.com/craftyjs/Crafty/blob/develop/src/core/scenes.js

kevinsimper avatar Dec 19 '18 01:12 kevinsimper

@kevinsimper Does Codepen use Electron? My game runs fine using Beefy. EDIT: youll have to uncomment the document.getElementById('game'), its on line 7.

ExperiBass avatar Dec 19 '18 23:12 ExperiBass

Heres the zip of the files used by Electron: Archive.zip Do i need to include the package.json?

ExperiBass avatar Dec 19 '18 23:12 ExperiBass