AI2 Component
(Version nb184)
|
Public Member Functions | |
void | Initialize () |
boolean | Enabled () |
void | Enabled (boolean enabled) |
double | Heading () |
void | Heading (double userHeading) |
int | Interval () |
void | Interval (int interval) |
void | Speed (float speed) |
float | Speed () |
boolean | Visible () |
void | Visible (boolean visible) |
double | X () |
void | X (double x) |
void | Y (double y) |
double | Y () |
void | Z (double layer) |
double | Z () |
void | CollidedWith (Sprite other) |
void | Dragged (float startX, float startY, float prevX, float prevY, float currentX, float currentY) |
void | EdgeReached (int edge) |
void | NoLongerCollidingWith (Sprite other) |
void | Touched (float x, float y) |
void | Flung (float x, float y, float speed, float heading, float xvel, float yvel) |
void | TouchUp (float x, float y) |
void | TouchDown (float x, float y) |
void | Bounce (int edge) |
boolean | CollidingWith (Sprite other) |
void | MoveIntoBounds () |
void | MoveTo (double x, double y) |
void | PointTowards (Sprite target) |
void | PointInDirection (double x, double y) |
BoundingBox | getBoundingBox (int border) |
boolean | intersectsWith (BoundingBox rect) |
boolean | containsPoint (double qx, double qy) |
void | alarm () |
HandlesEventDispatching | getDispatchDelegate () |
void | onDestroy () |
void | onDelete () |
Public Member Functions inherited from com.google.appinventor.components.runtime.VisibleComponent | |
abstract int | Width () |
abstract void | Width (int width) |
abstract void | WidthPercent (int wPercent) |
abstract int | Height () |
abstract void | Height (int height) |
abstract void | HeightPercent (int hPercent) |
Static Public Member Functions | |
static boolean | colliding (Sprite sprite1, Sprite sprite2) |
Protected Member Functions | |
Sprite (ComponentContainer container, Handler handler) | |
Sprite (ComponentContainer container) | |
void | OriginAtCenter (boolean b) |
void | postEvent (final Sprite sprite, final String eventName, final Object... args) |
void | registerChange () |
int | hitEdge () |
final void | moveIntoBounds (int canvasWidth, int canvasHeight) |
void | updateCoordinates () |
int | hitEdge (int canvasWidth, int canvasHeight) |
abstract void | onDraw (android.graphics.Canvas canvas) |
Protected Member Functions inherited from com.google.appinventor.components.runtime.VisibleComponent | |
VisibleComponent () | |
Protected Attributes | |
final Canvas | canvas |
boolean | initialized = false |
int | interval |
boolean | visible = true |
double | xLeft |
double | yTop |
double | zLayer |
float | speed |
boolean | originAtCenter |
double | xCenter |
double | yCenter |
Form | form |
double | userHeading |
double | heading |
double | headingRadians |
double | headingCos |
double | headingSin |
Static Protected Attributes | |
static final boolean | DEFAULT_ORIGIN_AT_CENTER = false |
Additional Inherited Members | |
Static Public Attributes inherited from com.google.appinventor.components.runtime.Component | |
static final String | ASSET_DIRECTORY = "component" |
static final int | ALIGNMENT_NORMAL = 0 |
static final int | ALIGNMENT_CENTER = 1 |
static final int | ALIGNMENT_OPPOSITE = 2 |
static final int | ACCELEROMETER_SENSITIVITY_WEAK = 1 |
static final int | ACCELEROMETER_SENSITIVITY_MODERATE = 2 |
static final int | ACCELEROMETER_SENSITIVITY_STRONG = 3 |
static final int | BUTTON_SHAPE_DEFAULT = 0 |
static final int | BUTTON_SHAPE_ROUNDED = 1 |
static final int | BUTTON_SHAPE_RECT = 2 |
static final int | BUTTON_SHAPE_OVAL = 3 |
static final int | COLOR_NONE = 0x00FFFFFF |
static final int | COLOR_BLACK = 0xFF000000 |
static final int | COLOR_BLUE = 0xFF0000FF |
static final int | COLOR_CYAN = 0xFF00FFFF |
static final int | COLOR_DKGRAY = 0xFF444444 |
static final int | COLOR_GRAY = 0xFF888888 |
static final int | COLOR_GREEN = 0xFF00FF00 |
static final int | COLOR_LTGRAY = 0xFFCCCCCC |
static final int | COLOR_MAGENTA = 0xFFFF00FF |
static final int | COLOR_ORANGE = 0xFFFFC800 |
static final int | COLOR_PINK = 0xFFFFAFAF |
static final int | COLOR_RED = 0xFFFF0000 |
static final int | COLOR_WHITE = 0xFFFFFFFF |
static final int | COLOR_YELLOW = 0xFFFFFF00 |
static final int | COLOR_DEFAULT = 0x00000000 |
static final String | DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF" |
static final String | DEFAULT_VALUE_COLOR_BLACK = "&HFF000000" |
static final String | DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF" |
static final String | DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF" |
static final String | DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444" |
static final String | DEFAULT_VALUE_COLOR_GRAY = "&HFF888888" |
static final String | DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00" |
static final String | DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC" |
static final String | DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF" |
static final String | DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800" |
static final String | DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF" |
static final String | DEFAULT_VALUE_COLOR_RED = "&HFFFF0000" |
static final String | DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF" |
static final String | DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00" |
static final String | DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000" |
static final float | FONT_DEFAULT_SIZE = 14 |
static final int | LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL |
static final int | LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL |
static final int | SCALING_SCALE_PROPORTIONALLY = 0 |
static final int | SCALING_SCALE_TO_FIT = 1 |
static final int | TYPEFACE_DEFAULT = 0 |
static final int | TYPEFACE_SANSSERIF = 1 |
static final int | TYPEFACE_SERIF = 2 |
static final int | TYPEFACE_MONOSPACE = 3 |
static final int | LENGTH_PREFERRED = -1 |
static final int | LENGTH_FILL_PARENT = -2 |
static final int | LENGTH_UNKNOWN = -3 |
static final int | LENGTH_PERCENT_TAG = -1000 |
static final int | TOAST_LENGTH_SHORT = 0 |
static final int | TOAST_LENGTH_LONG = 1 |
static final int | DIRECTION_NORTH = 1 |
static final int | DIRECTION_NORTHEAST = 2 |
static final int | DIRECTION_EAST = 3 |
static final int | DIRECTION_SOUTHEAST = 4 |
static final int | DIRECTION_SOUTH = -1 |
static final int | DIRECTION_SOUTHWEST = -2 |
static final int | DIRECTION_WEST = -3 |
static final int | DIRECTION_NORTHWEST = -4 |
static final int | DIRECTION_NONE = 0 |
static final int | DIRECTION_MIN = -4 |
static final int | DIRECTION_MAX = 4 |
static float | SLIDER_MIN_VALUE = 10 |
static float | SLIDER_MAX_VALUE = 50 |
static float | SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f |
static final String | DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = "" |
static final String | DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = "" |
Superclass of sprites able to move and interact with other sprites.
While the Simple programmer sees the x- and y-coordinates as integers, they are maintained internally as doubles so fractional changes (caused by multiplying the speed by a cosine or sine value) have the chance to add up.
Definition at line 37 of file Sprite.java.
|
protected |
Creates a new Sprite component. This version exists to allow injection of a mock handler for testing.
container | where the component will be placed |
handler | a scheduler to which runnable events will be posted |
Definition at line 103 of file Sprite.java.
|
protected |
Creates a new Sprite component. This is called by the constructors of concrete subclasses, such as Ball and ImageSprite.
container | where the component will be placed |
Definition at line 140 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.alarm | ( | ) |
Moves and redraws sprite, registering changes.
Implements com.google.appinventor.components.runtime.AlarmHandler.
Definition at line 990 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Bounce | ( | int | edge | ) |
Makes this type%
bounce, as if off a wall. For normal bouncing, the edge
argument should be the one returned by EdgeReached.
Definition at line 610 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.CollidedWith | ( | Sprite | other | ) |
Event handler called when two enabled sprites (Balls or ImageSprites) collide. Note that checking for collisions with a rotated ImageSprite
currently checks against its unrotated position. Therefore, collision checking will be inaccurate for tall narrow or short wide sprites that are rotated.
other | the other sprite in the collision |
Definition at line 435 of file Sprite.java.
|
static |
Determines whether two sprites are in collision. Note that we cannot merely see whether the rectangular regions around each intersect, since some types of sprite, such as BallSprite, are not rectangular.
sprite1 | one sprite |
sprite2 | another sprite |
Definition at line 922 of file Sprite.java.
boolean com.google.appinventor.components.runtime.Sprite.CollidingWith | ( | Sprite | other | ) |
Indicates whether a collision has been registered between this type%
and the passed other
sprite.
other | the sprite to check for collision with this sprite |
Definition at line 657 of file Sprite.java.
boolean com.google.appinventor.components.runtime.Sprite.containsPoint | ( | double | qx, |
double | qy | ||
) |
Indicates whether the specified point is contained by this sprite. Subclasses of Sprite that are not rectangular should override this method.
qx | the x-coordinate |
qy | the y-coordinate |
Reimplemented in com.google.appinventor.components.runtime.Ball.
Definition at line 978 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Dragged | ( | float | startX, |
float | startY, | ||
float | prevX, | ||
float | prevY, | ||
float | currentX, | ||
float | currentY | ||
) |
Event handler for Dragged events. 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 type%
won't actually move anywhere in response to the Dragged event unless MoveTo(double, double) is specifically called.
startX | the starting x-coordinate |
startY | the starting y-coordinate |
prevX | the previous x-coordinate (possibly equal to startX) |
prevY | the previous y-coordinate (possibly equal to startY) |
currentX | the current x-coordinate |
currentY | the current y-coordinate |
Definition at line 470 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.EdgeReached | ( | int | edge | ) |
Event handler called when the type%
reaches an edge
{:.variable.block} of the screen. If Bounce(int) is then called with that edge, the sprite 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).
Definition at line 489 of file Sprite.java.
boolean com.google.appinventor.components.runtime.Sprite.Enabled | ( | ) |
Controls whether the type%
moves when its speed is non-zero.
Definition at line 166 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Enabled | ( | boolean | enabled | ) |
Enabled property setter method: starts or stops the timer.
@suppressdoc
enabled |
Definition at line 180 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Flung | ( | float | x, |
float | y, | ||
float | speed, | ||
float | heading, | ||
float | xvel, | ||
float | yvel | ||
) |
When a fling gesture (quick swipe) is made on the sprite: provides the (x,y) position of the start of the fling, relative to the upper left of the canvas. Also provides the speed (pixels per millisecond) and heading (0-360 degrees) of the fling, as well as the x velocity and y velocity components of the fling's vector.
x | x-coordinate of touched point |
y | y-coordinate of touched point |
speed | the speed of the fling sqrt(xspeed^2 + yspeed^2) |
heading | the heading of the fling |
xvel | the speed in x-direction of the fling |
yvel | the speed in y-direction of the fling |
Definition at line 553 of file Sprite.java.
BoundingBox com.google.appinventor.components.runtime.Sprite.getBoundingBox | ( | int | border | ) |
Provides the bounding box for this sprite. Modifying the returned value does not affect the sprite.
border | the number of pixels outside the sprite to include in the bounding box |
Definition at line 908 of file Sprite.java.
HandlesEventDispatching com.google.appinventor.components.runtime.Sprite.getDispatchDelegate | ( | ) |
Returns the dispatch delegate that is responsible for dispatching events for this component.
Implements com.google.appinventor.components.runtime.Component.
Definition at line 1002 of file Sprite.java.
double com.google.appinventor.components.runtime.Sprite.Heading | ( | ) |
The type%
'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.
Definition at line 194 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Heading | ( | double | userHeading | ) |
Sets heading in which sprite should move. In addition to changing the local variables userHeading and heading, this sets headingCos, headingSin, and headingRadians.
@suppressdoc
userHeading | degrees above the positive x-axis |
Definition at line 210 of file Sprite.java.
|
protected |
Specifies which edge of the canvas has been hit by the Sprite, if any, moving the sprite back in bounds.
Definition at line 751 of file Sprite.java.
|
protected |
Definition at line 849 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Initialize | ( | ) |
Definition at line 147 of file Sprite.java.
boolean com.google.appinventor.components.runtime.Sprite.intersectsWith | ( | BoundingBox | rect | ) |
Determines whether this sprite intersects with the given rectangle.
rect | the rectangle |
Definition at line 950 of file Sprite.java.
int com.google.appinventor.components.runtime.Sprite.Interval | ( | ) |
The interval in milliseconds at which the type%
's position is updated. For example, if the Interval
is 50 and the Speed(float) is 10, then the type%
will move 10 pixels every 50 milliseconds.
Definition at line 232 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Interval | ( | int | interval | ) |
Interval property setter method: sets the interval between timer events.
@suppressdoc
interval | timer interval in ms |
Definition at line 246 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.MoveIntoBounds | ( | ) |
Moves the sprite back in bounds if part of it extends out of bounds, having no effect otherwise. If the sprite is too wide to fit on the canvas, this aligns the left side of the sprite with the left side of the canvas. If the sprite is too tall to fit on the canvas, this aligns the top side of the sprite with the top side of the canvas.
Definition at line 674 of file Sprite.java.
|
protected |
Moves the sprite back in bounds if part of it extends out of bounds, having no effect otherwise. If the sprite is too wide to fit on the canvas, this aligns the left side of the sprite with the left side of the canvas. If the sprite is too tall to fit on the canvas, this aligns the top side of the sprite with the top side of the canvas.
Definition at line 766 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.MoveTo | ( | double | x, |
double | y | ||
) |
Moves the type% so that its left top corner is at the specified x and y coordinates.
x | the x-coordinate |
y | the y-coordinate |
Reimplemented in com.google.appinventor.components.runtime.ImageSprite, and com.google.appinventor.components.runtime.Ball.
Definition at line 685 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.NoLongerCollidingWith | ( | Sprite | other | ) |
Event indicating that a pair of sprites are no longer colliding.
@internaldoc This also registers the removal of the collision to a private variable registeredCollisions so that CollidedWith(Sprite) and this event are only raised once per beginning and ending of a collision.
other | the sprite formerly colliding with this sprite |
Definition at line 513 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.onDelete | ( | ) |
Implements com.google.appinventor.components.runtime.Deleteable.
Definition at line 1016 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.onDestroy | ( | ) |
Implements com.google.appinventor.components.runtime.OnDestroyListener.
Definition at line 1009 of file Sprite.java.
|
abstractprotected |
Draws the sprite on the given canvas
canvas | the canvas on which to draw |
Reimplemented in com.google.appinventor.components.runtime.ImageSprite.
|
protected |
Reimplemented in com.google.appinventor.components.runtime.Ball.
Definition at line 396 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.PointInDirection | ( | double | x, |
double | y | ||
) |
Turns this type%
to point toward the point with the coordinates (x, y)
.
x | parameter of the point to turn to |
y | parameter of the point to turn to |
Definition at line 714 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.PointTowards | ( | Sprite | target | ) |
Turns this type%
to point towards a given target
sprite. The new heading will be parallel to the line joining the centerpoints of the two sprites.
target | the other sprite to point towards |
Definition at line 701 of file Sprite.java.
|
protected |
Posts a dispatch for the specified event. This guarantees that event handlers run with serial semantics, e.g., appear atomic relative to each other.
This method is overridden in tests.
sprite | the instance on which the event takes place |
eventName | the name of the event |
args | the arguments to the event handler |
Definition at line 415 of file Sprite.java.
|
protected |
Responds to a move or change of this sprite by redrawing the enclosing Canvas and checking for any consequences that need handling. Specifically, this (1) notifies the Canvas of a change so it can detect any collisions, etc., and (2) raises the EdgeReached(int) event if the Sprite has reached the edge of the Canvas.
Definition at line 728 of file Sprite.java.
float com.google.appinventor.components.runtime.Sprite.Speed | ( | ) |
Gets the speed with which this sprite moves.
@suppressdoc
Definition at line 276 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Speed | ( | float | speed | ) |
The speed at which the type%
moves. The type%
moves this many pixels every Interval() milliseconds if Enabled(boolean) is true
{:.logic.block}.
speed | the magnitude (in pixels) to move every interval milliseconds |
Definition at line 262 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.TouchDown | ( | float | x, |
float | y | ||
) |
When the user begins touching the sprite (places finger on sprite and leaves it there): provides the (x,y) position of the touch, relative to the upper left of the canvas
x | x-coordinate of touched point |
y | y-coordinate of touched point |
Definition at line 585 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Touched | ( | float | x, |
float | y | ||
) |
When the user touches the sprite and then immediately lifts finger: provides the (x,y) position of the touch, relative to the upper left of the canvas.
x | x-coordinate of touched point |
y | y-coordinate of touched point |
Definition at line 529 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.TouchUp | ( | float | x, |
float | y | ||
) |
When the user stops touching the sprite (lifts finger after a TouchDown event): provides the (x,y) position of the touch, relative to the upper left of the canvas.
x | x-coordinate of touched point |
y | y-coordinate of touched point |
Definition at line 569 of file Sprite.java.
|
protected |
Updates the x- and y-coordinates based on the heading and speed. The caller is responsible for calling registerChange().
Definition at line 823 of file Sprite.java.
boolean com.google.appinventor.components.runtime.Sprite.Visible | ( | ) |
The Visible
property determines whether the type% is visible (true
{:.logic.block}) or invisible (false
{:.logic.block}).
Definition at line 287 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Visible | ( | boolean | visible | ) |
Sets whether sprite should be visible.
visible |
Definition at line 301 of file Sprite.java.
double com.google.appinventor.components.runtime.Sprite.X | ( | ) |
Reimplemented in com.google.appinventor.components.runtime.ImageSprite, and com.google.appinventor.components.runtime.Ball.
Definition at line 306 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.X | ( | double | x | ) |
Definition at line 334 of file Sprite.java.
double com.google.appinventor.components.runtime.Sprite.Y | ( | ) |
Reimplemented in com.google.appinventor.components.runtime.ImageSprite, and com.google.appinventor.components.runtime.Ball.
Definition at line 367 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Y | ( | double | y | ) |
Definition at line 362 of file Sprite.java.
double com.google.appinventor.components.runtime.Sprite.Z | ( | ) |
Definition at line 390 of file Sprite.java.
void com.google.appinventor.components.runtime.Sprite.Z | ( | double | layer | ) |
How the type%
should be layered relative to other Balls and ImageSprites, with higher-numbered layers appearing in front of lower-numbered layers.
layer | higher numbers indicate that this sprite should appear in front of ones with lower numbers; if values are equal for sprites, either can go in front of the other |
Definition at line 382 of file Sprite.java.
|
protected |
Definition at line 48 of file Sprite.java.
|
staticprotected |
Definition at line 46 of file Sprite.java.
|
protected |
Definition at line 76 of file Sprite.java.
|
protected |
The angle, in degrees below the positive x-axis, specified by the user. We use this to compute new coordinates because, on Android, the y-coordinate increases "below" the x-axis.
Definition at line 91 of file Sprite.java.
|
protected |
Definition at line 93 of file Sprite.java.
|
protected |
Definition at line 92 of file Sprite.java.
|
protected |
Definition at line 94 of file Sprite.java.
|
protected |
Definition at line 60 of file Sprite.java.
|
protected |
Definition at line 64 of file Sprite.java.
|
protected |
Definition at line 72 of file Sprite.java.
|
protected |
Definition at line 69 of file Sprite.java.
|
protected |
The angle, in degrees above the positive x-axis, specified by the user. This is private in order to enforce that changing it also changes heading, headingRadians, headingCos, and headingSin.
Definition at line 84 of file Sprite.java.
|
protected |
Definition at line 65 of file Sprite.java.
|
protected |
Definition at line 73 of file Sprite.java.
|
protected |
Definition at line 66 of file Sprite.java.
|
protected |
Definition at line 74 of file Sprite.java.
|
protected |
Definition at line 67 of file Sprite.java.
|
protected |
Definition at line 68 of file Sprite.java.