Difference between revisions of "Sprite"
Jump to navigation
Jump to search
(Created page with "<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 effi...") |
|||
(4 intermediate revisions by the same user not shown) | |||
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>. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Method or Property !! Purpose | ||
+ | |- | ||
+ | | [[Sprite.image]] || image displayed by the sprite | ||
+ | |- | ||
+ | | [[Sprite.x]] || horizontal position of the sprite | ||
+ | |- | ||
+ | | [[Sprite.y]] || vertical position of the sprite | ||
+ | |- | ||
+ | | [[Sprite.scale]] || sprite scale (default 1.0) | ||
+ | |- | ||
+ | | [[Sprite.rotation]] || sprite rotation (degrees counter-clockwise) | ||
+ | |- | ||
+ | | [[Sprite.tint]] || tint color (defaults to white) | ||
+ | |- | ||
+ | | [[Sprite.localBounds]] || stores the local bounds of the sprite | ||
+ | |- | ||
+ | | [[Sprite.worldBounds]] || computes world bounds from local bounds and current position | ||
+ | |- | ||
+ | | [[Sprite.contains]](''x'', ''y'') || return whether the sprite contains the given world point | ||
+ | |- | ||
+ | | [[Sprite.overlaps]](''other'') || return whether this sprite is touching another sprite or [[Bounds]] | ||
+ | |- | ||
+ | |} | ||
== Example == | == Example == | ||
− | This example creates a sprite, loads it into display 4 (which by default is a [[SpriteDisplay]], and rotates it through 360 degrees. | + | This example creates a sprite, loads it into display 4 (which by default is a [[SpriteDisplay]]), and rotates it through 360 degrees. |
<ms>spr = new Sprite | <ms>spr = new Sprite | ||
Line 14: | Line 44: | ||
yield | yield | ||
end for</ms> | end for</ms> | ||
+ | |||
+ | [[Category: Mini Micro]] |
Revision as of 19:12, 12 April 2020
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.
Methods and properties used with Sprite objects
Use these methods on Sprite instances, created with new Sprite
.
Method or Property | Purpose |
---|---|
Sprite.image | image displayed by the sprite |
Sprite.x | horizontal position of the sprite |
Sprite.y | vertical position of the sprite |
Sprite.scale | sprite scale (default 1.0) |
Sprite.rotation | sprite rotation (degrees counter-clockwise) |
Sprite.tint | tint color (defaults to white) |
Sprite.localBounds | stores the local bounds of the sprite |
Sprite.worldBounds | computes world bounds from local bounds and current position |
Sprite.contains(x, y) | return whether the sprite contains the given world point |
Sprite.overlaps(other) | return whether this sprite is touching another sprite or Bounds |
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