Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix preloaded assets not showing on canvas in createjs?

I'm trying to create an animation by setting a background to a canvas and then trying to move my assets over the background image. I'm able to display the background image in the canvas and also able to preload all my assets. However, I'm not able to display any of the assets on the canvas.

I tried to play around with the coordinates of the bitmap I'm trying to display in case if it's displaying outside the visible area. I also tried to check if there is any problem with the timing of updating the stage, but no luck. Any help would be appreciated.

function set()
{
    var cgroup = new createjs.Container();

    cgroup.x = 100;
    cgroup.y = 100;


    // var path = 'img/cloud1.png';
    var img = preload.getResult("c1");
    console.log(img.src);  //displaying correct preloaded file
    var cloud1 = new createjs.Bitmap(img);
    cgroup.addChild(cloud1);
    cloud1.x = 120;
    cloud1.y = 120;
    cloud1.regX = 62;
    cloud1.regY = 62;

    stage.addChild(cgroup);
    stage.update();
}
like image 284
Steve Tom Avatar asked Dec 09 '25 21:12

Steve Tom


1 Answers

You need to call the function to make it run. For instance, this would be for when the page loads.

window.onload() = function(){
  var cgroup = new createjs.Container();

  cgroup.x = 100;
  cgroup.y = 100;

  // var path = 'img/cloud1.png';
  var img = preload.getResult("c1");
  console.log(img.src); //displaying correct preloaded file
  var cloud1 = new createjs.Bitmap(img);
  cgroup.addChild(cloud1);
  cloud1.x = 120;
  cloud1.y = 120;
  cloud1.regX = 62;
  cloud1.regY = 62;

  stage.addChild(cgroup);
  stage.update();
};
like image 160
Yoko Ishioka Avatar answered Dec 12 '25 10:12

Yoko Ishioka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!