sofia.micro.greenfoot
Class Actor

java.lang.Object
  extended by greenfoot.sofiainternal.Actor
      extended by sofia.graphics.Shape
          extended by sofia.graphics.ImageShape
              extended by sofia.micro.Actor
                  extended by sofia.micro.greenfoot.Actor

public class Actor
extends Actor

A small "adaptor" class that provides Greenfoot-style methods for some Actor features. It is intended to provide for source-level compatibility of some Greenfoot examples.

Version:
$Date: 2012/08/06 11:13 $
Author:
Stephen Edwards, Last changed by $Author: edwards $

Constructor Summary
Actor()
          Create a new Actor.
Actor(boolean scaleToCell)
          Create a new Actor.
Actor(java.lang.String nickName)
          Create a new Actor.
Actor(java.lang.String nickName, boolean scaleToCell)
          Create a new Actor.
 
Method Summary
 GreenfootImage getGreenfootImage()
          Returns the image used to represent this actor, as a GreenfootImage object.
protected
<MyActor extends Actor>
java.util.Set<MyActor>
getNeighbours(float distance, boolean diagonal, java.lang.Class<MyActor> cls)
          Return the neighbors to this object within a given distance.
 World getWorld()
          Return the world that this actor lives in.
 void setLocation(int x, int y)
          Assign a new location for this actor.
 
Methods inherited from class sofia.micro.Actor
act, addedToWorld, addOther, getGridX, getGridY, getImage, getIntersectingObjects, getNeighbors, getNickName, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getShape, move, remove, setBounds, setGridLocation, setGridX, setGridY, setImage, setImage, setNickName, setPosition, setPosition, setPositionAnchor, setPositionAnchor, setRotation, setX, setY, toString, turn, turnTowards, turnTowards
 
Methods inherited from class sofia.graphics.ImageShape
getSourceBounds, setBitmap, setSourceBounds, setSourceBounds
 
Methods inherited from class sofia.graphics.Shape
conditionallyRelayout, conditionallyRepaint, contains, contains, extendsOutside, getAlpha, getBounds, getColor, getHeight, getPosition, getPositionAnchor, getRotation, getRotationPivot, getShapeParent, getWidth, getX, getY, getZIndex, intersects, isInFrontOf, isVisible, move, notifyParentOfPositionChange, onBoundsResolved, rotateBy, setAlpha, setColor, setRotation, setRotation, setVisible, setZIndex
 
Methods inherited from class greenfoot.sofiainternal.Actor
_gf_addToWorld, _gf_getBoundingXs, _gf_getBoundingYs, _gf_getDelegate, _gf_getImage, _gf_getIntersectingObjects, _gf_getNeighbours, _gf_getObjectsAtOffset, _gf_getObjectsInRange, _gf_getOneIntersectingObject, _gf_getOneObjectAtOffset, _gf_getRotation, _gf_getX, _gf_getY, _gf_setImage, _gf_setImage, _gf_setLocation, _gf_setRotation, _gf_turn, addedToWorld, containsPoint, intersects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Actor

public Actor()
Create a new Actor. By default, this actor's image will be scaled to the size of a single grid cell, preserving aspect ratio.


Actor

public Actor(java.lang.String nickName)
Create a new Actor. By default, this actor's image will be scaled to the size of a single grid cell, preserving aspect ratio.

Parameters:
nickName - The nickname for this actor.

Actor

public Actor(boolean scaleToCell)
Create a new Actor.

Parameters:
scaleToCell - If true, the Actor's image will be scaled to the dimensions of a single World grid cell, while preserving aspect ratio. If false, the image will be sized relative to the underlying bitmap or shape.

Actor

public Actor(java.lang.String nickName,
             boolean scaleToCell)
Create a new Actor.

Parameters:
nickName - The nickname for this actor.
scaleToCell - If true, the Actor's image will be scaled to the dimensions of a single World grid cell, while preserving aspect ratio. If false, the image will be sized relative to the underlying bitmap or shape.
Method Detail

getWorld

public World getWorld()
Description copied from class: Actor
Return the world that this actor lives in.

Overrides:
getWorld in class Actor
Returns:
The world.

setLocation

public void setLocation(int x,
                        int y)
Assign a new location for this actor. This moves the actor to the specified location. The location is specified as the coordinates of a cell in the world.

Parameters:
x - Location index on the x-axis.
y - Location index on the y-axis.
See Also:
Actor.move(int)

getNeighbours

protected <MyActor extends Actor> java.util.Set<MyActor> getNeighbours(float distance,
                                                                       boolean diagonal,
                                                                       java.lang.Class<MyActor> cls)
Return the neighbors to this object within a given distance. This method considers only logical location, ignoring extent of the image. Thus, it is most useful in scenarios where objects are contained in a single cell.

All cells that can be reached in the number of steps given in 'distance' from this object are considered. Steps may be only in the four main directions, or may include diagonal steps, depending on the 'diagonal' parameter. Thus, a distance/diagonal specification of (1,false) will inspect four cells, (1,true) will inspect eight cells.

Type Parameters:
MyActor - The type of actor to look for, as specified in the cls parameter.
Parameters:
distance - Distance (in cells) in which to look for other objects.
diagonal - If true, include diagonal steps.
cls - Class of objects to look for (passing 'null' will find all objects).
Returns:
A set of all neighbors found.

getGreenfootImage

public GreenfootImage getGreenfootImage()
Returns the image used to represent this actor, as a GreenfootImage object. This image can be modified to change the actor's appearance.

Returns:
The object's image.


Greenfoot homepage