Graphics BitMapFill TypeError

我是研究僧i 提交于 2020-01-03 05:21:09

问题


I'm working with the easeljs javascript to make a sort of game. I'm using this example: http://www.createjs.com/#!/EaselJS/demos/game

As you can see there are spacerocks. This are graphics objects:

this.graphics.beginStroke("#FFFFFF");

I would like to fill the background with an image like this:

var bitmap = new createjs.Bitmap("http://nielsvroman.be/twitter/root/easeljs/image.png");
this.graphics.beginBitmapFill(bitmap, "no-repeat"); 

But I always get this error:

Uncaught TypeError: Type error

Does anybody know what I'm doing wrong?


回答1:


Use a reference to an HTML Image, and not a Bitmap instance.

var image = new Image();
image.srce = "http://nielsvroman.be/twitter/root/easeljs/image.png";
this.graphics.beginBitmapFill(image, "no-repeat"); 

Note that you have to ensure the image is loaded, otherwise it may not show up on the first stage update. You can either tick the stage, or listen for image onload, and refresh the stage then.

image.onload = function() {
    stage.update();
}


来源:https://stackoverflow.com/questions/17221853/graphics-bitmapfill-typeerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!