set Image

Set a new image for the sprite.

mySpritesetimage to
JavaScript
(method) Sprite.setImage(img: Image): void;
Python
(method) Sprite.set_image(img: Image): None

The image currently set for the sprite is replaced by the new image. The new image is displayed for the sprite.

Parameters

  • img: image that is the currently set for the sprite.

Example

Make two square block images, one with green pixels, the other with orange pixels. Every second, set the green or the orange image to the sprite on the screen.

1000togglemySpriteimage1setimage tomySpriteimage2setimage totogglenotsettoggletoifthenelseon game update everyms3232create image widthheightimage1cloneimage1image2image10spriteof kindsetmySpritetofillwithfillwithsetimage2tosetimage1toon start

See also

image