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). The object speed is automatically multiplied by the game speed (which has default 1.0).

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
`JGEngineInterface` | `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.
`double` | `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.
`static double` | `gamespeed` The engine's gamespeed setting, stored in a local variable for extra speed.
`boolean` | `is_suspended` Indicates if object is suspended.
`static int` | `pfheight` The engine's pfWidth/pfHeight, stored in a local variable for extra speed.
`static int` | `pfwidth` The engine's pfWidth/pfHeight, stored in a local variable for extra speed.
`static boolean` | `pfwrapx` The engine's pfWrap settings, stored in a local variable for extra speed.
`static boolean` | `pfwrapy` The engine's pfWrap settings, stored in a local variable for extra speed.
`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.
`static int` | `tileheight` The engine's tileWidth and tileHeight, stored in a local variable for extra speed.
`static int` | `tilewidth` The engine's tileWidth and tileHeight, stored in a local variable for extra speed.
`static int` | `viewheight` The engine's viewWidth and viewHeight, stored in a local variable for extra speed.
`static int` | `viewwidth` The engine's viewWidth and viewHeight, stored in a local variable for extra speed.
`static int` | `viewxofs` The engine's viewX/YOfs, stored in a local variable for extra speed.
`static int` | `viewyofs` The engine's viewX/YOfs, stored in a local variable for extra speed.
`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(JGRectangle r)` Check collision of tiles within given rectangle, return the OR of all cids found.
`int` | `checkCollision(int cid, double xofs, double yofs)` Check collision of this object with other objects, when the object position would be offset by xofs,yofs.
`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
`void` | `destroy()` Override to implement object disposal code.
`void` | `frameFinished()` Signal that a new frame has just been updated; make snapshot of object state.
`java.lang.String` | `getAnimId()` Get the ID of the currently running animation.
`JGRectangle` | `getBBox()` Get object collision bounding box in pixels.
`boolean` | `getBBox(JGRectangle bbox_copy)` Copy object collision bounding box in pixels into bbox_copy.
`JGPoint` | `getCenterTile()` Get the top left center tile of the object (that is, the x and y of getCenterTiles()).
`JGRectangle` | `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.
`JGRectangle` | `getImageBBox()` Get collision bounding box of object's image (same as object's default bbox, note that the offset is (0,0) here).
`JGRectangle` | `getImageBBoxConst()` Get collision bounding box of object's image (same as object's default bbox, note that the offset is (0,0) here).
`java.lang.String` | `getImageName()` Get name of current image.
`double` | `getLastX()` Get x position of previous frame.
`double` | `getLastY()` Get y position of previous frame.
`java.lang.String` | `getName()` Get object's ID
`JGRectangle` | `getTileBBox()` Get tile collision bounding box in pixels.
`boolean` | `getTileBBox(JGRectangle bbox_copy)` Get tile collision bounding box in pixels and store it in bbox_copy.
`JGRectangle` | `getTiles()` Get the tile index coordinates of all the tiles that the object's tile bbox overlaps with.
`JGPoint` | `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` | `isAligned()` Returns true if both isXAligned() and isYAligned() are true.
`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` | `moduloPos()` Modulo x/y position according to wrap settings.
`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` | `removeDone()` Signal to object that remove is done, don't call directly.
`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.
`static boolean` | `setEngine(JGEngineInterface engine)` Set the engine to connect to when a new object is created.
`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*gamespeed-epsilon, yspeed*gamespeed-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.
`void` | `updateAnimation(double gamespeed)` Do automatic animation.
`static void` | `updateEngineSettings()` Called automatically by the engine to signal changes to pfWrap, gameSpeed, pfWidth/Height, viewX/YOfs.

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

Field Detail

### viewwidth

    public static int viewwidth

  The engine's viewWidth and viewHeight, stored in a local variable for extra speed.

### viewheight

    public static int viewheight

  The engine's viewWidth and viewHeight, stored in a local variable for extra speed.

### tilewidth

    public static int tilewidth

  The engine's tileWidth and tileHeight, stored in a local variable for extra speed.

### tileheight

    public static int tileheight

  The engine's tileWidth and tileHeight, stored in a local variable for extra speed.

### pfwrapx

    public static boolean pfwrapx

  The engine's pfWrap settings, stored in a local variable for extra speed.

### pfwrapy

    public static boolean pfwrapy

  The engine's pfWrap settings, stored in a local variable for extra speed.

### gamespeed

    public static double gamespeed

  The engine's gamespeed setting, stored in a local variable for extra speed.

### pfwidth

    public static int pfwidth

  The engine's pfWidth/pfHeight, stored in a local variable for extra speed.

### pfheight

    public static int pfheight

  The engine's pfWidth/pfHeight, stored in a local variable for extra speed.

### viewxofs

    public static int viewxofs

  The engine's viewX/YOfs, stored in a local variable for extra speed.

### viewyofs

    public static int viewyofs

  The engine's viewX/YOfs, stored in a local variable for extra speed.

### 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 double 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.

### is_suspended

    public boolean is_suspended

  Indicates if object is suspended.

### eng

    public JGEngineInterface 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

### setEngine

    public static boolean setEngine(JGEngineInterface engine)

  Set the engine to connect to when a new object is created. This should be called only by the JGEngine implementation.

  Parameters:
    `engine` - pass null to indicate the engine has exited.
  Returns:
    true if success; false if other engine already running.

### updateEngineSettings

    public static void updateEngineSettings()

  Called automatically by the engine to signal changes to pfWrap, gameSpeed, pfWidth/Height, viewX/YOfs. The current values of these settings are stored in the JGObject local variables.

### 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

### getImageName

    public java.lang.String getImageName()

  Get name of current image.

### 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 boolean getBBox(JGRectangle bbox_copy)

  Copy object collision bounding box in pixels into bbox_copy. Has actual coordinate offset. If bounding box is not defined, bbox_copy is unchanged.

  Returns:
    false if bbox is null, true if not null

### getBBox

    public JGRectangle getBBox()

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

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

### getTileBBox

    public boolean getTileBBox(JGRectangle bbox_copy)

  Get tile collision bounding box in pixels and store it in bbox_copy. Bounding box has actual coordinate offset. If bounding box is not defined, bbox_copy is unchanged.

  Returns:
    false when bounding box is not defined, true otherwise

### getTileBBox

    public JGRectangle getTileBBox()

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

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

### getImageBBox

    public JGRectangle getImageBBox()

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

  Returns:
    copy of bbox's pixel coordinates, null if no bbox

### getImageBBoxConst

    public JGRectangle getImageBBoxConst()

  Get collision bounding box of object's image (same as object's default bbox, note that the offset is (0,0) here). Optimised version of getImageBBox(). Do not change the value of the object!

  Returns:
    *original* bbox's 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*gamespeed-epsilon, yspeed*gamespeed-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 JGRectangle getTiles()

  Get the tile index coordinates of all the tiles that the object's tile bbox overlaps with. Always returns the same temp object, so no object creation is necessary.

  Returns:
    tile index coordinates, null if no bbox

### getCenterTiles

    public JGRectangle 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. Always returns the same temp object, so no object creation is necessary.

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

### getCenterTile

    public JGPoint 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. Always returns the same temp object, so no object creation is necessary.

  Returns:
    tile index coordinate, null if no tile bbox

### getTopLeftTile

    public JGPoint getTopLeftTile()

  Get the topleftmost tile of the object. Always returns the same temp object, so no object creation is necessary.

  Returns:
    tile index coordinate, null if no bbox

### isAligned

    public boolean isAligned()

  Returns true if both isXAligned() and isYAligned() are true.

  See Also:
    `isXAligned()`, `isYAligned()`

### 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*gamespeed 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 yspeed*gamespeed 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.

### checkCollision

    public int checkCollision(int cid,
                              double xofs,
                              double yofs)

  Check collision of this object with other objects, when the object position would be offset by xofs,yofs. Returns 0 when object's bbox is not defined.

  Parameters:
    `cid` - cid mask of objects to consider, 0=any

### checkBGCollision

    public int checkBGCollision(JGRectangle r)

  Check collision of tiles within given rectangle, return the OR of all cids found. This method just calls eng.checkBGCollision; it's here because JGEngine.checkBGCollision(JGRectangle) is masked when the object is an inner class of JGEngine.

### 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. Returns 0 if tile bbox is not defined.

### 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.

### updateAnimation

    public void updateAnimation(double gamespeed)

  Do automatic animation. Is automatically called by the JGEngine implementation once for every moveObjects; normally it is not necessary to call this.

### frameFinished

    public void frameFinished()

  Signal that a new frame has just been updated; make snapshot of object state. Should only be called by the JGEngine implementation.

### moduloPos

    public void moduloPos()

  Modulo x/y position according to wrap settings. Is automatically performed by the JGEngine implementation after each moveObjects. Normally it is not necessary to call this, but it may be in special cases.

### 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. Also returns false if the object is still pending to be removed.

### removeDone

    public final void removeDone()

  Signal to object that remove is done, don't call directly. This is used by the engine to signal that the object should be finalised.

### 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.

### destroy

    public void destroy()

  Override to implement object disposal code. This method is called at the actual moment of removal.

### 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