Last Updated On 2021-07-16
Version 8MinSDK 7Tutorial Video
A 'sprite' that can be placed on a
Canvas, where it can react to touches and drags, interact with other sprites (
Balls and other
ImageSprites) and the edge of the Canvas, and move according to its property values. Its appearance is that of the image specified in its
Picture property (unless its
Visible property is
To have an
ImageSprite move 10 pixels to the left every 1000 milliseconds (one second), for example, you would set the
Speed property to 10 [pixels], the
Interval property to 1000 [milliseconds], the
Heading property to 180 [degrees], and the
Enabled property to
True. A sprite whose
Rotates property is
True will rotate its image as the sprite's
Heading changes. Checking for collisions with a rotated sprite currently checks the sprite's unrotated position so that collision checking will be inaccurate for tall narrow or short wide sprites that are rotated. Any of the sprite properties can be changed at any time under program control.
You can set the below properties in the UI part of the builder.
- Enabled - it's a boolean value which is set to true by default.
- Heading - it's a float value which is set to 0 by default.
- Interval - it's a non negative integer value which is set to 100 by default.
- Picture - it's a asset value which is set to blank by default.
- Rotates - it's a boolean value which is set to true by default.
- Speed - it's a float value which is set to 0.0 by default.
- Visible - it's a boolean value which is set to true by default.
- X - it's a float value which is set to 0.0 by default.
- Y - it's a float value which is set to 0.0 by default.
- Z - it's a float value which is set to 1.0 by default.
You can set the below blocks properties in the blocks section of the builder.
Controls whether the ImageSprite moves and can be interacted with through collisions, dragging, touching, and flinging.
Returns the ImageSprite's heading in degrees above the positive x-axis. Zero degrees is toward the right of the screen; 90 degrees is toward the top of the screen.
The height of the ImageSprite in pixels.
The interval in milliseconds at which the ImageSprite's position is updated. For example, if the interval is 50 and the speed is 10, then every 50 milliseconds the sprite will move 10 pixels in the heading direction.
The picture that determines the ImageSprite's appearance.
Whether the image should rotate to match the ImageSprite's heading. The sprite rotates around its centerpoint.
The number of pixels that the ImageSprite should move every interval, if enabled.
Whether the ImageSprite is visible.
The width of the ImageSprite in pixels.
The horizontal coordinate of the left edge of the ImageSprite, increasing as the ImageSprite moves right.
The vertical coordinate of the top edge of the ImageSprite, increasing as the ImageSprite moves down.
How the `ImageSprite` should be layered relative to other
You can set the below method blocks in the blocks section of the builder.
Makes the ImageSprite bounce, as if off a wall. For normal bouncing, the edge argument should be the one returned by EdgeReached.
Indicates whether a collision has been registered between this ImageSprite and the passed sprite (Ball or ImageSprite).
Moves the ImageSprite back in bounds if part of it extends out of bounds, having no effect otherwise. If the ImageSprite is too wide to fit on the canvas, this aligns the left side of the ImageSprite with the left side of the canvas. If the ImageSprite is too tall to fit on the canvas, this aligns the top side of the ImageSprite with the top side of the canvas.
Moves the ImageSprite so that its left top corner is at the specified x and y coordinates.
Sets the heading of the ImageSprite toward the point with the coordinates (x, y).
Turns the ImageSprite to point towards a designated target sprite (Ball or ImageSprite). The new heading will be parallel to the line joining the centerpoints of the two sprites.
You can set the below event blocks in the blocks section of the builder.
Event handler called when two enabled sprites (
Event handler called when a ImageSprite is dragged. On all calls, the starting coordinates are where the screen was first touched, and the "current" coordinates describe the endpoint of the current line segment. On the first call within a given drag, the "previous" coordinates are the same as the starting coordinates; subsequently, they are the "current" coordinates from the prior call. Note that the ImageSprite won't actually move anywhere in response to the Dragged event unless MoveTo is explicitly called. For smooth movement, each of its coordinates should be set to the sum of its initial value and the difference between its current and previous values.
Event handler called when the ImageSprite reaches an edge of the screen. If Bounce is then called with that edge, the ImageSprite will appear to bounce off of the edge it reached. Edge here is represented as an integer that indicates one of eight directions north (1), northeast (2), east (3), southeast (4), south (-1), southwest (-2), west (-3), and northwest (-4).
Event handler called when a fling gesture (quick swipe) is made on an enabled ImageSprite. This provides the x and y coordinates of the start of the fling (relative to the upper left of the canvas), the speed (pixels per millisecond), the heading (0-360 degrees), and the x and y velocity components of the fling's vector.
Event handler called when a pair of sprites (Balls and ImageSprites) are no longer colliding.
Event handler called when the user begins touching an enabled ImageSprite (placing their finger on a ImageSprite and leaving it there). This provides the x and y coordinates of the touch, relative to the upper left of the canvas.
Event handler called when the user stops touching an enabled ImageSprite (lifting their finger after a TouchDown event). This provides the x and y coordinates of the touch, relative to the upper left of the canvas.
Event handler called when the user touches an enabled ImageSprite and then immediately lifts their finger. The provided x and y coordinates are relative to the upper left of the canvas.