Difference between revisions of "Sprite"
Line 1: | Line 1: | ||
<c>Sprite</c> is a built-in class in the [[Mini Micro]] API. It represents an image which can be added to a [[SpriteDisplay]], enabling it to be drawn to the screen very efficiently while also being scaled, rotated, or tinted, and layered consistently with other sprites and the surrounding displays. | <c>Sprite</c> is a built-in class in the [[Mini Micro]] API. It represents an image which can be added to a [[SpriteDisplay]], enabling it to be drawn to the screen very efficiently while also being scaled, rotated, or tinted, and layered consistently with other sprites and the surrounding displays. | ||
− | + | == Methods and properties used with Sprite objects == | |
Use these methods on Sprite instances, created with <c>[[new]] Sprite</c>. | Use these methods on Sprite instances, created with <c>[[new]] Sprite</c>. | ||
+ | === Edit and Read === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | ! Method or Property !! Purpose | + | ! Method or Property !! Purpose !! Value |
|- | |- | ||
− | | [[Sprite.image]] || image displayed by the sprite | + | | [[Sprite.image]] || image displayed by the sprite || Input: image |
+ | Output: image | ||
|- | |- | ||
− | | [[Sprite.x]] || horizontal position of the sprite | + | | [[Sprite.x]] || horizontal position of the sprite || Input: number |
+ | Output: number | ||
|- | |- | ||
− | | [[Sprite.y]] || vertical position of the sprite | + | | [[Sprite.y]] || vertical position of the sprite || Input: number |
+ | Output: number | ||
|- | |- | ||
− | | [[Sprite.scale]] || sprite scale (default 1.0) | + | | [[Sprite.scale]] || sprite scale (default 1.0) || Input: number |
+ | Output: number | ||
+ | |||
+ | |- | ||
+ | | [[Sprite.rotation]] || sprite rotation (degrees counter-clockwise) || Input: number | ||
+ | Output: number | ||
+ | |- | ||
+ | | [[Sprite.tint]] || tint color (defaults to white) || Input: color | ||
+ | Output: color | ||
|- | |- | ||
− | | [[Sprite. | + | | [[Sprite.localBounds]] || stores the local bounds of the sprite || Input: [[Bounds]] |
+ | Output: [[Bounds]] | ||
|- | |- | ||
− | | | + | |} |
+ | === Read only === | ||
+ | {| class="wikitable" | ||
|- | |- | ||
− | + | ! Method or Property !! Purpose !! Value | |
|- | |- | ||
− | | [[Sprite.worldBounds]] || computes world bounds from local bounds and current position | + | | [[Sprite.worldBounds]] || computes world bounds from local bounds and current position || Input: NULL |
+ | Output: pare of numbers | ||
|- | |- | ||
− | | [[Sprite.contains]](''x'', ''y'') || return whether the sprite contains the given world point | + | | [[Sprite.contains]](''x'', ''y'') || return whether the sprite contains the given world point || Input: x: number; y: number |
+ | Output: true/false | ||
|- | |- | ||
− | | [[Sprite.overlaps]](''other'') || return whether this sprite is touching another sprite or [[Bounds]] | + | | [[Sprite.overlaps]](''other'') || return whether this sprite is touching another sprite or [[Bounds]] || Input: [[Sprite]] |
+ | Output: true/false | ||
+ | |- | ||
+ | | [[Sprite.corners]] || return <c>[x,y]</c> screen positions of the four corners of this sprite, counter-clockwise from bottom left || Input: NULL | ||
+ | Output: 4 pares of numbers | ||
+ | |- | ||
+ | |} | ||
+ | === Run === | ||
+ | {| class="wikitable" | ||
|- | |- | ||
− | + | ! Method or Property !! Purpose !! Value | |
|- | |- | ||
− | | [[Sprite.setCorners]] ''corners''|| set new screen positions for the four sprite corners (counter-clockwise from bottom left) | + | | [[Sprite.setCorners]] ''corners''|| set new screen positions for the four sprite corners (counter-clockwise from bottom left) || Input: 4 pares of numbers |
|- | |- | ||
|} | |} |
Revision as of 11:26, 29 January 2025
Sprite
is a built-in class in the Mini Micro API. It represents an image which can be added to a SpriteDisplay, enabling it to be drawn to the screen very efficiently while also being scaled, rotated, or tinted, and layered consistently with other sprites and the surrounding displays.
Contents
Methods and properties used with Sprite objects
Use these methods on Sprite instances, created with new Sprite
.
Edit and Read
Method or Property | Purpose | Value |
---|---|---|
Sprite.image | image displayed by the sprite | Input: image
Output: image |
Sprite.x | horizontal position of the sprite | Input: number
Output: number |
Sprite.y | vertical position of the sprite | Input: number
Output: number |
Sprite.scale | sprite scale (default 1.0) | Input: number
Output: number |
Sprite.rotation | sprite rotation (degrees counter-clockwise) | Input: number
Output: number |
Sprite.tint | tint color (defaults to white) | Input: color
Output: color |
Sprite.localBounds | stores the local bounds of the sprite | Input: Bounds
Output: Bounds |
Read only
Method or Property | Purpose | Value |
---|---|---|
Sprite.worldBounds | computes world bounds from local bounds and current position | Input: NULL
Output: pare of numbers |
Sprite.contains(x, y) | return whether the sprite contains the given world point | Input: x: number; y: number
Output: true/false |
Sprite.overlaps(other) | return whether this sprite is touching another sprite or Bounds | Input: Sprite
Output: true/false |
Sprite.corners | return [x,y] screen positions of the four corners of this sprite, counter-clockwise from bottom left |
Input: NULL
Output: 4 pares of numbers |
Run
Method or Property | Purpose | Value |
---|---|---|
Sprite.setCorners corners | set new screen positions for the four sprite corners (counter-clockwise from bottom left) | Input: 4 pares of numbers |
Usage Notes (Soda)
In Soda there is currently only one, implicit, Display. So to add sprites to this display, push them onto a global list called sprites
.
Soda does not currently support Sprite.corners or Sprite.setCorners.
Example
This example creates a sprite, loads it into display 4 (which by default is a SpriteDisplay), and rotates it through 360 degrees.
spr = new Sprite
spr.image = file.loadImage("/sys/pics/Wumpus.png")
display(4).sprites.push spr
spr.x = 480
spr.y = 320
for r in range(0,360)
spr.rotation = r
yield
end for