Search code examples
javascriptcanvascraftyjs

How can I render a Crafty JS canvas into a div I created in HTML?


I'm new to CraftyJS and was wondering if anybody has had this problem.

I want a game canvas that is located inside a div. I was wondering how to do this.

Crafty.init({...})
Crafty.canvas();

Doesn't give me the desired results.

It simply puts the canvas at the bottom of the page.


Solution

  • Just set the id of the div to "cr-stage". That should do the trick.

    Oh, and welcome to the Crafty community. Hope you enjoy it :-)

    btw. I only stumble upon Crafty questions on SO by chance. If you want to be sure to get an answer you should use our google group https://groups.google.com/forum/?fromgroups#!forum/craftyjs

    bbtw. It looks like you are using an older version of Crafty (We have changed the canvas initialization to Crafty.canvas.init()) I would advise you to upgrade before you continue with your game. There are a few breaking changes, ask in the forum.