2013-06-20 105 views
0

我正在使用easeljs javascript来制作某种游戏。 我用这个例子:http://www.createjs.com/#!/EaselJS/demos/game图形BitMapFill类型错误

正如你可以看到有spacerocks。这是图形对象:

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

我想填充背景,像这样的图像:

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

但我总是得到这样的错误:

Uncaught TypeError: Type error

enter image description here

有人知道我做错了什么吗?

回答

2

使用对HTML图像的引用而不是Bitmap实例。

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

请注意,您必须确保加载图像,否则可能无法在第一阶段更新显示。您可以勾选舞台,或者听取图像,然后刷新舞台。

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