2

This is my htmlcode:

<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <script src="http://code.createjs.com/easeljs-0.7.0.min.js"></script>
    <script src="Doge.js"></script>  
</head>

<body bgcolor="#C7C7C7" onload="Start();">
      <canvas id="DogeCanvas" width="480" height="320"></canvas>
</body>
</html>

And this is my Doge.js code:

function Start() {
      var stage = new createjs.Stage("DogeCanvas");
      var doge = new Image();
      doge.src = "images/doge.jpg"
      var bitmap = new createjs.Bitmap(doge);
      stage.addChild(bitmap);
      stage.update();
}

Why it doesn't show anything on the screen? What is wrong?

7
  • Does images/doge.jpg exist on the current path? Commented Dec 31, 2013 at 0:49
  • yes it does, i even tried to put it outside the folder and change to "doge.jpg" and the same result .. also. if i put a simple "alert("hello")" in the function it shows perfectly ... Commented Dec 31, 2013 at 1:02
  • Maybe you left it out of your snippet, but you're missing the doctype and the </html> part of the code. You should also using CSS to apply styling to elements rather than using things like "bgcolor" (this is HTML3). Commented Dec 31, 2013 at 2:14
  • Yes, the <!DOCTYPE html> is on the file but i didn't copy it to the question, also is the </html>. Commented Dec 31, 2013 at 2:35
  • 1
    possible duplicate of easeljs not showing bitmap Commented Dec 18, 2014 at 21:56

2 Answers 2

6

As stated above you cannot draw your image until you have loaded it. Try this:

<!DOCTYPE HTML>
<html>
    <title>Easel Test</title>
    <head>
    <script src="https://code.createjs.com/easeljs-0.8.0.min.js"></script>

    <script>
        var stage;

        function init() {
            stage = new createjs.Stage("myCanvas");

            var image = new Image();
            image.src = "path/image";
            image.onload = handleImageLoad;
        }

        function handleImageLoad(event) {
            var image = event.target;
            var bitmap = new createjs.Bitmap(image);
            stage.addChild(bitmap);
            stage.update();
        }


    </script>

    </head>
    <body onload="init();">
        <canvas id="myCanvas" width="960" height="580"></canvas>
    </body>

</html>
Sign up to request clarification or add additional context in comments.

Comments

5

The image is not loaded when the stage is updated. I posted an answer here:

» easeljs not showing bitmap

  1. You can add a Ticker to the stage to constantly update it (which most applications do, since there is other things changing over time)
  2. Listen for the onload of the image, and update the stage again
  3. Preload the image with something like PreloadJS before you draw it to the stage.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.