craftyjs.github.com

Image

Draw an image with or without repeating (tiling).

Back to top

.image

Events

Change
when the image is loaded

public this .image(String url[, String repeat])

url
URL of the image
repeat
If the image should be repeated to fill the entity.

Draw specified image. Repeat follows CSS syntax ("no-repeat", "repeat", "repeat-x", "repeat-y");

Note: Default repeat is no-repeat which is different to standard DOM (which is repeat)

If the width and height are 0 and repeat is set to no-repeat the width and height will automatically assume that of the image. This is an easy way to create an image without needing sprites.

Example

Will default to no-repeat. Entity width and height will be set to the images width and height

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

Create a repeating background.

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

See Also