Difference between revisions of "Sprite"

From MiniScript Wiki
Jump to navigation Jump to search
m (Fixing)
 
(3 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 ===
+
== 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>.
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! Method or Property !! Purpose
+
! Method or Property !! Purpose !! Type
 +
|-
 +
| colspan=3 style="text-align: center;" | '''Edit and read'''
 +
|-
 +
| [[Sprite.image]] || image displayed  by the sprite || [[Image]]
 +
|-
 +
| [[Sprite.x]] || horizontal position of the sprite || number
 +
|-
 +
| [[Sprite.y]] || vertical position of the sprite || number
 +
|-
 +
| [[Sprite.scale]] || sprite scale (default 1.0) || number
 
|-
 
|-
| [[Sprite.image]] || image displayed by the sprite
+
| [[Sprite.rotation]] || sprite rotation (degrees counter-clockwise) || number
 
|-
 
|-
| [[Sprite.x]] || horizontal position of the sprite
+
| [[Sprite.tint]] || tint color (defaults to white) || string (color)
 
|-
 
|-
| [[Sprite.y]] || vertical position of the sprite
+
| [[Sprite.localBounds]] || stores the local bounds of the sprite || [[Bounds]]
 
|-
 
|-
| [[Sprite.scale]] || sprite scale (default 1.0)
+
| colspan=3 style="text-align: center;" | '''Read only'''
 
|-
 
|-
| [[Sprite.rotation]] || sprite rotation (degrees counter-clockwise)
 
 
|-
 
|-
| [[Sprite.tint]] || tint color (defaults to white)
+
| [[Sprite.worldBounds]] || computes world bounds from local bounds and current position || pare of numbers
 
|-
 
|-
| [[Sprite.localBounds]] || stores the local bounds of the sprite
+
| [[Sprite.contains]](''x'', ''y'') || return whether the sprite contains the given world point || bool
 
|-
 
|-
| [[Sprite.worldBounds]] || computes world bounds from local bounds and current position
+
| [[Sprite.overlaps]](''other'') || return whether this sprite is touching another sprite or [[Bounds]] || bool
 
|-
 
|-
| [[Sprite.contains]](''x'', ''y'') || return whether the sprite contains the given world point
+
| [[Sprite.corners]] || return <c>[x,y]</c> screen positions of the four corners of this sprite, counter-clockwise from bottom left || 4 pares of numbers
 
|-
 
|-
| [[Sprite.overlaps]](''other'') || return whether this sprite is touching another sprite or [[Bounds]]
+
| colspan=3  style="text-align: center;"| '''Run'''
 
|-
 
|-
| [[Sprite.corners]] || return <c>[x,y]</c> screen positions of the four corners of this sprite, counter-clockwise from bottom left
 
 
|-
 
|-
 
| [[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)

Latest revision as of 17:19, 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.

Methods and properties used with Sprite objects

Use these methods on Sprite instances, created with new Sprite.

Method or Property Purpose Type
Edit and read
Sprite.image image displayed by the sprite Image
Sprite.x horizontal position of the sprite number
Sprite.y vertical position of the sprite number
Sprite.scale sprite scale (default 1.0) number
Sprite.rotation sprite rotation (degrees counter-clockwise) number
Sprite.tint tint color (defaults to white) string (color)
Sprite.localBounds stores the local bounds of the sprite Bounds
Read only
Sprite.worldBounds computes world bounds from local bounds and current position pare of numbers
Sprite.contains(x, y) return whether the sprite contains the given world point bool
Sprite.overlaps(other) return whether this sprite is touching another sprite or Bounds bool
Sprite.corners return [x,y] screen positions of the four corners of this sprite, counter-clockwise from bottom left 4 pares of numbers
Run
Sprite.setCorners corners set new screen positions for the four sprite corners (counter-clockwise from bottom left)

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

See also