Image 组件

绘制重复或不重复的图像(平铺)。

方法

Back to top

.image()

事件

Invalidate
当图像加载完毕时触发
public this .image(String url[, String repeat])
url

图像的URL

repeat

If the image should be repeated to fill the entity. This follows CSS syntax: ("no-repeat", "repeat", "repeat-x", "repeat-y"), but defaults to no-repeat.

绘制一个指定的图像。

注意:repeat 的默认值为 no-repeat, 这和标准的CSS默认值不同。

如果宽度和高度为0,repeat 设置为 no-repeat,宽度和高度将自动地设置为图像的宽度和高度。这是创建一个图像,而不需要精灵的一个简单的方法。

如果设置为no-repeat并且给定的尺寸比图像尺寸大,准确的外观取决于渲染器(WebGL, DOM, or Canvas)。

例子

默认不重复。实体宽度和高度将被设置为图像的宽度和高度。

var ent = Crafty.e("2D, DOM, Image").image("myimage.png");

创建一个重复的背景

var bg = Crafty.e("2D, DOM, Image")
             .attr({w: Crafty.viewport.width, h: Crafty.viewport.height})
             .image("bg.png", "repeat");