ch.aplu.jgamegrid
Class Actor
java.lang.Object
ch.aplu.jgamegrid.Actor
- All Implemented Interfaces:
- GGActorCollisionListener, GGBorderListener, GGTileCollisionListener, java.util.EventListener
- Direct Known Subclasses:
- CardActor, CardCover, GGButtonBase, TextActor, ToolBarItem
public class Actor
- extends java.lang.Object
- implements GGBorderListener, GGActorCollisionListener, GGTileCollisionListener
Class that holds sprite icons that plays the role of an actor in the
game's game grid. The actor's image may only be positioned in the center of cells.
(for even pixel unit cells/and or even pixel unit images, some rounding is necessary.)
For one pixel unit cells, the actor image is positioned at the pixel coordinates.
An actor may contain more than one sprite. This is useful if the appearence of the actor
should change, while remaining the same actor (walking, speaking, flying, etc.).
The sprites are referenced by an integer sprite id running from 0 up.
All sprites of an actor are positioned at the same location with the
same direction. At all times only one (or none) of the sprites is visible.
If an actor is declared rotatable, the sprite images are rotated when the actor
direction changes. To speed-up execution the images are preloaded
into the Java heap when the actor is created. By default there are 60 different
rotation images giving an angle resolution of 360 / 60 = 6 degrees.
(This number may be changed using a special GameGrid constructor.)
If there are many rotatable sprites with big images, it may be necessary
to increase the heap space by using
java -Xms -Xmx
Defaults are: java -Xms32m -Xmx128m
You can set this either in the Java Control Panel or on the command line,
depending on the environment you run your application.
Actors are partially active objects, animated by the same thread that runs the simulation loop. In
every simulation cycle, the actor's act() method is called, where the user performs the
desired action. This concept has the advantage that act() is called in a strict order
(that can be modified) and by the same thread. This avoids concurrency problems that is an issue
with fully active object where each object has its own thread. As a drawback all actors must
be cooperative: act() must return quickly in order to give other actors the chance to act.
If actors should not act synchronously, the execution may be skipped for
a given number of simulation cycles by using individually setSlowDown()
A advanced collision detection mechanism for collisions betweeen actors or
between an actor an a tile of a tile map is implemented.
The collision may be detected using collision rectangles, collision circles,
collision spots and for some collision types collisions of non-transparent
image pixels. Collision rectangles, circles and spots may be placed
at any desired position (rectangles and circles with specified size) relative
to the sprite image. The collision area rotates when the sprites rotates.
Much effort is investigated for a high speed implementation
of the collision detection, using the SAT (Separating Axis Theorem)
for rotated rectangle intersection.
To speed up the collision system, each actor defines actors or tiles that are
candidates for collisions. Collisions are considered to be events and are
notified by a registrated GGActorCollisionListener or a registrated
GGTileCollisionListener
The collision check is performed in every simulation cycle and the collision
event callback invoked by the game thread after actor's act() invocation. The
default collision area is a rectangle that fits the actor image. If performance
is an issue, use circle-circle collision type.
Collision areas are considered to be part of the sprite image and stored as
such. Because actors with the same sprite image have the same collision area,
modifying a collision area effects all actors with the same sprite.
Most methods are only valid after the actor has been added to the GameGrid.
At this time reset() is called. So perform your own initialization code
by overriding reset() or in the first act() cycle.
All public methods are synchronized to make them thread-safe.
Field Summary |
GameGrid |
gameGrid
The reference to the GameGrid instance. |
int |
nbCycles
The current number of simulation cycles since last reset. |
Constructor Summary |
Actor()
Constructs an actor with no sprite image. |
Actor(boolean isRotatable,
java.awt.image.BufferedImage... spriteImages)
Constructs an actor based on one several sprite images defined by the given
buffered images. |
Actor(boolean isRotatable,
java.awt.image.BufferedImage spriteImage)
Constructs actor based on the specified buffered image. |
Actor(boolean isRotatable,
java.lang.String... filenames)
Constructs an actor based on one several sprite images. |
Actor(boolean isRotatable,
java.lang.String filename)
Constructs an actor based on the specified sprite image. |
Actor(boolean isRotatable,
java.lang.String filename,
int nbSprites)
Constructs an actor based on one or more sprite images. |
Actor(java.awt.image.BufferedImage... spriteImages)
Constructs an unrotatable actor based on one or several sprite images
defined by the given buffered images. |
Actor(java.awt.image.BufferedImage spriteImage)
Constructs an unrotatable actor based on the specified sprite image. |
Actor(java.lang.String... filenames)
Constructs an unrotatable actor based on several sprite images. |
Actor(java.lang.String filename)
Constructs an unrotatable actor based on the specified sprite image. |
Actor(java.lang.String filename,
int nbSprites)
Constructs an unrotatable actor based on one or more sprite images. |
Method Summary |
void |
act()
Empty method called in every simulation iteration. |
void |
addActorCollisionListener(GGActorCollisionListener listener)
Registers a collision listener that reports collision events when
actors collide. |
void |
addBorderListener(GGBorderListener listener)
Registers an GGBorderListener so that the callback method nearBorder() is called
when the actor's location is on a cell at the border of the game grid. |
void |
addCollisionActor(Actor partner)
Registers a partner actor that becomes a collision candidate, e.g. that
is checked for collisions in every simulation cycle. |
void |
addCollisionActors(Actor[] partners)
Registers all actors in a list as collision candidates. |
void |
addCollisionActors(java.util.ArrayList<Actor> partners)
Registers all actors in a list as collision candidates. |
void |
addCollisionTile(Location location)
Registers a tile location that becomes a collision candidate, e.g. that
is checked for collisions in every simulation cycle. |
void |
addCollisionTiles(java.util.ArrayList<Location> locations)
Registers all tile locations in a list as collision candidates. |
void |
addCollisionTiles(Location[] locations)
Registers all tile locations in a list as collision candidates. |
void |
addMouseTouchListener(GGMouseTouchListener listener,
int mouseEventMask)
Same as addMouseTouchListener(listener, mouseEventMask, onTopOnly)
with onTopOnly = false. |
void |
addMouseTouchListener(GGMouseTouchListener listener,
int mouseEventMask,
boolean onTopOnly)
Add a GGMouseTouchListener to get notifications when the mouse
interacts with the mouse touch area. |
void |
addTileCollisionListener(GGTileCollisionListener listener)
Registers a tile listener that reports collision events when actors
and tiles collide. |
int |
collide(Actor actor1,
Actor actor2)
Empty implementation of a GGActorCollisionListener called when the two actors collides. |
int |
collide(Actor actor,
Location location)
Empty implementation of a GGTileCollisionListener called when
the an actor collides with a tile. |
static void |
delay(long time)
Delay execution for the given amount of time. |
void |
displace(double ds)
Increases the current double displace position in the
current direction to the given double distance and moves the actor
in the cell that contains the given coordinates. |
GGBackground |
getBackground()
Returns the GGBackground reference of the actor's game grid. |
java.util.ArrayList<Actor> |
getCollisionActors()
Returns a list of partners that are collision candidates. |
java.util.ArrayList<Actor> |
getCollisionActorsInRange(double radius,
java.lang.Class clazz,
int spriteId)
Returns all collision candidates who belongs to a given class whose collision areas
of the image with given sprite id intersects the circle with specified radius. |
java.util.ArrayList<Location> |
getCollisionTiles()
Returns a list of tile locations that are collision candidates. |
java.awt.image.BufferedImage |
getCurrentImage()
Returns the buffered image of the currently visible sprite picture. |
double |
getDirection()
Gets the current direction. |
double |
getDirectionStart()
Returns the start direction. |
java.awt.geom.Point2D.Double |
getDisplacePosition()
Returns the current displace position. |
int |
getHeight(int spriteId)
Returns the height of the sprite with given id. |
int |
getIdVisible()
Returns the id of the visible sprite. |
java.awt.image.BufferedImage |
getImage()
Returns the buffered image of the originally loaded sprite with
id = 0. |
java.awt.image.BufferedImage |
getImage(int spriteId)
Returns the buffered image of the originally loaded sprite with
given sprite id. |
int |
getIntDirection()
Gets the current direction rounded to the next integer. |
Location |
getLocation()
Returns the current location (horizontal and vertical coordinates). |
java.awt.Point |
getLocationOffset()
Returns the pixel offset in x- and y-direction relative to the current
location. |
Location |
getLocationStart()
Returns the start location (horizontal and vertical coordinates). |
int |
getNbCycles()
Returns the number of simulation cycles since last reset. |
int |
getNbHorzCells()
Returns number of cells of actor's game grid in horizontal direction. |
int |
getNbSprites()
Returns number of sprites. |
int |
getNbVertCells()
Returns number of cells of actor's game grid in vertical direction. |
java.util.ArrayList<Actor> |
getNeighbours(double distance)
Returns all actors in a specified distance. |
java.util.ArrayList<Actor> |
getNeighbours(double distance,
java.lang.Class clazz)
Returns all actors of specified class in a specified distance. |
Location |
getNextMoveLocation()
Returns the target location of the next move(). |
java.awt.Color |
getPixelColor(java.awt.Point pt)
Returns the color of the currently visible sprite image at given
pixel position ((0,0) at upper left vertex, x-axis to the right,
y-axis downwards). |
java.awt.Point |
getPixelLocation()
Returns the location of the actor center in pixel coordinates taking
into account the current location offset (default offset is 0). |
static GGVector |
getRotatedPosition(GGVector position,
java.awt.Point center,
double angle)
Returns a new position vector of given position vector
rotated with given center point by given angle. |
int |
getRotationIndex()
Returns the current rotation index for rotatable actors. |
static java.awt.image.BufferedImage |
getScaledImage(java.awt.image.BufferedImage bi,
double factor,
double angle)
Deprecated. Use GGBitmap.getScaledImage instead. GGBitmap.getScaledImage(BufferedImage bi, double factor, double angle) |
java.awt.image.BufferedImage |
getScaledImage(double factor,
double angle)
Same as getScaledImage(int spriteId, double factor, double angle)
with spriteId = 0. |
java.awt.image.BufferedImage |
getScaledImage(int spriteId,
double factor,
double angle)
Returns the sprite image scaled by the given factor and rotated to the
given angle. |
int |
getSlowDown()
Returns the current slow down factor. |
int |
getWidth(int spriteId)
Returns the width of the sprite with given id. |
int |
getX()
Returns the current horizontal coordinate. |
int |
getXStart()
Returns the x-coordinate of the start location. |
int |
getY()
Returns the current vertical coordinate. |
int |
getYStart()
Returns the y-coordinate of the start location. |
void |
hide()
Turns off the visiblity of this actor (all sprites are hidden, spriteId = -1). |
boolean |
isActEnabled()
Returns true, if act() is invoked in every simulation cycle. |
boolean |
isActorCollisionEnabled()
Returns true, if collision notification between actors is enabled. |
boolean |
isHorzMirror()
Returns the horizontal mirroring state. |
boolean |
isInGrid()
Returns true, if the actor's location is inside the grid. |
boolean |
isMoveValid()
Returns true, if the next call of move() will put the actor in a cell
inside the game grid. |
boolean |
isNearBorder()
Returns true, if the current location is on a border row or column. |
boolean |
isRemoved()
Returns true, if the actor has been removed (by calling removeSelf() or
GameGrid.removeActor()). |
boolean |
isRotatable()
Returns whether the actor is rotatable or not. |
boolean |
isTileCollisionEnabled()
Returns true, if collision notification between tiles is enabled. |
boolean |
isVertMirror()
Returns the vertical mirroring state. |
boolean |
isVisible()
Returns true, if the actor is visible. |
void |
move()
For a small grid (total number of cells <= 2500 = 50 * 50)
moves to one of 8 neighbour cells in the current direction (compass directions 45 degrees wide). |
void |
move(int distance)
Moves the given distance in the current direction. |
void |
nearBorder(Actor actor,
Location location)
Empty implementation of a BorderListener called when the actor is set into a border cell. |
void |
removeSelf()
Removes the given actor from the scene, so that act() is not called any more. |
void |
reset()
Empty method called when the actor is added to the game grid,
the reset button is clicked or doReset() is called. |
void |
rotate(Location centerLoc,
double angle)
Rotates the actor with given rotation center location by the given angle. |
void |
rotate(java.awt.Point center,
double angle)
Rotates the actor with given rotation center point by given angle. |
void |
setActEnabled(boolean enable)
Enable/disable the invocation of act() in every simulation cycle. |
void |
setActorCollisionEnabled(boolean enable)
Enable/disable the detection of collisions with the actor collision candidates. |
void |
setCollisionCircle(int spriteId,
java.awt.Point center,
int radius)
Selects the circle (in pixel units) relative to the sprite image that is used for
collision detection. |
void |
setCollisionCircle(java.awt.Point center,
int radius)
Same as setCollisionCircle(int spriteId, Point center, int radius)
for spriteId = 0. |
void |
setCollisionImage()
Same as setCollisionImage(int spriteId) for spriteId = 0. |
void |
setCollisionImage(int spriteId)
Selects collision detection on non-transparent pixels of the image. |
void |
setCollisionLine(int spriteId,
java.awt.Point startPoint,
java.awt.Point endPoint)
Selects the line segment (in pixel units) relative to the sprite image that is used for
collision detection. |
void |
setCollisionLine(java.awt.Point startPoint,
java.awt.Point endPoint)
Same as setCollisionLine(int spriteId, Point startPoint, Point endPoint)
for spriteId = 0. |
void |
setCollisionRectangle(int spriteId,
java.awt.Point center,
int width,
int height)
Selects the rectangle (in pixel units) relative to the sprite image that is used for
collision detection. |
void |
setCollisionRectangle(java.awt.Point center,
int width,
int height)
Same as setCollisionRectangle(int spriteId, Point center, int width, int height)
for spriteId = 0 |
void |
setCollisionSpot(int spriteId,
java.awt.Point spot)
Selects the hot spot (in pixel units) relative to the sprite image that is used for
collision detection. |
void |
setCollisionSpot(java.awt.Point spot)
Same as setCollisionSpot(int spriteId, Point spot)
for spriteId = 0. |
void |
setDirection(double direction)
Sets the moving direction. |
void |
setDirection(Location.CompassDirection compassDir)
Sets the moving direction to the given compass direction. |
void |
setDisplacePosition(java.awt.geom.Point2D.Double displacePosition)
Sets the current displace position and moves the actor in the cell that
contains the given coordinates. |
void |
setHorzMirror(boolean enable)
If set, the sprite image shown is mirrored horizontally. |
void |
setLocation(Location location)
Assigns a new current location. |
void |
setLocationOffset(int x,
int y)
Same as setLoctionOffset(Point locationOffset) with given x and
y displacements. |
void |
setLocationOffset(java.awt.Point locationOffset)
Sets a pixel offset in x- any y-direction relative to the current
location. |
void |
setMouseTouchCircle(int spriteId,
java.awt.Point center,
int radius)
Selects the circle (in pixel units) relative to the sprite image that is used for
mouse touch detection. |
void |
setMouseTouchCircle(java.awt.Point center,
int radius)
Same as setMouseTouchCircle(int spriteId, Point center, int radius)
for all sprites of this actor. |
void |
setMouseTouchEnabled(boolean enable)
Enable/disable the detection of mouse interactions. |
void |
setMouseTouchImage()
Same as setMouseTouchImage(int spriteId) for all sprites of this actor. |
void |
setMouseTouchImage(int spriteId)
Selects the non-transparent pixels of the sprite image for
mouse touch detection. |
void |
setMouseTouchRectangle(int spriteId,
java.awt.Point center,
int width,
int height)
Selects the rectangle (in pixel units) relative to the sprite image that is used for
mouse touch detection. |
void |
setMouseTouchRectangle(java.awt.Point center,
int width,
int height)
Same as setTouchRectangle(int spriteId, Rectangle rect)
for all sprites of this actor. |
void |
setOnBottom()
Sets the actor at the last place in the scene of the actor class. |
void |
setOnTop()
Sets the actor at the first place in the scene of actor class. |
void |
setPixelLocation(java.awt.Point imageCenter)
Moves the center of the actor to the given pixel coordinates. |
void |
setSlowDown(int factor)
Slows down the calling of act() by the given factor. |
void |
setTileCollisionEnabled(boolean enable)
Enable/disable the detection of collisions with the tile collision candidates. |
void |
setVertMirror(boolean enable)
If set, the sprite image shown is mirrored vertically. |
void |
setX(int x)
Assigns a new current horizontal cell coordinate. |
void |
setY(int y)
Assigns a new current vertical cell coordinate. |
void |
show()
Turns on the visibility of the sprite with id 0. |
void |
show(int spriteId)
Turns on the visibility of the sprite with given id. |
void |
showNextSprite()
Increases the id of the currently visible sprite and makes this
sprite visible. |
void |
showPreviousSprite()
Decreases the id of the currently visible sprite and makes this
sprite visible. |
void |
turn(double angle)
Turns the moving direction by the given angle (clockwise for positive
angles, counterclockwise for negative angles). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
gameGrid
public GameGrid gameGrid
- The reference to the GameGrid instance.
Null if the actor is not yet added to the game grid. If it was added and
removed after, gameGrid is still valid.
nbCycles
public int nbCycles
- The current number of simulation cycles since last reset.
Actor
public Actor(java.awt.image.BufferedImage... spriteImages)
- Constructs an unrotatable actor based on one or several sprite images
defined by the given buffered images.
The spriteId starts from 0 and corresponds to the order of the given images.
(Used to create an actor based on images defined on runtime.)
- Parameters:
spriteImages
- references to BufferedImages that contains the sprite images
Actor
public Actor(java.awt.image.BufferedImage spriteImage)
- Constructs an unrotatable actor based on the specified sprite image.
(Used to create an actor based on images defined on runtime.)
- Parameters:
spriteImage
- references to BufferedImage that contains the sprite image
Actor
public Actor(boolean isRotatable,
java.awt.image.BufferedImage spriteImage)
- Constructs actor based on the specified buffered image.
(Used to create an actor based on an image defined on runtime.)
If isRotatable is true, the actor is rotated when the direction changes.
- Parameters:
isRotatable
- if true, the actor's image may be rotated when the direction changesspriteImage
- reference to a BufferedImage that contains the sprite image
Actor
public Actor(boolean isRotatable,
java.awt.image.BufferedImage... spriteImages)
- Constructs an actor based on one several sprite images defined by the given
buffered images.
The spriteId starts from 0 and corresponds to the order of the given images.
(Used to create an actor based on images defined on runtime.)
If isRotatable is true, the actor is rotated when the direction changes.
- Parameters:
isRotatable
- if true, the actor's image may be rotated when the direction changesspriteImages
- references to BufferedImages that contains the sprite images
Actor
public Actor()
- Constructs an actor with no sprite image. Sometimes this is useful for
dummy actors that are not shown but act only.
Actor
public Actor(java.lang.String filename)
- Constructs an unrotatable actor based on the specified sprite image.
From the given filename the image file is searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
filename
- the path or URL to the image file displayed for this actor.
Actor
public Actor(java.lang.String... filenames)
- Constructs an unrotatable actor based on several sprite images.
The spriteId starts from 0 and corresponds to the order of the given filenames.
From the given filenames the image files are searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
filenames
- the paths or URLs (one or more) to the image files displayed for this actor.
Actor
public Actor(boolean isRotatable,
java.lang.String filename)
- Constructs an actor based on the specified sprite image.
If isRotatable is true, the actor is rotated when the direction changes.
From the given filename the image file is searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
isRotatable
- if true, the actor's image may be rotated when the direction changesfilename
- the path to the image file displayed for this actor
Actor
public Actor(boolean isRotatable,
java.lang.String... filenames)
- Constructs an actor based on one several sprite images.
If isRotatable is true, the actor is rotated when the direction changes.
The spriteId starts from 0 and corresponds to the order of the given filenames.
From the given filenames the image files are searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
isRotatable
- if true, the actor's image may be rotated when the direction changesfilenames
- the paths or URLs to the image files displayed for this actor
Actor
public Actor(java.lang.String filename,
int nbSprites)
- Constructs an unrotatable actor based on one or more sprite images.
The actor may contain more than one sprite images, if nbSprites > 1
the filenames of these images are automatically generated in a sequence
filename_0.ext, filename_1.ext, ...
From the given filename the image file is searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
filename
- the fully qualified path to the image file displayed for this actornbSprites
- the number of sprite images for the same actor
Actor
public Actor(boolean isRotatable,
java.lang.String filename,
int nbSprites)
- Constructs an actor based on one or more sprite images.
If isRotatable is true, the actor is rotated when the direction changes.
The actor may contain more than one sprite images, if nbSprites > 1
the filenames of these images are automatically generated in a sequence
filename_0.ext, filename_1.ext, ...
From the given filename the image file is searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive
- relative to the directory <userhome>/gamegrid/
- relative or absolute to current application directory
- if filename starts with http://, from the given URL
- imagePath prefixed with _ and searched relative to the root of the jar archive (used for sprite library distribution)
- Parameters:
isRotatable
- if true, the actor's image may be rotated when the direction changesfilename
- the path or URL to the image file displayed for this actornbSprites
- the number of sprite images for the same actor
setLocationOffset
public void setLocationOffset(java.awt.Point locationOffset)
- Sets a pixel offset in x- any y-direction relative to the current
location. Effects the display position and the mouseTouchArea only.
All location values (e.g. getLocation(), collisionAreas, etc.) are unchanged.
Used to fine tune the displayed sprite position in a coarse game grid.
- Parameters:
locationOffset
- x,y displacement (x to the left, y downwards)
setLocationOffset
public void setLocationOffset(int x,
int y)
- Same as setLoctionOffset(Point locationOffset) with given x and
y displacements.
- Parameters:
x
- displacement (positive x to the left)y
- displacement (positive y to downwards)
getLocationOffset
public java.awt.Point getLocationOffset()
- Returns the pixel offset in x- and y-direction relative to the current
location.
- Returns:
- x, y displacment
getBackground
public GGBackground getBackground()
- Returns the GGBackground reference of the actor's game grid.
Requires that the actor has been added to the game grid.
- Returns:
- the GGBackground reference of the actor's game grid.
If the actor is not yet added to the game grid,
displays an error and terminates application.
setX
public void setX(int x)
- Assigns a new current horizontal cell coordinate.
The location may be outside the range of the cells inside the game grid.
Triggers a border event, if the location is near the border.
- Parameters:
x
- the x-coordinate (cell index)
setY
public void setY(int y)
- Assigns a new current vertical cell coordinate.
The location may be outside the range of the cells inside the game grid.
Triggers a border event, if the location is near the border.
- Parameters:
y
- the y-coordinate (cell index)
setLocation
public void setLocation(Location location)
- Assigns a new current location.
Triggers a border event, if the location is near the border.
The location may be outside the range of the cells inside the game grid.
- Parameters:
location
- the location (value copy)
setPixelLocation
public void setPixelLocation(java.awt.Point imageCenter)
- Moves the center of the actor to the given pixel coordinates.
Sets the actor location to the cell that contains the given point
(if outside the game grid, the nearest location in the grid is used)
The location offset is set to show the picture center at the given point.
Pixel coordinate system: origin at the left upper vertex of
the game grid window, x-axis to the left, y-axis downwards.
Keep in mind that the location offset is an actor attribute that may
cause side effects and only effects the display position and
the mouseTouchArea (collisionAreas are unchanged).
- Parameters:
imageCenter
- the pixel coordinates of the image center
getX
public int getX()
- Returns the current horizontal coordinate.
- Returns:
- the x-coordinate (cell index)
getY
public int getY()
- Returns the current vertical coordinate.
- Returns:
- the y-coordinate (cell index)
getLocation
public Location getLocation()
- Returns the current location (horizontal and vertical coordinates).
- Returns:
- a clone of the current location (cell indices)
getLocationStart
public Location getLocationStart()
- Returns the start location (horizontal and vertical coordinates).
- Returns:
- a clone of the location when the actor was added to the game grid
getXStart
public int getXStart()
- Returns the x-coordinate of the start location.
- Returns:
- the x-coordinate when the actor was added to the game grid
getYStart
public int getYStart()
- Returns the y-coordinate of the start location.
- Returns:
- the y-coordinate when the actor was added to the game grid
getDirectionStart
public double getDirectionStart()
- Returns the start direction.
- Returns:
- the start direction when the actor was added to the game grid
setDirection
public void setDirection(double direction)
- Sets the moving direction.
- Parameters:
direction
- the angle for the next movement (in degrees clockwise, 0 to east)
setDirection
public void setDirection(Location.CompassDirection compassDir)
- Sets the moving direction to the given compass direction.
- Parameters:
compassDir
- the compass dirction for the next movement
getRotationIndex
public int getRotationIndex()
- Returns the current rotation index for rotatable actors.
By default the rotation index is within 0..59, because
there are 60 different rotation images giving an angle
resolution of 360 / 60 = 6 degrees.
(This number may be changed using a special GameGrid constructor.)
- Returns:
- the rotation index (for non-rotatable actors always 0)
getDirection
public double getDirection()
- Gets the current direction.
- Returns:
- the direction for the next movement (in degrees clockwise, 0 to east)
getIntDirection
public int getIntDirection()
- Gets the current direction rounded to the next integer.
- Returns:
- the direction for the next movement (in degrees clockwise, 0 to east)
getNextMoveLocation
public Location getNextMoveLocation()
- Returns the target location of the next move().
For a small grid (total number of cells <= 2500 = 50 * 50)
the target location is one of 8 neighbour cells in the current direction (compass directions 45 degrees wide).
otherwise it is a cell location about 5 cell sizes away in the current direction.
move
public void move()
- For a small grid (total number of cells <= 2500 = 50 * 50)
moves to one of 8 neighbour cells in the current direction (compass directions 45 degrees wide).
otherwise moves to a cell about 5 cell sizes away in the current direction.
Keep in mind that successive calls of move() in the same direction does not
necessarily move the actor on a straight line. If you want to move the
actor on a line, use displace() or declare global double (float) x and
y coordinates and increase them in each step with
xnew = x + speedx * Math.cos(Math.toRadians(getDirection())
ynew = y + speedy * Math.sin(Math.toRadians(getDirection())
x = xnew
y = ynew
move
public void move(int distance)
- Moves the given distance in the current direction. For distance = 1, the
8 neighbour locations are reached. To move the actor on a straight line, see
the remarks for method move().
- Parameters:
distance
- the distance to the requested cell location in cell units.- See Also:
move()
getNbHorzCells
public int getNbHorzCells()
- Returns number of cells of actor's game grid in horizontal direction.
Requires that the actor has been added to the game grid.
- Returns:
- the number of cells in x-direction
getNbVertCells
public int getNbVertCells()
- Returns number of cells of actor's game grid in vertical direction.
Requires that the actor has been added to the game grid.
- Returns:
- the number of cells in y-direction
turn
public void turn(double angle)
- Turns the moving direction by the given angle (clockwise for positive
angles, counterclockwise for negative angles). The new moving direction
remains within 0..360.
- Parameters:
angle
- the angle to turn in degrees
act
public void act()
- Empty method called in every simulation iteration. Override it to
implement your own notification.
reset
public void reset()
- Empty method called when the actor is added to the game grid,
the reset button is clicked or doReset() is called.
Override to get your own notification. Perform your initialization code
here better than in the constructor, where many of the actor's method
are still invalid. This method is called before the first act() cycling.
addBorderListener
public void addBorderListener(GGBorderListener listener)
- Registers an GGBorderListener so that the callback method nearBorder() is called
when the actor's location is on a cell at the border of the game grid.
- Parameters:
listener
- the GGBorderListener to register
nearBorder
public void nearBorder(Actor actor,
Location location)
- Empty implementation of a BorderListener called when the actor is set into a border cell.
Override to get your own notification.
- Specified by:
nearBorder
in interface GGBorderListener
- Parameters:
actor
- the current actorlocation
- the border location
isInGrid
public boolean isInGrid()
- Returns true, if the actor's location is inside the grid.
Requires that the actor has been added to the game grid.
- Returns:
- true, if the current actor's location is inside the grid
isNearBorder
public boolean isNearBorder()
- Returns true, if the current location is on a border row or column.
Be aware that in one pixel games, the near border location is only 1 pixel from the border.
Requires that the actor has been added to the game grid.
- Returns:
- true, if the current location is on a border row or column
isMoveValid
public boolean isMoveValid()
- Returns true, if the next call of move() will put the actor in a cell
inside the game grid.
Requires that the actor has been added to the game grid.
- Returns:
- true, if the actor remains inside the grid on the next move()
removeSelf
public void removeSelf()
- Removes the given actor from the scene, so that act() is not called any more.
The visiblity is turned off (spriteId = -1) and a registered mouse,
mouse touch or key listener is disabled. If the actor has not yet
been added to the game grid, nothing happens.Be aware that clicking
the reset button or calling reset() will not bring
the actor to life.
The public gameGrid reference remains valid, even if the actor has
been removed. You may check if an actor has been added and then
removed by calling isRemoved().
If you want to reuse the removed actor, you may add it again
to the game grid (the sprite with id = 0 is shown). Any mouse, mouse touch
or key listener must be registered again. Instead of removing the actor,
call hide() to make him invisible and show() to display him again.
The buffered image resources will be released when the actor
reference runs out of scope. Because actors use a lot of heap space,
you should be careful to remove actors and deassign their reference
when they are no more used (e.g. moves out of the visible game grid).
setSlowDown
public void setSlowDown(int factor)
- Slows down the calling of act() by the given factor. This may be used to
individually adapt the speed of actors. Sets a counter to the given value.
Before calling act(), the counter is decremented. When it reaches zero,
act() is called.
- Parameters:
factor
- the factor greater or equal to 1 for delaying the
invocation of act()
getSlowDown
public int getSlowDown()
- Returns the current slow down factor.
- Returns:
- the slow down factor
show
public void show()
- Turns on the visibility of the sprite with id 0.
All other sprites are hidden.
show
public void show(int spriteId)
- Turns on the visibility of the sprite with given id.
All other sprites are hidden.
- Parameters:
spriteId
- the sprite id that will become visible; visibility
remains unchanged if spriteId is less than zero or greater or equal to
the number of sprites
hide
public void hide()
- Turns off the visiblity of this actor (all sprites are hidden, spriteId = -1).
getIdVisible
public int getIdVisible()
- Returns the id of the visible sprite.
- Returns:
- the id of the visible sprite in the range 0..number of
sprites (exclusive), -1 if no sprite is visible
isVisible
public boolean isVisible()
- Returns true, if the actor is visible.
- Returns:
- true, if one of the sprites is shown; false, if the actor has
spriteId == -1 or is not part of the game grid
addCollisionActor
public void addCollisionActor(Actor partner)
- Registers a partner actor that becomes a collision candidate, e.g. that
is checked for collisions in every simulation cycle.
The collisions are reported by a collision listener that must be
registered with addActorCollisionListener().
- Parameters:
partner
- the partner that is checked for collision
collide
public int collide(Actor actor1,
Actor actor2)
- Empty implementation of a GGActorCollisionListener called when the two actors collides.
Override to get your own notification.
- Specified by:
collide
in interface GGActorCollisionListener
- Parameters:
actor1
- the first actoractor2
- the second actor
- Returns:
- nb of simulation cycles to wait until collision is rearmed
collide
public int collide(Actor actor,
Location location)
- Empty implementation of a GGTileCollisionListener called when
the an actor collides with a tile.
Override to get your own notification.
- Specified by:
collide
in interface GGTileCollisionListener
- Parameters:
actor
- the colliding actorlocation
- the location of the colliding tile within the tile map
- Returns:
- nb of simulation cycles to wait until collision is rearmed
addCollisionActors
public void addCollisionActors(Actor[] partners)
- Registers all actors in a list as collision candidates.
The collisions are reported by a collision listener that must be
registered with addActorCollisionListener().
- Parameters:
partners
- an array of actors that are checked for collision
addCollisionActors
public void addCollisionActors(java.util.ArrayList<Actor> partners)
- Registers all actors in a list as collision candidates.
The collisions are reported by a collision listener that must be
registered with addActorCollisionListener().
- Parameters:
partners
- a list of actors that are checked for collision
getCollisionActors
public java.util.ArrayList<Actor> getCollisionActors()
- Returns a list of partners that are collision candidates.
- Returns:
- all actors that are checked for collisions
addCollisionTile
public void addCollisionTile(Location location)
- Registers a tile location that becomes a collision candidate, e.g. that
is checked for collisions in every simulation cycle.
The collisions are reported by a collision listener that must be
registered with addTileCollisionListener().
- Parameters:
location
- the location of the tile within the tile map
addCollisionTiles
public void addCollisionTiles(Location[] locations)
- Registers all tile locations in a list as collision candidates.
The collisions are reported by a collision listener that must be
registered with addTileCollisionListener().
- Parameters:
locations
- an array of tile locations that are checked for collision
addCollisionTiles
public void addCollisionTiles(java.util.ArrayList<Location> locations)
- Registers all tile locations in a list as collision candidates.
The collisions are reported by a collision listener that must be
registered with addTileCollisionListener().
- Parameters:
locations
- a list of tile locations that are checked for collision
getCollisionTiles
public java.util.ArrayList<Location> getCollisionTiles()
- Returns a list of tile locations that are collision candidates.
- Returns:
- all tile locations that are checked for collisions
addActorCollisionListener
public void addActorCollisionListener(GGActorCollisionListener listener)
- Registers a collision listener that reports collision events when
actors collide. Another already registered listener is disabled. The
collision notification is called in every simulation cycle before
the actor's act().
- Parameters:
listener
- an actor collision listener; null to disable events
addTileCollisionListener
public void addTileCollisionListener(GGTileCollisionListener listener)
- Registers a tile listener that reports collision events when actors
and tiles collide. Another already registered listener is disabled.
- Parameters:
listener
- a tile collision listener; null to disable events
setHorzMirror
public void setHorzMirror(boolean enable)
- If set, the sprite image shown is mirrored horizontally.
- Parameters:
enable
- if true, horizontal mirroring is enabled
setVertMirror
public void setVertMirror(boolean enable)
- If set, the sprite image shown is mirrored vertically.
- Parameters:
enable
- if true, vertical mirroring is enabled
isHorzMirror
public boolean isHorzMirror()
- Returns the horizontal mirroring state.
- Returns:
- true, if the sprite is mirrored horizontally; otherwise false
isVertMirror
public boolean isVertMirror()
- Returns the vertical mirroring state.
- Returns:
- true, if the sprite is mirrored vertically; otherwise false
setActEnabled
public void setActEnabled(boolean enable)
- Enable/disable the invocation of act() in every simulation cycle.
- Parameters:
enable
- if true, act() is invoked; otherwise act() is not invoked
isActEnabled
public boolean isActEnabled()
- Returns true, if act() is invoked in every simulation cycle.
- Returns:
- true (default), if act() is called; false if the invokation of act() is disabled
setActorCollisionEnabled
public void setActorCollisionEnabled(boolean enable)
- Enable/disable the detection of collisions with the actor collision candidates.
- Parameters:
enable
- if true (default), collisions will be notified
isActorCollisionEnabled
public boolean isActorCollisionEnabled()
- Returns true, if collision notification between actors is enabled.
- Returns:
- true, if collision detection is enabled
setTileCollisionEnabled
public void setTileCollisionEnabled(boolean enable)
- Enable/disable the detection of collisions with the tile collision candidates.
- Parameters:
enable
- if true (default), collisions will be notified
isTileCollisionEnabled
public boolean isTileCollisionEnabled()
- Returns true, if collision notification between tiles is enabled.
- Returns:
- true, if collision detection is enabled
getCollisionActorsInRange
public java.util.ArrayList<Actor> getCollisionActorsInRange(double radius,
java.lang.Class clazz,
int spriteId)
- Returns all collision candidates who belongs to a given class whose collision areas
of the image with given sprite id intersects the circle with specified radius. Also actors whose cell locations are outside the visible grid are considered.
Requires that the actor has been added to the game grid.
- Parameters:
radius
- the radius of the circle around the center of the current location in (fractional) cell unitsclazz
- the clazz the actors must belong to, if null, all actors are considered
- Returns:
- the list of actors within the given distance
getNeighbours
public java.util.ArrayList<Actor> getNeighbours(double distance,
java.lang.Class clazz)
- Returns all actors of specified class in a specified distance.
The distance defines a circle around the current cell center. All actors in cells that intersects
with this circle are returned. Also cells outside the visible grid are considered.
To restrict this list to actors inside the grid, use isInGrid().
To get the 8 nearest neighbours, use distance = 1, to exclude diagonal
locations, use distance = 0.5;
Actors at the current location are not considered.
Requires that the actor has been added to the game grid.
- Parameters:
distance
- the distance in (fractional) cell units publicclazz
- the class of the actors to look for; if null actors of all classes are included
getNeighbours
public java.util.ArrayList<Actor> getNeighbours(double distance)
- Returns all actors in a specified distance.
The distance defines a circle around the current cell center. All actors in cells that intersects
with this circle are returned. Also cells outside the visible grid are considered.
To restrict this list to actors inside the grid, use isInGrid().
To get the 6 nearest neighbours, use distance = 1, to exlude diagonal
locations, use distance = 0.5;
Actors at the current location are not considered.
- Parameters:
distance
- the distance in (fractional) cell units public
isRotatable
public boolean isRotatable()
- Returns whether the actor is rotatable or not.
- Returns:
- true, if rotatable, e.g. image rotates when direction changes
setCollisionRectangle
public void setCollisionRectangle(int spriteId,
java.awt.Point center,
int width,
int height)
- Selects the rectangle (in pixel units) relative to the sprite image that is used for
collision detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(For even image pixel width or height, the center is half pixel width
to the left or resp. to the top).
Any collision types defined earlier are removed.
- Parameters:
spriteId
- the id of the spritecenter
- the rectangle center (zero at image center)width
- the width in pixel units of the rectangle (in x-direction)height
- the height in pixel units of the rectangle (in y-direction)
setCollisionRectangle
public void setCollisionRectangle(java.awt.Point center,
int width,
int height)
- Same as setCollisionRectangle(int spriteId, Point center, int width, int height)
for spriteId = 0
- Parameters:
center
- the rectangle center (zero at image center)width
- the width in pixel units of the rectangle (in x-direction)height
- the height in pixel units of the rectangle (in y-direction)
setCollisionCircle
public void setCollisionCircle(int spriteId,
java.awt.Point center,
int radius)
- Selects the circle (in pixel units) relative to the sprite image that is used for
collision detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(for even image pixel width or height, the center is half pixel width
to the left or resp. to the top).
Any collision types defined earlier are removed.
- Parameters:
spriteId
- the id of the spritecenter
- circle center (zero at image center)radius
- the radius of the circle (in pixel units)
setCollisionCircle
public void setCollisionCircle(java.awt.Point center,
int radius)
- Same as setCollisionCircle(int spriteId, Point center, int radius)
for spriteId = 0.
- Parameters:
center
- the circle center (zero at image center)radius
- the radius of the circle (in pixel units)
setCollisionLine
public void setCollisionLine(int spriteId,
java.awt.Point startPoint,
java.awt.Point endPoint)
- Selects the line segment (in pixel units) relative to the sprite image that is used for
collision detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(for even image pixel width or height, the center is half pixel width
to the left or resp. to the top).
Any collision types defined earlier are removed.
- Parameters:
spriteId
- the id of the spritestartPoint
- the start point of the line (zero at image center)endPoint
- the end point of the line (zero at image center)
setCollisionLine
public void setCollisionLine(java.awt.Point startPoint,
java.awt.Point endPoint)
- Same as setCollisionLine(int spriteId, Point startPoint, Point endPoint)
for spriteId = 0.
- Parameters:
startPoint
- the start point of the line (zero at image center)endPoint
- the end point of the line (zero at image center)
setCollisionSpot
public void setCollisionSpot(int spriteId,
java.awt.Point spot)
- Selects the hot spot (in pixel units) relative to the sprite image that is used for
collision detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(for even image pixel width or height, the center is half pixel
width to the left or resp. to the top).
Any collision types defined earlier are removed.
- Parameters:
spriteId
- the id of the spritespot
- the hot spot (zero at image center)
setCollisionSpot
public void setCollisionSpot(java.awt.Point spot)
- Same as setCollisionSpot(int spriteId, Point spot)
for spriteId = 0.
- Parameters:
spot
- the hot spot (zero at image center)
setCollisionImage
public void setCollisionImage(int spriteId)
- Selects collision detection on non-transparent pixels of the image.
Due to performance reasons only available if the collision partner
detects collision using spot, circle or line detection.
Any collision types defined earlier are removed.
- Parameters:
spriteId
- the id of the sprite
setCollisionImage
public void setCollisionImage()
- Same as setCollisionImage(int spriteId) for spriteId = 0.
setOnTop
public void setOnTop()
- Sets the actor at the first place in the scene of actor class.
Consequently the actor act() method will be called first and the actor image
will be drawn on top of all other actor images for this class. The order
of the other actors remains unchanged. To change the act or paint order of
the actors class, use GameGrid.setActOrder() or GameGrid.setPaintOrder().
Requires that the actor has been added to the game grid.
If you want to change the paint order of actors in different actor classes,
use GameGrid.setPaintOrder().
- See Also:
GameGrid.setPaintOrder(Class... classes)
setOnBottom
public void setOnBottom()
- Sets the actor at the last place in the scene of the actor class.
Consequently the actor act() method will be called last and the actor image
will be drawn on the bottom of all other actor images for this class. The order
of the other actors remains unchanged. To change the act or paint order of
the actors class, use GameGrid.setActOrder() or GameGrid.setPaintOrder().
Requires that the actor has been added to the game grid.
If you want to change the paint order of actors in different actor classes,
use GameGrid.setPaintOrder().
- See Also:
GameGrid.setPaintOrder(Class... classes)
getNbCycles
public int getNbCycles()
- Returns the number of simulation cycles since last reset.
- Returns:
- the number of simulation cycles
delay
public static void delay(long time)
- Delay execution for the given amount of time.
- Parameters:
time
- the delay time (in ms)
showNextSprite
public void showNextSprite()
- Increases the id of the currently visible sprite and makes this
sprite visible.
If spriteId reaches nbSprites - 1 the next sprite id will be 0.
If spriteId is -1 (sprite invisible) the next sprite id is 0.
showPreviousSprite
public void showPreviousSprite()
- Decreases the id of the currently visible sprite and makes this
sprite visible.
If spriteId reaches 0 the previous sprite id will be nbSprites - 1.
If spriteId is -1 (sprite invisible) the previous sprite id is still -1.
getCurrentImage
public java.awt.image.BufferedImage getCurrentImage()
- Returns the buffered image of the currently visible sprite picture.
If the actor is rotatable, this is the rotated image and it's size
(bounding rectangle) is bigger than the originally loaded image.
- Returns:
- the buffered image of the displayed sprite picture.
getImage
public java.awt.image.BufferedImage getImage(int spriteId)
- Returns the buffered image of the originally loaded sprite with
given sprite id. Unmodified when the actor is rotatable.
- Returns:
- the buffered image of the loaded sprite.
getImage
public java.awt.image.BufferedImage getImage()
- Returns the buffered image of the originally loaded sprite with
id = 0. Unmodified when the actor is rotatable.
- Returns:
- the buffered image of the loaded sprite.
getPixelColor
public java.awt.Color getPixelColor(java.awt.Point pt)
- Returns the color of the currently visible sprite image at given
pixel position ((0,0) at upper left vertex, x-axis to the right,
y-axis downwards).
- Parameters:
pt
- the point where to look for the color
- Returns:
- the image color of the given point returned by BufferedImage.getRGB()
getPixelLocation
public java.awt.Point getPixelLocation()
- Returns the location of the actor center in pixel coordinates taking
into account the current location offset (default offset is 0).
- Returns:
- the pixel coordinates with respect to the game grid window
(origin at upper left vertex, x-axis to the left, y-axis downward);
null, if the actor is not yet added to the game grid
- See Also:
setLocationOffset(Point locationOffset)
getWidth
public int getWidth(int spriteId)
- Returns the width of the sprite with given id.
This is the width of the originally loaded sprited image. (For
rotatable actors the bounding rectangle is increased to give space
for the rotated images.)
- Parameters:
spriteId
- the id of the sprite
- Returns:
- The width in pixels of this sprite
getHeight
public int getHeight(int spriteId)
- Returns the height of the sprite with given id.
This is the height of the originally loaded sprited image. (For
rotatable actors the bounding rectangle is increased to give space
for the rotated images.)
- Parameters:
spriteId
- the id of the sprite
- Returns:
- The height in pixels of this sprite
getRotatedPosition
public static GGVector getRotatedPosition(GGVector position,
java.awt.Point center,
double angle)
- Returns a new position vector of given position vector
rotated with given center point by given angle.
- Parameters:
position
- the vector to the current positioncenter
- the rotation center pointangle
- the rotating angle (in degrees, positive clockwise)
- Returns:
- the position (vector with double precision) to the rotated position
rotate
public void rotate(Location centerLoc,
double angle)
- Rotates the actor with given rotation center location by the given angle.
The rotated location is approximate due to the grid resolution.
If a precise sequence of rotations with the same rotation center is needed,
use getRotatedPosition(Point center, GGVector position, double angle)
with a global center and position.
- Parameters:
centerLoc
- the rotation center locationangle
- the rotation angle (in degrees, positive clockwise)
rotate
public void rotate(java.awt.Point center,
double angle)
- Rotates the actor with given rotation center point by given angle.
The rotated location is approximate due to the grid resolution.
If a precise sequence of rotations with the same rotation center is needed,
use getRotatedPosition(Point center, GGVector position, double angle)
with a global center and position.
- Parameters:
center
- the rotation center pointangle
- the rotation angle (in degrees, positive clockwise)
addMouseTouchListener
public void addMouseTouchListener(GGMouseTouchListener listener,
int mouseEventMask)
- Same as addMouseTouchListener(listener, mouseEventMask, onTopOnly)
with onTopOnly = false.
- Parameters:
listener
- the GGMouseTouchListener to registermouseEventMask
- an OR-combinaton of constants defined in class GGMouse
addMouseTouchListener
public void addMouseTouchListener(GGMouseTouchListener listener,
int mouseEventMask,
boolean onTopOnly)
- Add a GGMouseTouchListener to get notifications when the mouse
interacts with the mouse touch area.
Only the events defined as OR-combination in the specified mask
are notified. GGMouse.enter and GGMouse.leave events are produced with
respect to the mouse touch area. Touch area types available: IMAGE
(default, events on non-transparent pixels of sprite image),
RECTANGLE, CIRCLE. The non-default types can be selected for each sprite ID
with Actor.setMouseTouchRectangle(), Actor.setMouseTouchCircle().
The mouse must be enabled and the mouse event not "consumed"
by other mouse event callbacks. The sequence of events from several
registered listeners is not previsible.
- Parameters:
listener
- the GGMouseTouchListener to registermouseEventMask
- an OR-combinaton of constants defined in class GGMouseonTopOnly
- if true, enable mouse touch event for the actor at top of others
(painted last) only; otherwise touch event of all actors is enabled
setMouseTouchRectangle
public void setMouseTouchRectangle(int spriteId,
java.awt.Point center,
int width,
int height)
- Selects the rectangle (in pixel units) relative to the sprite image that is used for
mouse touch detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(For even image pixel width or height, the center is half pixel width
to the left or resp. to the top).
Any touch type defined earlier is replaced.
- Parameters:
spriteId
- the id of the spritecenter
- the rectangle center (zero at image center)width
- the width in pixel units of the rectangle (in x-direction)height
- the height in pixel units of the rectangle (in y-direction)
setMouseTouchRectangle
public void setMouseTouchRectangle(java.awt.Point center,
int width,
int height)
- Same as setTouchRectangle(int spriteId, Rectangle rect)
for all sprites of this actor.
- Parameters:
center
- the rectangle center (zero at image center)width
- the width in pixel units of the rectangle (in x-direction)height
- the height in pixel units of the rectangle (in y-direction)
setMouseTouchCircle
public void setMouseTouchCircle(int spriteId,
java.awt.Point center,
int radius)
- Selects the circle (in pixel units) relative to the sprite image that is used for
mouse touch detection. The following coordinate system is used:
x-axis to the left, y-axis downward, zero at image center
(for even image pixel width or height, the center is half pixel width
to the left or resp. to the top).
Any interaction type defined earlier is replaced.
- Parameters:
spriteId
- the id of the spritecenter
- circle center (zero at image center)radius
- the radius of the circle (in pixel units)
setMouseTouchCircle
public void setMouseTouchCircle(java.awt.Point center,
int radius)
- Same as setMouseTouchCircle(int spriteId, Point center, int radius)
for all sprites of this actor.
- Parameters:
center
- circle center (zero at image center)radius
- the radius of the circle (in pixel units)
setMouseTouchImage
public void setMouseTouchImage(int spriteId)
- Selects the non-transparent pixels of the sprite image for
mouse touch detection. This is the default detection
type when the GGMouseInteractionListener is registered.
Any interaction type defined earlier is replaced.
setMouseTouchImage
public void setMouseTouchImage()
- Same as setMouseTouchImage(int spriteId) for all sprites of this actor.
setMouseTouchEnabled
public void setMouseTouchEnabled(boolean enable)
- Enable/disable the detection of mouse interactions.
- Parameters:
enable
- if true, mouse interactions will be notified
getScaledImage
public java.awt.image.BufferedImage getScaledImage(int spriteId,
double factor,
double angle)
- Returns the sprite image scaled by the given factor and rotated to the
given angle.
The returned image can be used to create a new actor with a zoomed and
rotated image.
If rotation angle != 0, the size of the returned buffer image is enlarged
to take place for the rotated image.
- Parameters:
spriteId
- the sprite id of the actor's sprite imagefactor
- the zoom factor (>1 zoom-in, <1 zoom-out)angle
- the rotation angle (in degrees clockwise, 0 to east)
- Returns:
- the transformed image
getScaledImage
public java.awt.image.BufferedImage getScaledImage(double factor,
double angle)
- Same as getScaledImage(int spriteId, double factor, double angle)
with spriteId = 0.
- Parameters:
factor
- the zoom factor (>1 zoom-in, <1 zoom-out)angle
- the rotation angle (in degrees clockwise, 0 to east)
- Returns:
- the transformed image
getScaledImage
@Deprecated
public static java.awt.image.BufferedImage getScaledImage(java.awt.image.BufferedImage bi,
double factor,
double angle)
- Deprecated. Use GGBitmap.getScaledImage instead.
GGBitmap.getScaledImage(BufferedImage bi, double factor, double angle)
- Transforms the given buffered image by scaling by the given factor and
rotating by the given angle.
- Parameters:
bi
- the buffered image to transformfactor
- the zoom factor (>1 zoom-in, <1 zoom-out)angle
- the rotation angle (in degrees clockwise)
- Returns:
- the transformed image
getNbSprites
public int getNbSprites()
- Returns number of sprites.
- Returns:
- the number of sprites
isRemoved
public boolean isRemoved()
- Returns true, if the actor has been removed (by calling removeSelf() or
GameGrid.removeActor()). If the actor was never part of the game grid
or is added again to the game grid after being removed, returns false.
- Returns:
- true, if the actor has been removed
displace
public void displace(double ds)
- Increases the current double displace position in the
current direction to the given double distance and moves the actor
in the cell that contains the given coordinates. Sets the location
offset accordingly.
The displace position uses a double coordinate system corresponing to
the integer pixel coordinates. This method is convenient to move
the actor as precise as possible on a straight line even in a coarse grid.
- Parameters:
ds
- the distance to displace the actor; if negative, displace in
opposite direction
getDisplacePosition
public java.awt.geom.Point2D.Double getDisplacePosition()
- Returns the current displace position.
- Returns:
- the current displace position
setDisplacePosition
public void setDisplacePosition(java.awt.geom.Point2D.Double displacePosition)
- Sets the current displace position and moves the actor in the cell that
contains the given coordinates. Sets the location offset accordingly.
- Parameters:
displacePosition
- the double coordinates of the new position