Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jgame
Class JGObject

    java.lang.Object
      jgame.JGObject

Direct Known Subclasses:
  StdDungeonMonster, StdDungeonPlayer, StdMazeMonster, StdMazePlayer, StdScoring

    public class JGObject

extends java.lang.Object

Superclass for game objects, override to define animated game objects. When an object is created, it is automatically registered with the currently running engine. The object will become active only after the frame ends. The object is managed by the engine, which will display it and call the move and hit methods when appropriate. Call remove() to remove the object. It will be removed after the frame ends. Use isAlive() to see if the object has been removed or not.

Each object corresponds to one image. The object's appearance can be changed using setImage or any of the animation functions. If you want multi-image objects, use multiple objects and co-reference them using regular references or using JGEngine's getObject(). You can also define your own paint() method to generate any appearance you want.

Objects have a pointer to the engine by which they are managed (eng). This can be used to call the various useful methods in the engine. Alternatively, the objects can be made inner classes of your JGEngine class, so that they have direct access to all JGEngine methods.

The object remembers some of the state of the previous frame (in particular the previous position and bounding boxes), so that corrective action can be taken after something special happened (such as bumping into a wall).

Objects have a direction and speed built in. After their move() method finishes, their x and y position are incremented with the given speed/direction. Speed may be used as absolute value (leave the direction at 1), or as a value relative to the direction (the movement is speed*dir).

Objects can be suspended, which may be useful for having them sleep until they come into view. When suspended, they are invisible, and their move, hit, and paint methods are not called. Also, they will not expire. They can still be counted by countObjects and removed by removeObjects, if you choose to do so. By default, objects resume operation when they enter the view. This can be disabled by means of the resume_in_view setting. An object that has suspend_off_view enabled will be suspended immediately at creation when it is off view.

Field Summary
`int` | `colid` Collision ID
`JGEngine` | `eng` You can use this to call methods in the object's engine.
`static int` | `expire_never` Expiry value: never expire.
`static int` | `expire_off_pf` Expiry value: expire when off playfield.
`static int` | `expire_off_view` Expiry value: expire when out of view.
`int` | `expiry` Number of move() steps before object removes itself, -1 (default) is never; -2 means expire when off-playfield, -3 means expire when off-view, -4 means suspend when off-view, -5 means suspend when off-view and expire when off-playfield.
`boolean` | `resume_in_view` If true, object will automatically start() when it is suspended and in view.
`static int` | `suspend_off_view` Expiry value: suspend when out of view.
`static int` | `suspend_off_view_expire_off_pf` Expiry value: suspend when out of view and expire when out of playfield.
`double` | `x` Object position
`int` | `xdir` Object direction, is multiplied with speed; default=1
`double` | `xspeed` Object speed; default=0
`double` | `y` Object position
`int` | `ydir` Object direction, is multiplied with speed; default=1
`double` | `yspeed` Object speed; default=0

Constructor Summary
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname)` Create object.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, double xspeed, double yspeed)` Create object with given absolute speed.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, double xspeed, double yspeed, int expiry)` Create object with given absolute speed and expiry.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int expiry)` Create object with given expiry.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int xdir, int ydir, double xspeed, double yspeed, int expiry)` Create object with given direction/speed, expiry.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int tilebbox_x, int tilebbox_y, int tilebbox_width, int tilebbox_height)` Create object with given tile bbox.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int tilebbox_x, int tilebbox_y, int tilebbox_width, int tilebbox_height, double xspeed, double yspeed)` Create object with given tile bbox and absolute speed.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int tilebbox_x, int tilebbox_y, int tilebbox_width, int tilebbox_height, double xspeed, double yspeed, int expiry)` Create object with given tile bbox, absolute speed, expiry.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int tilebbox_x, int tilebbox_y, int tilebbox_width, int tilebbox_height, int expiry)` Create object with given tile bbox and expiry.
`JGObject(java.lang.String name, boolean unique_id, double x, double y, int collisionid, java.lang.String gfxname, int tilebbox_x, int tilebbox_y, int tilebbox_width, int tilebbox_height, int xdir, int ydir, double xspeed, double yspeed, int expiry)` Create object with given tile bbox, direction/speed, expiry.

Method Summary
`static boolean` | `and(int value, int mask)` A Boolean AND shorthand to use for collision; returns (value&mask) != 0.
`int` | `checkBGCollision(double xofs, double yofs)` Get OR of Tile Cids of the object's current tile bbox at the current position, when offset by the given offset.
`int` | `checkBGCollision(java.awt.Rectangle r)` Check collision of tiles within given rectangle, return the OR of all cids found.
`void` | `clearAnim()` Clear the animation, the object's current image will remain.
`void` | `clearBBox()` Clear bbox definition so that we use the image bbox again.
`void` | `clearTileBBox()` Clear tile bbox definition so that we use the regular bbox again.
`void` | `dbgPrint(java.lang.String msg)` Print a message to the debug channel, using the object ID as source
`java.lang.String` | `getAnimId()` Get the ID of the currently running animation.
`java.awt.Rectangle` | `getBBox()` Get object collision bounding box in pixels.
`java.awt.Point` | `getCenterTile()` Get the top left center tile of the object (that is, the x and y of getCenterTiles()).
`java.awt.Rectangle` | `getCenterTiles()` Get the tile indices spanning the tiles that the object has the most overlap with.
`java.lang.String` | `getGraphic()` Get object's current animation ID, or image ID if not defined.
`java.awt.Rectangle` | `getImageBBox()` Get collision bounding box of object's image (same as object's default bbox, note that the offset is (0,0) here).
`java.awt.Rectangle` | `getLastBBox()` Get object collision bounding box in pixels of previous frame.
`java.awt.Rectangle` | `getLastCenterTiles()`
`java.awt.Rectangle` | `getLastTileBBox()` Get tile collision bounding box of previous frame.
`java.awt.Rectangle` | `getLastTiles()` Get the tile index coordinates of the object's previous tile bbox.
`double` | `getLastX()` Get x position of previous frame.
`double` | `getLastY()` Get y position of previous frame.
`java.lang.String` | `getName()` Get object's ID
`java.awt.Rectangle` | `getTileBBox()` Get tile collision bounding box in pixels.
`java.awt.Rectangle` | `getTiles()` Get the tile index coordinates of all the tiles that the object's tile bbox overlaps with.
`java.awt.Point` | `getTopLeftTile()` Get the topleftmost tile of the object.
`void` | `hit_bg(int tilecid)` Override to handle tile collision; default is do nothing.
`void` | `hit_bg(int tilecid, int tx, int ty)` Override to handle tile collision; default is do nothing.
`void` | `hit_bg(int tilecid, int tx, int ty, int txsize, int tysize)` Override to handle tile collision; default is do nothing.
`void` | `hit(JGObject obj)` Override to handle collision; default is do nothing.
`boolean` | `isAlive()` Check if object is still active, or has already been removed.
`boolean` | `isBottomAligned(double margin)` Returns true if the bottom of the object's tile bbox is within margin of being tile grid aligned.
`boolean` | `isInView(int marginx, int marginy)` Margin is the margin beyond which the object is considered off-view.
`boolean` | `isLeftAligned(double margin)` Returns true if the left of the object's tile bbox is within margin of being tile grid aligned.
`boolean` | `isOnPF(int marginx, int marginy)` Margin is the margin beyond which the object is considered off the playfield.
`boolean` | `isOnScreen(int marginx, int marginy)` Deprecated. Use isOnPF and isInView according to your situation.
`boolean` | `isRightAligned(double margin)` Returns true if the right of the object's tile bbox is within margin of being tile grid aligned.
`boolean` | `isSuspended()` Check if object is suspended.
`boolean` | `isTopAligned(double margin)` Returns true if the top of the object's tile bbox is within margin of being tile grid aligned.
`boolean` | `isXAligned()` Returns true if x is distance xspeed-epsilon away from being grid aligned.
`boolean` | `isXAligned(double margin)` Returns true if x is within margin of being tile grid aligned.
`boolean` | `isYAligned()` Returns true if y is distance yspeed-epsilon away from being grid aligned.
`boolean` | `isYAligned(double margin)` Returns true if y is within margin of being tile grid aligned.
`void` | `move()` Override to implement automatic move; default is do nothing.
`void` | `paint()` Override to define custom paint actions.
`void` | `remove()` Mark object for removal, ignore if already removed.
`void` | `resetAnim()` Reset the animation's state to the start state.
`void` | `resetAnim(java.lang.String anim_id)` Always set the animation to the given default animation definition, resetting any changes or updates made to the animation.
`void` | `resume()` Resume from suspended state, if suspended.
`void` | `setAnim(java.lang.String anim_id)` Set the animation to the given default animation definition, or leave it as it was if the anim_id is unchanged.
`void` | `setAnimPingpong(boolean pingpong)`
`void` | `setAnimSpeed(double speed)` Set animation speed; speed may be less than 0, indicating that animation should go backwards.
`void` | `setBBox(int x, int y, int width, int height)` Set bbox definition to override the image bbox.
`void` | `setDir(int xdir, int ydir)` Set direction.
`void` | `setDirSpeed(int xdir, int ydir, double speed)` Set speed and direction in one go.
`void` | `setDirSpeed(int xdir, int ydir, double xspeed, double yspeed)` Set speed and direction in one go.
`void` | `setGraphic(java.lang.String gfxname)` Set ID of animation or image to display.
`void` | `setImage(java.lang.String imgname)` Set ID of image to display; clear animation.
`void` | `setPos(double x, double y)`
`void` | `setResumeMode(boolean resume_in_view)` Set resume condition.
`void` | `setSpeed(double speed)` Set relative speed; the value is copied into xspeed,yspeed.
`void` | `setSpeed(double xspeed, double yspeed)` Set relative speed; the values are copied into xspeed,yspeed.
`void` | `setSpeedAbs(double xspeed, double yspeed)` Set absolute speed.
`void` | `setTileBBox(int x, int y, int width, int height)`
`void` | `snapBBoxToGrid(double gridsnapx, double gridsnapy, boolean snap_right, boolean snap_bottom)` Snap an object's tile bbox corner to grid; floats are rounded down.
`void` | `snapToGrid()` Snap object to grid using the default gridsnap margin of (xspeed-epsilon, yspeed-epsilon), corresponding to the default is...Aligned margin.
`void` | `snapToGrid(double gridsnapx, double gridsnapy)` Snap object to grid.
`void` | `startAnim()`
`void` | `stopAnim()`
`void` | `suspend()` Suspend object until either resume is called or, if resume_in_view is true, when it comes into view.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### expire_never

    public static final int expire_never

  Expiry value: never expire.

  See Also:
    Constant Field Values

### expire_off_pf

    public static final int expire_off_pf

  Expiry value: expire when off playfield.

  See Also:
    Constant Field Values

### expire_off_view

    public static final int expire_off_view

  Expiry value: expire when out of view.

  See Also:
    Constant Field Values

### suspend_off_view

    public static final int suspend_off_view

  Expiry value: suspend when out of view.

  See Also:
    Constant Field Values

### suspend_off_view_expire_off_pf

    public static final int suspend_off_view_expire_off_pf

  Expiry value: suspend when out of view and expire when out of playfield.

  See Also:
    Constant Field Values

### x

    public double x

  Object position

### y

    public double y

  Object position

### xspeed

    public double xspeed

  Object speed; default=0

### yspeed

    public double yspeed

  Object speed; default=0

### xdir

    public int xdir

  Object direction, is multiplied with speed; default=1

### ydir

    public int ydir

  Object direction, is multiplied with speed; default=1

### colid

    public int colid

  Collision ID

### expiry

    public int expiry

  Number of move() steps before object removes itself, -1 (default) is never; -2 means expire when off-playfield, -3 means expire when off-view, -4 means suspend when off-view, -5 means suspend when off-view and expire when off-playfield. See also the expire_ and suspend_ constants.

### resume_in_view

    public boolean resume_in_view

  If true, object will automatically start() when it is suspended and in view. Default is true.

### eng

    public JGEngine eng

  You can use this to call methods in the object's engine. Even handier is to have the objects as inner class of the engine.

Constructor Detail

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname)

  Create object.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int expiry)

  Create object with given expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int tilebbox_x,
                    int tilebbox_y,
                    int tilebbox_width,
                    int tilebbox_height)

  Create object with given tile bbox.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int tilebbox_x,
                    int tilebbox_y,
                    int tilebbox_width,
                    int tilebbox_height,
                    int expiry)

  Create object with given tile bbox and expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    double xspeed,
                    double yspeed)

  Create object with given absolute speed.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    double xspeed,
                    double yspeed,
                    int expiry)

  Create object with given absolute speed and expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int tilebbox_x,
                    int tilebbox_y,
                    int tilebbox_width,
                    int tilebbox_height,
                    double xspeed,
                    double yspeed)

  Create object with given tile bbox and absolute speed.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int tilebbox_x,
                    int tilebbox_y,
                    int tilebbox_width,
                    int tilebbox_height,
                    double xspeed,
                    double yspeed,
                    int expiry)

  Create object with given tile bbox, absolute speed, expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int xdir,
                    int ydir,
                    double xspeed,
                    double yspeed,
                    int expiry)

  Create object with given direction/speed, expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

### JGObject

    public JGObject(java.lang.String name,
                    boolean unique_id,
                    double x,
                    double y,
                    int collisionid,
                    java.lang.String gfxname,
                    int tilebbox_x,
                    int tilebbox_y,
                    int tilebbox_width,
                    int tilebbox_height,
                    int xdir,
                    int ydir,
                    double xspeed,
                    double yspeed,
                    int expiry)

  Create object with given tile bbox, direction/speed, expiry.

  Parameters:
    `unique_id` - append name with unique ID if unique_id set
    `gfxname` - id of animation or image, null = no image

Method Detail

### dbgPrint

    public void dbgPrint(java.lang.String msg)

  Print a message to the debug channel, using the object ID as source

### getName

    public java.lang.String getName()

  Get object's ID

### clearTileBBox

    public void clearTileBBox()

  Clear tile bbox definition so that we use the regular bbox again.

### setTileBBox

    public void setTileBBox(int x,
                            int y,
                            int width,
                            int height)

### setBBox

    public void setBBox(int x,
                        int y,
                        int width,
                        int height)

  Set bbox definition to override the image bbox.

### clearBBox

    public void clearBBox()

  Clear bbox definition so that we use the image bbox again.

### setPos

    public void setPos(double x,
                       double y)

### setSpeedAbs

    public void setSpeedAbs(double xspeed,
                            double yspeed)

  Set absolute speed. Set xdir, ydir to the sign of the supplied speed, and xspeed and yspeed to the absolute value of the supplied speed. Passing a value of exactly 0.0 sets the dir to 0.

### setDirSpeed

    public void setDirSpeed(int xdir,
                            int ydir,
                            double xspeed,
                            double yspeed)

  Set speed and direction in one go.

### setDirSpeed

    public void setDirSpeed(int xdir,
                            int ydir,
                            double speed)

  Set speed and direction in one go.

### setSpeed

    public void setSpeed(double xspeed,
                         double yspeed)

  Set relative speed; the values are copied into xspeed,yspeed.

### setSpeed

    public void setSpeed(double speed)

  Set relative speed; the value is copied into xspeed,yspeed.

### setDir

    public void setDir(int xdir,
                       int ydir)

  Set direction.

### setGraphic

    public void setGraphic(java.lang.String gfxname)

  Set ID of animation or image to display. First, look for an animation with the given ID, and setAnim if found. Otherwise, look for an image with the given ID, and setImage if found. Passing null clears the image and stops the animation.

### setImage

    public void setImage(java.lang.String imgname)

  Set ID of image to display; clear animation. Passing null clears the image.

### getGraphic

    public java.lang.String getGraphic()

  Get object's current animation ID, or image ID if not defined.

### setAnim

    public void setAnim(java.lang.String anim_id)

  Set the animation to the given default animation definition, or leave it as it was if the anim_id is unchanged. Subsequent changes made in the animation's parameters do not change the default animation definition. The changes will be preserved if another call to setAnimation is made with the same anim_id. If you want to reset the animation to the original settings, use resetAnimation().

### resetAnim

    public void resetAnim(java.lang.String anim_id)

  Always set the animation to the given default animation definition, resetting any changes or updates made to the animation. Subsequent changes made in the animation's parameters do not change the default animation definition.

### clearAnim

    public void clearAnim()

  Clear the animation, the object's current image will remain.

### getAnimId

    public java.lang.String getAnimId()

  Get the ID of the currently running animation.

### setAnimSpeed

    public void setAnimSpeed(double speed)

  Set animation speed; speed may be less than 0, indicating that animation should go backwards.

### setAnimPingpong

    public void setAnimPingpong(boolean pingpong)

### startAnim

    public void startAnim()

### stopAnim

    public void stopAnim()

### resetAnim

    public void resetAnim()

  Reset the animation's state to the start state.

### getBBox

    public java.awt.Rectangle getBBox()

  Get object collision bounding box in pixels. Has actual coordinate offset.

  Returns:
    copy of bbox in pixel coordinates, null if no bbox

### getLastBBox

    public java.awt.Rectangle getLastBBox()

  Get object collision bounding box in pixels of previous frame.

  Returns:
    pixel coordinates, null if no bbox

### getTileBBox

    public java.awt.Rectangle getTileBBox()

  Get tile collision bounding box in pixels. Bounding box has actual coordinate offset.

  Returns:
    pixel coordinates, null if no bbox

### getLastTileBBox

    public java.awt.Rectangle getLastTileBBox()

  Get tile collision bounding box of previous frame.

  Returns:
    pixel coordinates, null if no bbox

### getImageBBox

    public java.awt.Rectangle getImageBBox()

  Get collision bounding box of object's image (same as object's default bbox, note that the offset is (0,0) here).

  Returns:
    pixel coordinates, null if no bbox

### getLastX

    public double getLastX()

  Get x position of previous frame.

### getLastY

    public double getLastY()

  Get y position of previous frame.

### snapToGrid

    public void snapToGrid()

  Snap object to grid using the default gridsnap margin of (xspeed-epsilon, yspeed-epsilon), corresponding to the default is...Aligned margin.

### snapToGrid

    public void snapToGrid(double gridsnapx,
                           double gridsnapy)

  Snap object to grid.

  Parameters:
    `gridsnapx` - margin below which to snap, 0.0 is no snap
    `gridsnapy` - margin below which to snap, 0.0 is no snap

### snapBBoxToGrid

    public void snapBBoxToGrid(double gridsnapx,
                               double gridsnapy,
                               boolean snap_right,
                               boolean snap_bottom)

  Snap an object's tile bbox corner to grid; floats are rounded down. Snaps to bottom or right of object instead of top and left if the resp. flags are set. Note that bottom and right alignment means that the object's bounding box is one pixel away from crossing the tile border.

  Parameters:
    `snap_right` - snap the right hand side of the tile bbox
    `snap_bottom` - snap the bottom of the tile bbox

### getTiles

    public java.awt.Rectangle getTiles()

  Get the tile index coordinates of all the tiles that the object's tile bbox overlaps with.

  Returns:
    tile index coordinates, null if no bbox

### getLastTiles

    public java.awt.Rectangle getLastTiles()

  Get the tile index coordinates of the object's previous tile bbox.

  Returns:
    tile index coordinates, null if no tile bbox

### getCenterTiles

    public java.awt.Rectangle getCenterTiles()

  Get the tile indices spanning the tiles that the object has the most overlap with. The size of the span is always the same as size of the tile bbox in tiles. For example, if the tile bbox is 48x32 pixels and the tile size is 32x32 pixels, the size in tiles is always 1.5x1 tiles, which is rounded up to 2x1 tiles.

  Returns:
    tile index coordinates, null if no tile bbox is defined

### getLastCenterTiles

    public java.awt.Rectangle getLastCenterTiles()

  Returns:
    tile index coordinates, null if no tile bbox

### getCenterTile

    public java.awt.Point getCenterTile()

  Get the top left center tile of the object (that is, the x and y of getCenterTiles()). If the object is 1x1 tile in size, you get the center tile. If the object is larger, you get the top left tile of the center tiles.

  Returns:
    tile index coordinate, null if no tile bbox

### getTopLeftTile

    public java.awt.Point getTopLeftTile()

  Get the topleftmost tile of the object.

  Returns:
    tile index coordinate, null if no bbox

### isXAligned

    public boolean isXAligned()

  Returns true if x is distance xspeed-epsilon away from being grid aligned. If an object moves at its current xspeed, this method will always return true when the object crosses the tile alignment line, and return false when the object is snapped to grid, and then moves xspeed away from its aligned position.

### isYAligned

    public boolean isYAligned()

  Returns true if y is distance yspeed-epsilon away from being grid aligned. If an object moves at its current yspeed, this method will always return true when the object crosses the tile alignment line, and return false when the object is snapped to grid, and then moves xspeed away from its aligned position.

### isXAligned

    public boolean isXAligned(double margin)

  Returns true if x is within margin of being tile grid aligned. Epsilon is added to the margin, so that isXAligned(1.0000, 1.0000) always returns true.

### isYAligned

    public boolean isYAligned(double margin)

  Returns true if y is within margin of being tile grid aligned. Epsilon is added to the margin, so that isXAligned(1.0000, 1.0000) always returns true.

### isLeftAligned

    public boolean isLeftAligned(double margin)

  Returns true if the left of the object's tile bbox is within margin of being tile grid aligned.

### isTopAligned

    public boolean isTopAligned(double margin)

  Returns true if the top of the object's tile bbox is within margin of being tile grid aligned.

### isRightAligned

    public boolean isRightAligned(double margin)

  Returns true if the right of the object's tile bbox is within margin of being tile grid aligned. Note that right aligned means that the bbox is one pixel away from crossing the tile border.

### isBottomAligned

    public boolean isBottomAligned(double margin)

  Returns true if the bottom of the object's tile bbox is within margin of being tile grid aligned. Note that right aligned means that the bbox is one pixel away from crossing the tile border.

### checkBGCollision

    public int checkBGCollision(java.awt.Rectangle r)

  Check collision of tiles within given rectangle, return the OR of all cids found. this method just calls engine.checkBGCollision.

### checkBGCollision

    public int checkBGCollision(double xofs,
                                double yofs)

  Get OR of Tile Cids of the object's current tile bbox at the current position, when offset by the given offset.

### isOnScreen

    public boolean isOnScreen(int marginx,
                              int marginy)

  Deprecated. Use isOnPF and isInView according to your situation.

  Margin is the margin beyond which the object is considered offscreen. The tile bounding box is used as the object's size, if there is none, we use a zero-size bounding box. isOnScreen is equal to isOnPF, but is deprecated because the name is ambiguous.

  Parameters:
    `marginx` - pixel margin, may be negative
    `marginy` - pixel margin, may be negative

### isInView

    public boolean isInView(int marginx,
                            int marginy)

  Margin is the margin beyond which the object is considered off-view. The tile bounding box is used as the object's size, if there is none, we use a zero-size bounding box.

  Parameters:
    `marginx` - pixel margin, may be negative
    `marginy` - pixel margin, may be negative

### isOnPF

    public boolean isOnPF(int marginx,
                          int marginy)

  Margin is the margin beyond which the object is considered off the playfield. The tile bounding box is used as the object's size, if there is none, we use a zero-size bounding box.

  Parameters:
    `marginx` - pixel margin, may be negative
    `marginy` - pixel margin, may be negative

### and

    public static boolean and(int value,
                              int mask)

  A Boolean AND shorthand to use for collision; returns (value&mask) != 0.

### suspend

    public void suspend()

  Suspend object until either resume is called or, if resume_in_view is true, when it comes into view. A suspended object does not participate in any move, hit, or paint.

### resume

    public void resume()

  Resume from suspended state, if suspended.

### isSuspended

    public boolean isSuspended()

  Check if object is suspended.

### setResumeMode

    public void setResumeMode(boolean resume_in_view)

  Set resume condition.

  Parameters:
    `resume_in_view` - resume when in view

### isAlive

    public boolean isAlive()

  Check if object is still active, or has already been removed.

### remove

    public void remove()

  Mark object for removal, ignore if already removed. The object will be removed at the end of this moveObjects, checkCollision, or checkBGCollision action, or immediately if not inside either of these actions. You can override this to implement object disposal code, as the engine guarantees that remove is called when the object is removed. If you do so, you must call super.remove() to ensure proper removal from the system.

### move

    public void move()

  Override to implement automatic move; default is do nothing.

### hit

    public void hit(JGObject obj)

  Override to handle collision; default is do nothing.

### hit_bg

    public void hit_bg(int tilecid)

  Override to handle tile collision; default is do nothing.

### hit_bg

    public void hit_bg(int tilecid,
                       int tx,
                       int ty,
                       int txsize,
                       int tysize)

  Override to handle tile collision; default is do nothing. This method is always called when hit_bg(int) is also called, only, extra information is passed that may be useful.

### hit_bg

    public void hit_bg(int tilecid,
                       int tx,
                       int ty)

  Override to handle tile collision; default is do nothing. This method is always called when hit_bg(int) is also called, only it may be called multiple times, namely once for each tile the object collides with. The arguments pass the tile cid and position of that tile. It is always called after hit_bg(int) and hit_bg(int,int,int,int,int) have been called.

### paint

    public void paint()

  Override to define custom paint actions.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD