jgame.impl
Interface JGEngineInterface

All Known Implementing Classes:
JGEngine, StdGame

public interface JGEngineInterface

Interface defining all platform-independent methods in JGEngine. It is primarily used as an internal interface for JGObjects, JGTimers, etc to the different engine implementations.


Field Summary
static int CROSSHAIR_CURSOR
          Platform-independent cursor.
static int DEFAULT_CURSOR
          Platform-independent cursor.
static int HAND_CURSOR
          Platform-independent cursor.
static java.lang.String JGameVersionString
           
static int KeyAlt
           
static int KeyBackspace
           
static int KeyCtrl
           
static int KeyDown
          Cursor keys for both regular and mobile keyboard.
static int KeyEnter
          On a mobile, pressing "*" also triggers KeyEnter.
static int KeyEsc
           
static int KeyFire
          Fire stands for a mobile key, indicating the fire button of the cursor controls.
static int KeyLeft
          Cursor keys for both regular and mobile keyboard.
static int KeyMouse1
          Keymap equivalent of mouse button.
static int KeyMouse2
          Keymap equivalent of mouse button.
static int KeyMouse3
          Keymap equivalent of mouse button.
static int KeyPound
          The mobile Pound key, equal to '#'.
static int KeyRight
          Cursor keys for both regular and mobile keyboard.
static int KeyShift
          On a mobile, the cursor control Fire is the same as shift.
static int KeyStar
          The mobile Star key, equal to '*'.
static int KeyTab
           
static int KeyUp
          Cursor keys for both regular and mobile keyboard.
static int NO_CURSOR
          Platform-independent cursor.
static int WAIT_CURSOR
          Platform-independent cursor.
 
Method Summary
 void addGameState(java.lang.String state)
          Add the given state to the game's existing state on the next frame.
 boolean and(int value, int mask)
          A Boolean AND shorthand to use for collision; returns (value&mask) != 0.
 void andTileCid(int x, int y, int and_mask)
          Modify the cid of a single tile by ANDing a bit mask, leaving the actual tile.
 double atan2(double y, double x)
          Replacement for Math.atan2 for the sake of MIDP portability.
 void checkBGCollision(int tilecid, int objcid)
          Calls all bg colliders of objects that match objid that collide with tiles that match tileid.
 int checkBGCollision(JGRectangle r)
          Check collision of tiles within given rectangle, return the OR of all cids found.
 void checkCollision(int srccid, int dstcid)
          Calls all colliders of objects that match dstcid that collide with objects that match srccid.
 int checkCollision(int cidmask, JGObject obj)
          Checks collision of objects with given cid mask with given object.
 void clearGameState()
          Set the game's main state to none, on the next frame.
 void clearKey(int key)
          Set the key status of a key to released.
 void clearLastKey()
          Clear the lastkey status.
 void clearMouseButton(int nr)
          Set state of button to released.
 int countObjects(java.lang.String prefix, int cidmask)
          Count how many objects there are with both the given name prefix and have colid&cidmask != 0.
 int countObjects(java.lang.String prefix, int cidmask, boolean suspended_obj)
          Count how many objects there are with both the given name prefix and have colid&cidmask != 0.
 int countTiles(int tilecidmask)
          Count number of tiles with given mask.
 java.lang.String dbgExceptionToString(java.lang.Throwable e)
          Convert the relevant information of an exception to a multiline String.
 void dbgPrint(java.lang.String msg)
          Print a debug message, with the main program being the source.
 void dbgPrint(java.lang.String source, java.lang.String msg)
          Print a debug message from a specific source, which is either the main program or a JGObject.
 void dbgSetDebugColor1(JGColor col)
          Set debug color 1, used for printing debug information.
 void dbgSetDebugColor2(JGColor col)
          Set debug color 2, used for printing debug information.
 void dbgSetMessageExpiry(int ticks)
          Set the number of frames a debug message of a removed object should remain on the playfield.
 void dbgSetMessageFont(JGFont font)
          Set the font for displaying debug messages.
 void dbgShowBoundingBox(boolean enabled)
          Show bounding boxes around the objects: the image bounding box (getBBox) , the tile span (getTiles), and the center tiles (getCenterTiles).
 void dbgShowException(java.lang.String source, java.lang.Throwable e)
          Print the relevant information of an exception as a debug message.
 void dbgShowFullStackTrace(boolean enabled)
          Indicates whether to show full exception stack traces or just the first lines.
 void dbgShowGameState(boolean enabled)
          Show the game state in the bottom right corner of the screen.
 void dbgShowMessagesInPf(boolean enabled)
          Output messages on playfield instead of console.
 void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed)
          Define new animation sequence.
 void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed, boolean pingpong)
          Define new animation sequence.
 void defineAudioClip(java.lang.String clipid, java.lang.String filename)
          Associate given clipid with a filename.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgmap, int mapidx, java.lang.String img_op)
          Define new sprite/tile image from map, with collision bounding box equal to the image's dimensions.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgmap, int mapidx, java.lang.String img_op, int top, int left, int width, int height)
          Define new sprite/tile image from map.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op)
          Define new sprite/tile image from a file, with collision bounding box equal to the image's dimensions.
 void defineImage(java.lang.String name, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op, int top, int left, int width, int height)
          Define new sprite/tile image from a file.
 void defineImageMap(java.lang.String mapname, java.lang.String imgfile, int xofs, int yofs, int tilex, int tiley, int skipx, int skipy)
          Define image map, a large image containing a number of smaller images to use for sprites or fonts.
 void defineImageRotated(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String srcimg, double angle)
          Define new image by rotating an already loaded image.
 void defineMedia(java.lang.String filename)
          Load a set of imagemap, image, animation, and audio clip definitions from a file.
 void destroy()
          Destroy function for deinitialising the engine properly.
 void destroyApp(boolean unconditional)
          Called by the application manager to exit app.
 void disableAudio()
          Disable audio, stop all currently playing audio.
 int displayHeight()
          Get the real display height on this device.
 int displayWidth()
          Get the real display width on this device.
 void doFrame()
          Is called every frame.
 void drawImage(double x, double y, java.lang.String imgname)
          Draw image with given ID.
 void drawImage(double x, double y, java.lang.String imgname, boolean pf_relative)
          Draw image with given ID.
 void drawImage(double x, double y, java.lang.String imgname, JGColor blend_col, double alpha, double rot, double scale, boolean pf_relative)
          Extended version of drawImage for OpenGL or Android.
 void drawImage(java.lang.String imgname, double x, double y)
          Draw image with given ID, new version.
 void drawImage(java.lang.String imgname, double x, double y, boolean pf_relative)
          Draw image with given ID, new version.
 void drawImage(java.lang.String imgname, double x, double y, boolean pf_relative, JGColor blend_col, double alpha, double rot, double scale)
          Extended version of drawImage for OpenGL or Android, new version.
 void drawImageString(java.lang.String string, double x, double y, int align, java.lang.String imgmap, int char_offset, int spacing)
          Draws a single line of text using an image map as font; text alignment is same as drawString.
 void drawImageString(java.lang.String string, double x, double y, int align, java.lang.String imgmap, int char_offset, int spacing, boolean pf_relative)
          Draws a single line of text using an image map as font; text alignment is same as drawString.
 void drawLine(double x1, double y1, double x2, double y2)
          Draw a line with current thickness and colour.
 void drawLine(double x1, double y1, double x2, double y2, boolean pf_relative)
          Draw a line with current thickness and colour.
 void drawLine(double x1, double y1, double x2, double y2, double thickness, JGColor color)
          DrawLine combined with thickness/colour setting.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered)
          Draw oval with default thickness and colour.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative)
          Draw oval with default thickness and colour.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered, double thickness, JGColor color)
          Set thickness/colour and draw oval.
 void drawPolygon(double[] x, double[] y, JGColor[] col, int len, boolean filled, boolean pf_relative)
          Draw convex polygon.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered)
          Draw rectangle in default colour and thickness.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative)
          Draw rectangle in default colour and thickness.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative, JGColor[] shadecol)
          Draw shaded rectangle.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative, JGColor[] shadecol, java.lang.String tileimage)
          Draw shaded or patterned rectangle.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, double thickness, JGColor color)
          Set colour/thickness and draw rectangle.
 void drawString(java.lang.String str, double x, double y, int align)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawString(java.lang.String str, double x, double y, int align, boolean pf_relative)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawString(java.lang.String str, double x, double y, int align, JGFont font, JGColor color)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawTile(int xi, int yi, int tileid)
          Draw tile directly on background, do not call this directly, use setTile instead.
 void enableAudio()
          Enable audio, restart any audio loops.
 boolean existsObject(java.lang.String index)
          Get object if it exists.
 void exitEngine(java.lang.String msg)
          Exit, optionally reporting an exit message.
 void fillBG(java.lang.String filltile)
          Fill the background with the given tile.
 double[] getAccelVec()
          get double[3] vector representing acceleration
 double getAccelX()
          get accelerometer vector X coordinate
 double getAccelY()
          get accelerometer vector Y coordinate
 double getAccelZ()
          get accelerometer vector Z coordinate (positive = towards user)
 Animation getAnimation(java.lang.String id)
          Get animation definition, don't call directly.
 java.lang.String getConfigPath(java.lang.String filename)
          Returns path to writable location for a file with the given name.
 double getFontHeight(JGFont font)
          Get height of given font in pixels.
 double getFrameRate()
           
 double getFrameSkip()
           
 double getGameSpeed()
          Get game speed variable.
 JGImage getImage(java.lang.String imgname)
          Gets (scaled) image directly.
 JGRectangle getImageBBox(java.lang.String imgname)
          Gets the collision bounding box of an image.
 JGPoint getImageSize(java.lang.String imgname)
          Gets (non-scaled) image's physical size directly.
 boolean getKey(int key)
          Get the key status of the given key.
 int getKeyCode(java.lang.String keydesc)
          Obtain key code from printable string describing the key, the inverse of getKeyDesc.
 java.lang.String getKeyDesc(int key)
          Get a printable string describing the key.
 int getLastKey()
          Get the keycode of the key that was pressed last, 0=none.
 char getLastKeyChar()
          Get the keycode of the key that was pressed last, 0=none.
 double getMinScaleFactor()
          Get minimum of the x and y scale factors
 boolean getMouseButton(int nr)
          Get state of button.
 boolean getMouseInside()
          Check if mouse is inside game window
 JGPoint getMousePos()
          Get current mouse position in logical coordinates, inverse projected through last set view zoom/rotate setting.
 int getMouseX()
          Get current mouse X position
 int getMouseY()
          Get current mouse Y position
 JGObject getObject(java.lang.String index)
          Get object if it exists, null if not.
 java.util.Vector getObjects(java.lang.String prefix, int cidmask, boolean suspended_obj, JGRectangle bbox)
          Query the object list for objects matching the given name prefix, CID mask, and collide with the given bounding box.
 int getOffscreenMarginX()
          Get offscreen X margin.
 int getOffscreenMarginY()
          Get offscreen Y margin.
 int getTileCid(int xidx, int yidx)
          Get collision id of tile at given tile index position.
 int getTileCid(JGPoint center, int xofs, int yofs)
          Get the tile cid of the point that is (xofs,yofs) from the tile index coordinate center.
 int getTileCid(JGRectangle tiler)
          Get the OR of the cids at the tile indexes given by tiler
 int getTileCidAtCoord(double x, double y)
          Get collision id of the tile at given pixel coordinates.
 JGPoint getTileCoord(int tilex, int tiley)
          Get pixel coordinate corresponding to the top left of the tile at the given index
 JGPoint getTileCoord(JGPoint tileidx)
          Get pixel coordinate corresponding to the top left of the tile at the given index
 JGPoint getTileIndex(double x, double y)
          Get tile index of the tile the coordinate is on.
 JGRectangle getTiles(JGRectangle r)
          Get tile index range of all tiles overlapping given rectangle of pixel coordinates.
 boolean getTiles(JGRectangle dest, JGRectangle r)
          Get tile index range of all tiles overlapping given rectangle of pixel coordinates, version without object creation.
 java.lang.String getTileStr(int xidx, int yidx)
          get string id of tile at given index position.
 java.lang.String getTileStr(JGPoint center, int xofs, int yofs)
          Get the tile string of the point that is (xofs,yofs) from the tile index coordinate center.
 java.lang.String getTileStrAtCoord(double x, double y)
          Get string id of the tile at given pixel coordinates.
 boolean getVideoSyncedUpdate()
           
 double getXAlignOfs(double x)
          Returns the difference between position and the closest tile-aligned position.
 double getXDist(double x1, double x2)
          Calculates length of the shortest path between x1 and x2, with x1, x2 being playfield coordinates, taking into account the wrap setting.
 double getXScaleFactor()
          Get scale factor of real screen width wrt virtual screen width
 double getYAlignOfs(double y)
          Returns the difference between position and the closest tile-aligned position.
 double getYDist(double y1, double y2)
          Calculates length of the shortest path between y1 and y2, with y1, y2 being playfield coordinates, taking into account the wrap setting.
 double getYScaleFactor()
          Get scale factor of real screen height wrt virtual screen height
 boolean hasAccelerometer()
          returns true if device has accelerometer (currently only android)
 boolean inGameState(java.lang.String state)
          Check if game is in given state.
 boolean inGameStateNextFrame(java.lang.String state)
          Check if game will be in given state the next frame.
 void initCanvas()
          Override to define your own initialisations before the engine initialises.
 void initEngine(int width, int height)
          Init engine as application.
 void initEngineApplet()
          Init engine as applet; call this in your engine constructor.
 void initEngineComponent(int width, int height)
          Init engine as component to be embedded in a frame or panel; call this in your engine constructor.
 void initGame()
          Override to define your own initialisations after the engine initialised.
 int invokeUrl(java.lang.String url, java.lang.String target)
          Execute or go to URL (action depends on file type).
 boolean isAndroid()
          Are we running on Android?
 boolean isApplet()
          Are we running as an applet or as an application?
 boolean isMidlet()
          Are we running as a midlet?
 boolean isOpenGL()
          Are we running with an OpenGL backend?
 boolean isRunning()
          True if engine is running, false if paused.
 boolean isXAligned(double x, double margin)
          Returns true if x falls within margin of the tile snap grid.
 boolean isYAligned(double y, double margin)
          Returns true if y falls within margin of the tile snap grid.
 java.lang.String lastPlayedAudio(java.lang.String channel)
          Returns the audioclip that was last played, null if audio was stopped with stopAudio.
 void markAddObject(JGObject obj)
          Add new object, will become active next frame, do not call directly.
 double moduloXPos(double x)
          A modulo that moduloes symmetrically, relative to the middle of the view.
 double moduloYPos(double y)
          A modulo that moduloes symmetrically, relative to the middle of the view.
 void moveObjects()
          Call the move() methods of all registered objects.
 void moveObjects(java.lang.String prefix, int cidmask)
          Call the move() methods of those objects matching the given name prefix and collision id mask.
 void optsAddBoolean(java.lang.String varname, java.lang.String title, java.lang.String desc, boolean initial)
          Adds boolean that can be configured with a checkbox.
 void optsAddEnum(java.lang.String varname, java.lang.String title, java.lang.String desc, java.lang.String[] values, int initial)
          Adds enum that can be configured with radio buttons.
 void optsAddKey(java.lang.String varname, java.lang.String title, java.lang.String desc, int initial)
          Adds "key" option that can be configured by selecting a key or button on the device.
 void optsAddNumber(java.lang.String varname, java.lang.String title, java.lang.String desc, int decimals, double lower, double upper, double step, double initial)
          adds (int or float) number that can be configured with a slider.
 void optsAddString(java.lang.String varname, java.lang.String title, java.lang.String desc, int maxlen, boolean isPassword, java.lang.String initial)
          Adds String that can be configured by typing text.
 void optsAddTitle(java.lang.String title)
          Adds title to be displayed above subsequent items.
 void optsClear()
          Clear all previous option definitions.
 void orTileCid(int x, int y, int or_mask)
          Modify the cid of a single tile by ORing a bit mask, leaving the actual tile.
 void paintFrame()
          Is called when the engine's default screen painting is finished, and custom painting actions may be carried out.
 void pauseApp()
          Called by the application manager to pause app.
 int pfHeight()
          Get the virtual height in pixels (not the scaled screen height)
 int pfTilesX()
          Get the number of tiles in X direction
 int pfTilesY()
          Get the number of tiles in Y direction
 int pfWidth()
          Get the virtual width in pixels (not the scaled screen width)
 boolean pfWrapX()
          Is playfield X wrap enabled?
 boolean pfWrapY()
          Is playfield Y wrap enabled?
 void playAudio(java.lang.String clipid)
          Play audio clip on unnamed channel, which means it will not replace another clip, and cannot be stopped.
 void playAudio(java.lang.String channel, java.lang.String clipid, boolean loop)
          Play clip on channel with given name.
 double random(double min, double max)
          A floating-point random number between min and max
 double random(double min, double max, double interval)
          Generates discrete random number between min and max inclusive, with steps of interval.
 int random(int min, int max, int interval)
          Generates discrete random number between min and max inclusive, with steps of interval, integer version.
 void registerTimer(JGTimer timer)
          Register a timer with the engine, don't call directly.
 void removeAllTimers()
          Remove all JGTimers still ticking in the system.
 void removeGameState(java.lang.String state)
          Remove the given state from the game's existing state on the next frame.
 void removeObject(JGObject obj)
          Remove one particular object.
 void removeObjects(java.lang.String prefix, int cidmask)
          Remove all objects which have the given name prefix and/or match the given cidmask.
 void removeObjects(java.lang.String prefix, int cidmask, boolean suspended_obj)
          Remove all objects which have the given name prefix and/or match the given cidmask.
 void requestGameFocus()
          Call this to get focus.
 void setAuthorMessage(java.lang.String msg)
          Set author message, default "JGame [version]"
 void setBGColor(JGColor bgcolor)
          Set global background colour, which is displayed in borders, and behind transparent tiles if no BGImage is defined.
 void setBGImage(int depth, java.lang.String bgimg, boolean wrapx, boolean wrapy)
          Set image to display at a particular parallax scroll level.
 void setBGImage(java.lang.String bgimg)
          Set image to display behind transparent tiles.
 void setBGImgOffset(int depth, double xofs, double yofs, boolean centered)
          Change (absolute) offset of BG image independently of view offset.
 void setBlendMode(int src_func, int dst_func)
          Set blend mode, for platforms that support blending.
 void setCanvasSettings(int nrtilesx, int nrtilesy, int tilex, int tiley, JGColor fgcolor, JGColor bgcolor, JGFont msgfont)
          Set canvas dimensions and message colours/fonts.
 void setColor(JGColor col)
          Set current drawing colour.
 void setColorsFont(JGColor fgcolor, JGColor bgcolor, JGFont msgfont)
          Set foreground and background colour, and message font in one go; passing a null means ignore that argument.
 void setFGColor(JGColor fgcolor)
          Set global foreground colour, used for printing text and status messages.
 void setFont(JGFont font)
          Set current font, scale the font to screen size.
 void setFrameRate(double fps, double maxframeskip)
          Set frame rate in frames per second, and maximum number of frames that may be skipped before displaying a frame again.
 void setGameSpeed(double speed)
          Set game speed variable, default is 1.0.
 void setGameState(java.lang.String state)
          Set the game's main state on the next frame.
 void setKey(int key)
          Set the key status of a key to pressed.
 void setMouseButton(int nr)
          Set state of button to pressed.
 void setMouseCursor(int cursor)
          Set mouse cursor to a platform-independent standard cursor.
 void setMouseCursor(java.lang.Object cursor)
          Set mouse cursor, platform dependent.
 void setMsgFont(JGFont msgfont)
          Set the (unscaled) message font, used for displaying status messages.
 void setOffscreenMargin(int xmargin, int ymargin)
          Set margin used for testing if object should expire or suspend when off-view or off-playfield.
 void setPFSize(int nrtilesx, int nrtilesy)
          Set the playfield size to be any size larger or equal to the view size.
 void setPFWrap(boolean wrapx, boolean wrapy, int shiftx, int shifty)
          Set playfield wraparound setting.
 void setProgressBar(double pos)
          Set progress bar position in the load screen.
 void setProgressMessage(java.lang.String msg)
          Set progress message, default "Loading files..."
 void setRenderSettings(int alpha_thresh, JGColor render_bg_col)
          Configure image rendering.
 void setScalingPreferences(double min_aspect_ratio, double max_aspect_ratio, int crop_top, int crop_left, int crop_bottom, int crop_right)
          Set scaling preferences for translating the virtual playfield to the actual display.
 void setSmoothing(boolean smooth_magnify)
          Magnification can be set to smooth or blocky.
 void setStroke(double thickness)
          Set the line thickness
 void setTextOutline(int thickness, JGColor colour)
          Set parameters of outline surrounding text (for example, used to increase contrast).
 void setTile(int x, int y, java.lang.String tilestr)
          Set a single tile.
 void setTile(JGPoint tileidx, java.lang.String tilename)
          Set a single tile.
 void setTileCid(int x, int y, int value)
          Set the cid of a single tile to the given value, leaving the actual tile.
 void setTileCid(int x, int y, int and_mask, int or_mask)
          Set the cid of a single tile using and and or mask.
 void setTiles(int xofs, int yofs, java.lang.String[] tilemap)
          Set a block of tiles according to the single-letter tile names in the nxm character array tilemap.
 void setTileSettings(java.lang.String out_of_bounds_tile, int out_of_bounds_cid, int preserve_cids)
          Define background tile settings.
 void setTilesMulti(int xofs, int yofs, java.lang.String[] tilemap)
          Set a block of tiles according to the tile names in the nxm element array tilemap.
 void setVideoSyncedUpdate(boolean value)
          Enable/disable video synced update (jogl only).
 void setViewOffset(int xofs, int yofs, boolean centered)
          Change offset of playfield view.
 void setViewZoomRotate(double zoom, double rotate)
          Zoom/rotate view.
 void snapToGrid(JGPoint p, int gridsnapx, int gridsnapy)
          Snap p to grid in case p is close enough to the grid lines.
 double snapToGridX(double x, double gridsnapx)
          Snap to grid, double version.
 double snapToGridY(double y, double gridsnapy)
          Snap to grid, double version.
 void start()
          Signal that the engine should start running.
 void startApp()
          Called when midlet is first initialised, or unpaused.
 void stop()
          signal that the engine should stop running and wait.
 void stopAudio()
          Stop all audio channels.
 void stopAudio(java.lang.String channel)
          Stop one audio channel.
 boolean storeExists(java.lang.String id)
          Checks if item exists in store
 double storeReadDouble(java.lang.String id, double undef)
          Reads double from store, use undef if ID not found
 int storeReadInt(java.lang.String id, int undef)
          Reads int from store, use undef if ID not found
 java.lang.String storeReadString(java.lang.String id, java.lang.String undef)
          Reads String from store, use undef if ID not found
 void storeRemove(java.lang.String id)
          Remove record if it exists
 void storeWriteDouble(java.lang.String id, double value)
          Writes double to store under given ID
 void storeWriteInt(java.lang.String id, int value)
          Writes integer to store under given ID
 void storeWriteString(java.lang.String id, java.lang.String value)
          Writes string to store under given ID
 int tileHeight()
          Get the tile height in (virtual) pixels.
 java.lang.String tileIDToStr(int tileid)
          Convert tile ID code to tile name (as used internally).
 int tileStrToID(java.lang.String tilestr)
          Convert tile name to integer ID code (as used internally).
 int tileWidth()
          Get the tile width in (virtual) pixels.
 int viewHeight()
          Get the virtual height in pixels (not the scaled screen height)
 int viewTilesX()
          Get the number of tiles of view window in X direction
 int viewTilesY()
          Get the number of tiles of view window in Y direction
 int viewWidth()
          Get the virtual width in pixels (not the scaled screen width)
 int viewXOfs()
          Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.
 int viewYOfs()
          Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.
 void wakeUpOnKey(int key)
          Make engine call start() when a key is pressed.
 

Field Detail

JGameVersionString

static final java.lang.String JGameVersionString
See Also:
Constant Field Values

KeyUp

static final int KeyUp
Cursor keys for both regular and mobile keyboard.

See Also:
Constant Field Values

KeyDown

static final int KeyDown
Cursor keys for both regular and mobile keyboard.

See Also:
Constant Field Values

KeyLeft

static final int KeyLeft
Cursor keys for both regular and mobile keyboard.

See Also:
Constant Field Values

KeyRight

static final int KeyRight
Cursor keys for both regular and mobile keyboard.

See Also:
Constant Field Values

KeyShift

static final int KeyShift
On a mobile, the cursor control Fire is the same as shift.

See Also:
Constant Field Values

KeyFire

static final int KeyFire
Fire stands for a mobile key, indicating the fire button of the cursor controls. It is equivalent to KeyShift.

See Also:
Constant Field Values

KeyCtrl

static final int KeyCtrl
See Also:
Constant Field Values

KeyAlt

static final int KeyAlt
See Also:
Constant Field Values

KeyEsc

static final int KeyEsc
See Also:
Constant Field Values

KeyEnter

static final int KeyEnter
On a mobile, pressing "*" also triggers KeyEnter.

See Also:
Constant Field Values

KeyStar

static final int KeyStar
The mobile Star key, equal to '*'.

See Also:
Constant Field Values

KeyPound

static final int KeyPound
The mobile Pound key, equal to '#'.

See Also:
Constant Field Values

KeyBackspace

static final int KeyBackspace
See Also:
Constant Field Values

KeyTab

static final int KeyTab
See Also:
Constant Field Values

KeyMouse1

static final int KeyMouse1
Keymap equivalent of mouse button.

See Also:
Constant Field Values

KeyMouse2

static final int KeyMouse2
Keymap equivalent of mouse button.

See Also:
Constant Field Values

KeyMouse3

static final int KeyMouse3
Keymap equivalent of mouse button.

See Also:
Constant Field Values

NO_CURSOR

static final int NO_CURSOR
Platform-independent cursor.

See Also:
Constant Field Values

DEFAULT_CURSOR

static final int DEFAULT_CURSOR
Platform-independent cursor.

See Also:
Constant Field Values

CROSSHAIR_CURSOR

static final int CROSSHAIR_CURSOR
Platform-independent cursor.

See Also:
Constant Field Values

HAND_CURSOR

static final int HAND_CURSOR
Platform-independent cursor.

See Also:
Constant Field Values

WAIT_CURSOR

static final int WAIT_CURSOR
Platform-independent cursor.

See Also:
Constant Field Values
Method Detail

setProgressBar

void setProgressBar(double pos)
Set progress bar position in the load screen.

Parameters:
pos - a number between 0 and 1

setProgressMessage

void setProgressMessage(java.lang.String msg)
Set progress message, default "Loading files..."


setAuthorMessage

void setAuthorMessage(java.lang.String msg)
Set author message, default "JGame [version]"


getImage

JGImage getImage(java.lang.String imgname)
Gets (scaled) image directly. Is usually not necessary. Returns null if image is a null image; throws error if image is not defined.


getImageSize

JGPoint getImageSize(java.lang.String imgname)
Gets (non-scaled) image's physical size directly. The object returned may be a reference to an internal variable, do not change it!


defineImage

void defineImage(java.lang.String name,
                 java.lang.String tilename,
                 int collisionid,
                 java.lang.String imgfile,
                 java.lang.String img_op,
                 int top,
                 int left,
                 int width,
                 int height)
Define new sprite/tile image from a file. If an image with this id is already defined, it is removed from any caches, so that the old image is really unloaded. This can be used to load large (background) images on demand, rather than have them all in memory. Note that the unloading does not work for images defined from image maps. Defining an image with the same name and filename twice does not cause the image to be reloaded, but keeps the old image.

Parameters:
name - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgfile - filespec in resource path; "null" means no file
top - collision bounding box dimensions
left - collision bounding box dimensions
width - collision bounding box dimensions
height - collision bounding box dimensions

defineImageRotated

void defineImageRotated(java.lang.String imgname,
                        java.lang.String tilename,
                        int collisionid,
                        java.lang.String srcimg,
                        double angle)
Define new image by rotating an already loaded image. This method does not yet work for images defined from image maps! The destination image is always a square which is large enough to fit the source image at any angle. Its dimension is calculated as: max(width, height, 0.75*(width+height)). The source image is rendered to its center.

If an image with this id is already defined, it is removed from any caches, so that the old image is really unloaded. This can be used to load large (background) images on demand, rather than have them all in memory. Note that the unloading does not work for images defined from image maps.

Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
srcimg - image id of (already loaded) source image
angle - the angle in radians by which to rotate

defineImageMap

void defineImageMap(java.lang.String mapname,
                    java.lang.String imgfile,
                    int xofs,
                    int yofs,
                    int tilex,
                    int tiley,
                    int skipx,
                    int skipy)
Define image map, a large image containing a number of smaller images to use for sprites or fonts. The images must be in a regularly spaced matrix. One may define multiple image maps with the same image but different matrix specs.

Parameters:
mapname - id of image map
imgfile - filespec in resource path
xofs - x offset of first image
yofs - y offset of first image
tilex - width of an image
tiley - height of an image
skipx - nr of pixels to skip between successive images
skipy - nr of pixels to skip between successive images vertically.

getImageBBox

JGRectangle getImageBBox(java.lang.String imgname)
Gets the collision bounding box of an image.


defineImage

void defineImage(java.lang.String imgname,
                 java.lang.String tilename,
                 int collisionid,
                 java.lang.String imgfile,
                 java.lang.String img_op)
Define new sprite/tile image from a file, with collision bounding box equal to the image's dimensions. If an image with this id is already defined, it is removed from any caches, so that the old image is really unloaded. This can be used to load large (background) images on demand, rather than have them all in memory. Note that the unloading does not work for images defined from image maps. Defining an image with the same name and filename twice does not cause the image to be reloaded, but keeps the old image.

Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgfile - filespec in resource path; "null" means no file

defineImage

void defineImage(java.lang.String imgname,
                 java.lang.String tilename,
                 int collisionid,
                 java.lang.String imgmap,
                 int mapidx,
                 java.lang.String img_op,
                 int top,
                 int left,
                 int width,
                 int height)
Define new sprite/tile image from map.

Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgmap - id of image map
mapidx - index of image in map, 0=first
top - collision bounding box dimensions
left - collision bounding box dimensions
width - collision bounding box dimensions
height - collision bounding box dimensions

defineImage

void defineImage(java.lang.String imgname,
                 java.lang.String tilename,
                 int collisionid,
                 java.lang.String imgmap,
                 int mapidx,
                 java.lang.String img_op)
Define new sprite/tile image from map, with collision bounding box equal to the image's dimensions.

Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgmap - id of image map
mapidx - index of image in map, 0=first

defineMedia

void defineMedia(java.lang.String filename)
Load a set of imagemap, image, animation, and audio clip definitions from a file. The file contains one image / imagemap / animation definition / audio clip on each line, with the fields separated by one or more tabs. Lines not matching the required number of fields are ignored. The fields have the same order as in defineImage, defineImageMap, defineAnimation, and defineAudioClip. For example:

defineImage("mytile", "#", 1,"gfx/myimage.gif", "-");

is equivalent to the following line in the table:

mytile     #     1     gfx/myimage.gif     -

with the whitespace between the fields consisting of one or more tabs. The defineAnimation methods take an array of names as the second argument. This is represented in table format as the names separated by semicolon ';' characters. So:

defineAnimation("anim",new String[]{"frame0","frame1",...},0.5);

is equivalent to:

anim     frame0;frame1;...     0.5


setBGImage

void setBGImage(java.lang.String bgimg)
Set image to display behind transparent tiles. Image size must be a multiple of the tile size. Passing null turns off background image; the background colour will be used instead.

Parameters:
bgimg - image name, null=turn off background image

setBGImage

void setBGImage(int depth,
                java.lang.String bgimg,
                boolean wrapx,
                boolean wrapy)
Set image to display at a particular parallax scroll level. Only some platforms support parallax scrolling. On other platforms, only the level 0 image is displayed, with its offset equal to the view offset. Level 0 corresponds to the top level; setBGImage(String) is equivalent to setBGImage(String,0,true,true). The level 0 image follows the view offset by default, higher levels are initialised to offset (0,0) by default.

Parameters:
bgimg - image name, null=turn off image at this level
depth - depth level, 0=topmost
wrapx - image should wrap in x direction
wrapy - image should wrap in y direction

setTileSettings

void setTileSettings(java.lang.String out_of_bounds_tile,
                     int out_of_bounds_cid,
                     int preserve_cids)
Define background tile settings. Default is setBGCidSettings("",0,0).

Parameters:
out_of_bounds_tile - tile string to use outside of screen bounds
out_of_bounds_cid - cid to use outside of screen boundaries
preserve_cids - cid mask to preserve when setting tiles

fillBG

void fillBG(java.lang.String filltile)
Fill the background with the given tile.

Parameters:
filltile - null means use background colour

markAddObject

void markAddObject(JGObject obj)
Add new object, will become active next frame, do not call directly. This method is normally called automatically by the JGObject constructor. You should not need to call this directly.


existsObject

boolean existsObject(java.lang.String index)
Get object if it exists.


getObject

JGObject getObject(java.lang.String index)
Get object if it exists, null if not.


moveObjects

void moveObjects(java.lang.String prefix,
                 int cidmask)
Call the move() methods of those objects matching the given name prefix and collision id mask.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore

moveObjects

void moveObjects()
Call the move() methods of all registered objects.


checkCollision

void checkCollision(int srccid,
                    int dstcid)
Calls all colliders of objects that match dstcid that collide with objects that match srccid.


checkCollision

int checkCollision(int cidmask,
                   JGObject obj)
Checks collision of objects with given cid mask with given object. Suspended objects are not counted (same as checkCollision(int,int)). This method should be a more efficient way to check for object overlap than getObjects, though it's still not very efficient.

Parameters:
cidmask - cid mask of objects to consider, 0 means any
Returns:
the OR of the CIDs of all object overlapping r

checkBGCollision

int checkBGCollision(JGRectangle r)
Check collision of tiles within given rectangle, return the OR of all cids found.

Parameters:
r - bounding box in pixel coordinates

checkBGCollision

void checkBGCollision(int tilecid,
                      int objcid)
Calls all bg colliders of objects that match objid that collide with tiles that match tileid.


getObjects

java.util.Vector getObjects(java.lang.String prefix,
                            int cidmask,
                            boolean suspended_obj,
                            JGRectangle bbox)
Query the object list for objects matching the given name prefix, CID mask, and collide with the given bounding box. If suspended_obj is true, suspended objects are also included. The list of objects returned match all the supplied criteria. This is an inefficient method, use sparingly.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore
suspended_obj - also count suspended objects
bbox - collision bounding box, null means ignore

removeObject

void removeObject(JGObject obj)
Remove one particular object. The actual removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop.


removeObjects

void removeObjects(java.lang.String prefix,
                   int cidmask)
Remove all objects which have the given name prefix and/or match the given cidmask. It also removes suspended objects. The actual matching and removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop. It also removes any matching objects which are pending to be added the next frame.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore

removeObjects

void removeObjects(java.lang.String prefix,
                   int cidmask,
                   boolean suspended_obj)
Remove all objects which have the given name prefix and/or match the given cidmask. You can specify whether to remove suspended objects or not. The actual matching and removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop. It also removes any matching objects which are pending to be added the next frame.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore
suspended_obj - also count suspended objects

countObjects

int countObjects(java.lang.String prefix,
                 int cidmask)
Count how many objects there are with both the given name prefix and have colid&cidmask != 0. Either criterion can be left out. It also counts suspended objects. Actually searches the object array, so it may be inefficient to use it a lot of times.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore

countObjects

int countObjects(java.lang.String prefix,
                 int cidmask,
                 boolean suspended_obj)
Count how many objects there are with both the given name prefix and have colid&cidmask != 0. Either criterion can be left out. You can specify whether to count suspended objects or not. Actually searches the object array, so it may be inefficient to use it a lot of times.

Parameters:
cidmask - collision id mask, 0 means ignore
prefix - ID prefix, null means ignore
suspended_obj - also count suspended objects

setTileCid

void setTileCid(int x,
                int y,
                int and_mask,
                int or_mask)
Set the cid of a single tile using and and or mask.


setTile

void setTile(int x,
             int y,
             java.lang.String tilestr)
Set a single tile.


countTiles

int countTiles(int tilecidmask)
Count number of tiles with given mask. Actually searches all tiles, so it's inefficient and should be used sparingly (such as, determine the number of something at the beginning of a game).


getTileCid

int getTileCid(int xidx,
               int yidx)
Get collision id of tile at given tile index position. Moduloes the given position if wraparound


getTileStr

java.lang.String getTileStr(int xidx,
                            int yidx)
get string id of tile at given index position. Moduloes the given position if wraparound


getTileCid

int getTileCid(JGRectangle tiler)
Get the OR of the cids at the tile indexes given by tiler


getTiles

JGRectangle getTiles(JGRectangle r)
Get tile index range of all tiles overlapping given rectangle of pixel coordinates. Get tile position range of all tiles overlapping given rectangle. Returns null is rectangle is null.

Parameters:
r - rectangle in pixel coordinates, null is none
Returns:
tile indices

getTiles

boolean getTiles(JGRectangle dest,
                 JGRectangle r)
Get tile index range of all tiles overlapping given rectangle of pixel coordinates, version without object creation. Get tile position range of all tiles overlapping given rectangle. Returns false is rectangle is null.

Parameters:
r - rectangle in pixel coordinates, null is none
dest - rectangle to copy tile range into
Returns:
true if rectangle exists, false if null

drawTile

void drawTile(int xi,
              int yi,
              int tileid)
Draw tile directly on background, do not call this directly, use setTile instead.


setTileCid

void setTileCid(int x,
                int y,
                int value)
Set the cid of a single tile to the given value, leaving the actual tile.


orTileCid

void orTileCid(int x,
               int y,
               int or_mask)
Modify the cid of a single tile by ORing a bit mask, leaving the actual tile.


andTileCid

void andTileCid(int x,
                int y,
                int and_mask)
Modify the cid of a single tile by ANDing a bit mask, leaving the actual tile.


setTile

void setTile(JGPoint tileidx,
             java.lang.String tilename)
Set a single tile.


setTiles

void setTiles(int xofs,
              int yofs,
              java.lang.String[] tilemap)
Set a block of tiles according to the single-letter tile names in the nxm character array tilemap.


setTilesMulti

void setTilesMulti(int xofs,
                   int yofs,
                   java.lang.String[] tilemap)
Set a block of tiles according to the tile names in the nxm element array tilemap. The tile names may be multiple characters. Each String in the tilemap consists of a list of tile names separated by spaces. So: "x aa ab abc" stands for a sequence of four tiles, "x", "aa", "ab", and "abc".


getTileCidAtCoord

int getTileCidAtCoord(double x,
                      double y)
Get collision id of the tile at given pixel coordinates.


getTileCid

int getTileCid(JGPoint center,
               int xofs,
               int yofs)
Get the tile cid of the point that is (xofs,yofs) from the tile index coordinate center.


getTileStrAtCoord

java.lang.String getTileStrAtCoord(double x,
                                   double y)
Get string id of the tile at given pixel coordinates.


getTileStr

java.lang.String getTileStr(JGPoint center,
                            int xofs,
                            int yofs)
Get the tile string of the point that is (xofs,yofs) from the tile index coordinate center.


tileStrToID

int tileStrToID(java.lang.String tilestr)
Convert tile name to integer ID code (as used internally). The ID code basically encodes the four characters of the string into the bytes of the four-byte integer. The ID code is NOT related to the collision ID (CID).

Parameters:
tilestr - tilename, null or empty string -> ID = 0

tileIDToStr

java.lang.String tileIDToStr(int tileid)
Convert tile ID code to tile name (as used internally). The ID code basically encodes the four characters of the string into the bytes of the four-byte integer. The ID code is NOT related to the collision ID (CID).

Parameters:
tileid - tile ID, tileid==0 -> tilename = empty string

moduloXPos

double moduloXPos(double x)
A modulo that moduloes symmetrically, relative to the middle of the view. That is, the returned x/ypos falls within -pfwidth/height_half and pfwidth/height_half of x/yofs_mid


moduloYPos

double moduloYPos(double y)
A modulo that moduloes symmetrically, relative to the middle of the view. That is, the returned x/ypos falls within -pfwidth/height_half and pfwidth/height_half of x/yofs_mid


dbgShowBoundingBox

void dbgShowBoundingBox(boolean enabled)
Show bounding boxes around the objects: the image bounding box (getBBox) , the tile span (getTiles), and the center tiles (getCenterTiles).


dbgShowGameState

void dbgShowGameState(boolean enabled)
Show the game state in the bottom right corner of the screen. The message font and foreground colour are used to draw the text.


dbgShowFullStackTrace

void dbgShowFullStackTrace(boolean enabled)
Indicates whether to show full exception stack traces or just the first lines. Default is false.


dbgShowMessagesInPf

void dbgShowMessagesInPf(boolean enabled)
Output messages on playfield instead of console. Default is true. Messages printed by an object are displayed close to that object. Messages printed by the main program are shown at the bottom of the screen. The debug message font is used to display the messages.

A message that is generated in this frame is shown in the foreground colour at the appropriate source. If the source did not generate a message, the last printed message remains visible, and is shown in debug colour 1. If an object prints a message, and then dies, the message will remain for a period of time after the object is gone. These messages are shown in debug colour 2.


dbgSetMessageExpiry

void dbgSetMessageExpiry(int ticks)
Set the number of frames a debug message of a removed object should remain on the playfield.


dbgSetMessageFont

void dbgSetMessageFont(JGFont font)
Set the font for displaying debug messages.


dbgSetDebugColor1

void dbgSetDebugColor1(JGColor col)
Set debug color 1, used for printing debug information.


dbgSetDebugColor2

void dbgSetDebugColor2(JGColor col)
Set debug color 2, used for printing debug information.


dbgPrint

void dbgPrint(java.lang.String msg)
Print a debug message, with the main program being the source.


dbgPrint

void dbgPrint(java.lang.String source,
              java.lang.String msg)
Print a debug message from a specific source, which is either the main program or a JGObject.

Parameters:
source - may be object ID or "MAIN" for the main program.

dbgShowException

void dbgShowException(java.lang.String source,
                      java.lang.Throwable e)
Print the relevant information of an exception as a debug message.

Parameters:
source - may be object ID or "MAIN" for the main program.

dbgExceptionToString

java.lang.String dbgExceptionToString(java.lang.Throwable e)
Convert the relevant information of an exception to a multiline String.


exitEngine

void exitEngine(java.lang.String msg)
Exit, optionally reporting an exit message. The exit message can be used to report fatal errors. In case of an application or midlet, the program exits. In case of an applet, destroy is called, and the exit message is displayed on the playfield.

Parameters:
msg - an exit message, null means none

initEngineComponent

void initEngineComponent(int width,
                         int height)
Init engine as component to be embedded in a frame or panel; call this in your engine constructor.

Parameters:
width - canvas width
height - canvas height

initEngineApplet

void initEngineApplet()
Init engine as applet; call this in your engine constructor. Applet init() will start the game.


initEngine

void initEngine(int width,
                int height)
Init engine as application. Passing (0,0) for width, height will result in a full-screen window without decoration. Passing another value results in a regular window with decoration.

Parameters:
width - real screen width, 0 = use screen size
height - real screen height, 0 = use screen size

setCanvasSettings

void setCanvasSettings(int nrtilesx,
                       int nrtilesy,
                       int tilex,
                       int tiley,
                       JGColor fgcolor,
                       JGColor bgcolor,
                       JGFont msgfont)
Set canvas dimensions and message colours/fonts. You must call this in initCanvas().

Parameters:
nrtilesx - nr of tiles horizontally
nrtilesy - nr of tiles vertically
tilex - width of one tile
tiley - height of one tile
fgcolor - pen/text colour, null for default white
bgcolor - background colour, null for default black
msgfont - font for messages and text drawing, null for default

setScalingPreferences

void setScalingPreferences(double min_aspect_ratio,
                           double max_aspect_ratio,
                           int crop_top,
                           int crop_left,
                           int crop_bottom,
                           int crop_right)
Set scaling preferences for translating the virtual playfield to the actual display. You can only call this in initCanvas(). You can set the allowed aspect ratio and the crop margin here. Aspect ratio is defined as the ratio (actual_tile_width / actual_tile_height) / (virtual_tile_width / virtual_tile_height). So, if the tile size of the scaled display is (3,2) pixels, and the original was (4,4) pixels, the aspect ratio is 1.5. Default values for min_aspect_ratio and max_aspect_ratio are resp 0.75 and 1.333. Setting both to 1.0 means you always get a square aspect ratio.

Crop margin can be used if you wish to allow the scaling algorithm to take just a few pixels off your playfield in order to make a wider tile size fit. The tile size is always integer, so even a best-fit scaled tile size may leave an unused border around the playfield, which may be undesirable for small screens. Cropping just a few pixels off the playfield may be just enough to make the tiles 1 pixel larger. Setting a crop to a value greater than zero means you allow the playfield to fall off the canvas for the amount of actual pixels specified, in order to make a larger tile size fit. Default crop margin is 0.

Parameters:
min_aspect_ratio - minimum width:height ratio allowed
max_aspect_ratio - maximum width:height ratio allowed
crop_top - number of pixels to crop at top
crop_left - number of pixels to crop at left size
crop_bottom - number of pixels to crop at bottom
crop_right - number of pixels to crop at right size

setSmoothing

void setSmoothing(boolean smooth_magnify)
Magnification can be set to smooth or blocky. For platforms that enable smooth magnification (OpenGL), smoothing may look too blurry when magnifying by a large amount, so blocky magnification may actually look more charming.

Parameters:
smooth_magnify - smooth images when magnifying

requestGameFocus

void requestGameFocus()
Call this to get focus.


isApplet

boolean isApplet()
Are we running as an applet or as an application?


isMidlet

boolean isMidlet()
Are we running as a midlet?


isOpenGL

boolean isOpenGL()
Are we running with an OpenGL backend?


isAndroid

boolean isAndroid()
Are we running on Android?


viewWidth

int viewWidth()
Get the virtual width in pixels (not the scaled screen width)


viewHeight

int viewHeight()
Get the virtual height in pixels (not the scaled screen height)


viewTilesX

int viewTilesX()
Get the number of tiles of view window in X direction


viewTilesY

int viewTilesY()
Get the number of tiles of view window in Y direction


viewXOfs

int viewXOfs()
Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.


viewYOfs

int viewYOfs()
Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.


pfWidth

int pfWidth()
Get the virtual width in pixels (not the scaled screen width)


pfHeight

int pfHeight()
Get the virtual height in pixels (not the scaled screen height)


pfTilesX

int pfTilesX()
Get the number of tiles in X direction


pfTilesY

int pfTilesY()
Get the number of tiles in Y direction


pfWrapX

boolean pfWrapX()
Is playfield X wrap enabled?


pfWrapY

boolean pfWrapY()
Is playfield Y wrap enabled?


tileWidth

int tileWidth()
Get the tile width in (virtual) pixels.


tileHeight

int tileHeight()
Get the tile height in (virtual) pixels.


displayWidth

int displayWidth()
Get the real display width on this device.


displayHeight

int displayHeight()
Get the real display height on this device.


initCanvas

void initCanvas()
Override to define your own initialisations before the engine initialises. This method is meant for doing initialisations after the applet has been initialised (in case we're an applet) but before the engine initialises. This can be considered a replacement of the regular constructor, making it independent of whether we're an applet or application. Typically you only need to call setCanvasSettings here, and, optionally, setScalingPreferences(). This is the place where you can read applet parameters and initialise accordingly. In case you want to adapt to the real display dimensions, you can get them using displayWidth/Height at this point.


initGame

void initGame()
Override to define your own initialisations after the engine initialised. This method is called by the game thread after initEngine(), initEngineApplet(), or initEngineComponent() was called.


start

void start()
Signal that the engine should start running. May be called by the web browser.


stop

void stop()
signal that the engine should stop running and wait. May be called by the web browser.


startApp

void startApp()
Called when midlet is first initialised, or unpaused. Midlet version of init() when called for the first time, and start() for subsequent calls.


pauseApp

void pauseApp()
Called by the application manager to pause app. Basically the midlet version of stop(), behaves the same as stop().


destroyApp

void destroyApp(boolean unconditional)
Called by the application manager to exit app. Basically the midlet version of destroy(), behaves the same as destroy().


isRunning

boolean isRunning()
True if engine is running, false if paused.


wakeUpOnKey

void wakeUpOnKey(int key)
Make engine call start() when a key is pressed. This can be used to determine a start criterion when halting the engine from within using stop().

Parameters:
key - keycode to wake up on, -1=any key or mouse, 0=none

destroy

void destroy()
Destroy function for deinitialising the engine properly. This is called by the applet viewer to dispose the applet. Use exitEngine to destroy the applet and exit the system.


getFrameRate

double getFrameRate()
Returns:
frame rate in frames per second

getFrameSkip

double getFrameSkip()
Returns:
max successive frames to skip

getVideoSyncedUpdate

boolean getVideoSyncedUpdate()
Returns:
true = video synced mode enabled

setViewOffset

void setViewOffset(int xofs,
                   int yofs,
                   boolean centered)
Change offset of playfield view. The offset will become active at the next frame draw. If the view would be out of the playfield's bounds, the offset is corrected so that it is inside them. The offset of the parallax level 0 background image is set to the offset as well, the other levels remain unchanged.

Parameters:
centered - center view on (xofs, yofs), topleft otherwise

setBGImgOffset

void setBGImgOffset(int depth,
                    double xofs,
                    double yofs,
                    boolean centered)
Change (absolute) offset of BG image independently of view offset. Only supported by parallax scrolling platforms. Note that parallax level 0 follows the view offset, so a call to this method to set level 0 should be done after calling setViewOffset.

Parameters:
depth - depth level of image to set
centered - center view on (xofs, yofs), topleft otherwise

setViewZoomRotate

void setViewZoomRotate(double zoom,
                       double rotate)
Zoom/rotate view. Can be used to create special effects, like speed-dependent zoom, explosion shake, etc. Only works in OpenGL. If you zoom out too far, parts that are beyond the borders of the defined view may get exposed, the appearance of which is undefined. This also happens when you rotate, so you will also need to zoom in to ensure this does not happen. Everything that is drawn relative to the playfield is zoomed/rotated, everything that is not is unaffected. Game logic is unaffected.

Mouse coordinates are inverse projected through the last set zoom/rotate setting, so that a playfield relative pixel drawn at the logical mouse coordinates coincides with the physical position of the mouse pointer. If you don't want this, you can set zoom/rotate to (1,0), read the mouse position, then set zoom/rotate to the desired value.

The zoom/rotate setting used for actual drawing is the last value set at the end of the doFrame phase. Should not be called during the paintFrame phase.

Parameters:
zoom - zoom factor, 1.0 is normal size
rotate - angle in radians

setPFSize

void setPFSize(int nrtilesx,
               int nrtilesy)
Set the playfield size to be any size larger or equal to the view size.

Parameters:
nrtilesx - number of tiles, >= viewTilesX()
nrtilesy - number of tiles, >= viewTilesY()

setPFWrap

void setPFWrap(boolean wrapx,
               boolean wrapy,
               int shiftx,
               int shifty)
Set playfield wraparound setting. When wraparound is enabled, the playfield theoretically behaves as if it is infinitely long or high, with tiles and objects repeating periodically, with playfield size being the period. Tile coordinates in a wrapped playfield are effectively modulo the playfield size. Object coordinates are wrapped symmetrically to the view offset, that is, they are kept within -playfieldsize, +playfieldsize of the center of the view offset. This ensures that regular coordinate comparison and collision usually work as expected, without having to actually model the infinite repetition of the objects in the wrap direction. The shiftx and shifty can be used to shift the object's wrap center by some pixels, to ensure they enter and leave the sides / top-bottom of the screen neatly when the playfield is not larger than the view. For this case, use the following formula: ensure the playfield is slightly larger than the view (namely, one sprite length), and set the shift to sprite length/2.


setFrameRate

void setFrameRate(double fps,
                  double maxframeskip)
Set frame rate in frames per second, and maximum number of frames that may be skipped before displaying a frame again. Default is 35 frames per second, with a maxframeskip of 4.

Parameters:
fps - frames per second, useful range 2...80
maxframeskip - max successive frames to skip, useful range 0..10

setVideoSyncedUpdate

void setVideoSyncedUpdate(boolean value)
Enable/disable video synced update (jogl only). This method has no effect on non-jogl platforms, where it is always disabled. The game state update becomes synced with the screen refresh rate. Frame rate is no longer fixed, but depends on the machine the game is running on. Gamespeed is set at the beginning of each frame to compensate for this. Gamespeed is 1 when actual frame rate == frame rate set with setFrameRate, less than 1 if frame rate greater than setFrameRate, more than 1 if frame rate less than setFrameRate. There is a hard upper and lower bound for gamespeed, to ensure it does not attain wild values under rare conditions. Lower bound for game speed is determined by a fixed upper bound for the expected screen refresh rate, 95 hz. Upper bound for game speed is determined by the frameskip setting.


setGameSpeed

void setGameSpeed(double speed)
Set game speed variable, default is 1.0. Game speed affects certain parts of the game engine automatically to offload some of the work involved of adapting a game to different speeds. These are the following: it is used as JGTimer tick increment, animation increment, JGObject expiry increment, and is used as multiplier for object x/yspeed, and for the default margins of is...Aligned and snapToGrid.


getGameSpeed

double getGameSpeed()
Get game speed variable. This can be used if you have other stuff in your game that is affected by game speed, besides the standard game speed adaptation done by the engine.


setRenderSettings

void setRenderSettings(int alpha_thresh,
                       JGColor render_bg_col)
Configure image rendering. alpha_thresh is used to determine how a translucent image is converted to a bitmask image. Alpha values below the threshold are set to 0, the others to 255. render_bg_col is used to render transparency for scaled images; it is the background colour that interpolations between transparent and non-transparent pixels are rendered to. Currently, this has an effect in Jdk1.2 only. The default render_bg_col is null, meaning the global background colour is used.

Parameters:
alpha_thresh - bitmask threshold, 0...255, default=128
render_bg_col - bg colour for render, null=use background colour

setOffscreenMargin

void setOffscreenMargin(int xmargin,
                        int ymargin)
Set margin used for testing if object should expire or suspend when off-view or off-playfield. Default is 16,16.


getOffscreenMarginX

int getOffscreenMarginX()
Get offscreen X margin.

See Also:
setOffscreenMargin(int,int)

getOffscreenMarginY

int getOffscreenMarginY()
Get offscreen Y margin.

See Also:
setOffscreenMargin(int,int)

setBGColor

void setBGColor(JGColor bgcolor)
Set global background colour, which is displayed in borders, and behind transparent tiles if no BGImage is defined.


setFGColor

void setFGColor(JGColor fgcolor)
Set global foreground colour, used for printing text and status messages. It is also the default colour for painting


setMsgFont

void setMsgFont(JGFont msgfont)
Set the (unscaled) message font, used for displaying status messages. It is also the default font for painting.


setColorsFont

void setColorsFont(JGColor fgcolor,
                   JGColor bgcolor,
                   JGFont msgfont)
Set foreground and background colour, and message font in one go; passing a null means ignore that argument.


setTextOutline

void setTextOutline(int thickness,
                    JGColor colour)
Set parameters of outline surrounding text (for example, used to increase contrast).

Parameters:
thickness - 0 = turn off outline

setMouseCursor

void setMouseCursor(int cursor)
Set mouse cursor to a platform-independent standard cursor.


setMouseCursor

void setMouseCursor(java.lang.Object cursor)
Set mouse cursor, platform dependent. null (platform-independent) means hide cursor.


removeAllTimers

void removeAllTimers()
Remove all JGTimers still ticking in the system.


registerTimer

void registerTimer(JGTimer timer)
Register a timer with the engine, don't call directly. This is called automatically by the JGTimer constructor.


setGameState

void setGameState(java.lang.String state)
Set the game's main state on the next frame. Methods with the names doFrame<state> and paintFrame<state> will be called in addition to doFrame() and paintFrame(). Before the next frame, start<state> is called once. Note that setGameState may actually set a state that's already set, in which case start<state> is not called. Also, if the setGameState is superseded by another setGameState within the same frame, the first setGameState is ignored.


addGameState

void addGameState(java.lang.String state)
Add the given state to the game's existing state on the next frame. The methods doFrame<state> and paintFrame<state> will be called in addition to the methods of any states already set. Before the next frame, start<state> is called once. Note that addGameState may actually set a state that's already set, in which case start<state> is not called.


removeGameState

void removeGameState(java.lang.String state)
Remove the given state from the game's existing state on the next frame.


clearGameState

void clearGameState()
Set the game's main state to none, on the next frame. Only doFrame() and paintFrame() will be called each frame.


inGameState

boolean inGameState(java.lang.String state)
Check if game is in given state.


inGameStateNextFrame

boolean inGameStateNextFrame(java.lang.String state)
Check if game will be in given state the next frame.


doFrame

void doFrame()
Is called every frame. Override to define frame action. Default is do nothing.


paintFrame

void paintFrame()
Is called when the engine's default screen painting is finished, and custom painting actions may be carried out. Can be used to display status information or special graphics. Default is do nothing.


getXScaleFactor

double getXScaleFactor()
Get scale factor of real screen width wrt virtual screen width


getYScaleFactor

double getYScaleFactor()
Get scale factor of real screen height wrt virtual screen height


getMinScaleFactor

double getMinScaleFactor()
Get minimum of the x and y scale factors


setColor

void setColor(JGColor col)
Set current drawing colour.


setFont

void setFont(JGFont font)
Set current font, scale the font to screen size.


setStroke

void setStroke(double thickness)
Set the line thickness


setBlendMode

void setBlendMode(int src_func,
                  int dst_func)
Set blend mode, for platforms that support blending. Blend functions supported are based on the alpha of the object being drawn (the drawing source). Source and destination alpha multiplier are specified separately. These are one of: always 1 (encoded as 0), alpha (encoded as 1), and 1-alpha (encoded as -1). Default is (1,-1).

Parameters:
src_func - source multiply factor, 0=one, 1=alpha, -1 = one - alpha
dst_func - destination multiply factor, 0=one, 1=alpha, -1 = one - alpha

getFontHeight

double getFontHeight(JGFont font)
Get height of given font in pixels.


drawLine

void drawLine(double x1,
              double y1,
              double x2,
              double y2,
              double thickness,
              JGColor color)
DrawLine combined with thickness/colour setting. The line is drawn relative to the playfield coordinates.


drawLine

void drawLine(double x1,
              double y1,
              double x2,
              double y2)
Draw a line with current thickness and colour. The line is drawn relative to the playfield coordinates.


drawLine

void drawLine(double x1,
              double y1,
              double x2,
              double y2,
              boolean pf_relative)
Draw a line with current thickness and colour.

Parameters:
pf_relative - coordinates are relative to playfield, otherwise view

drawPolygon

void drawPolygon(double[] x,
                 double[] y,
                 JGColor[] col,
                 int len,
                 boolean filled,
                 boolean pf_relative)
Draw convex polygon. For filled polygons, it is possible to draw a colour gradient, namely a "fan" of colours (specified by col), spreading from the first point to each successive point in the polygon. For line polygons, a gradient is drawn between successive line segments. On non-OpenGL platforms, the fill gradient is drawn as a fan of plain colours, with colour 0 and 1 ignored, the line gradient as plain coloured lines.

Parameters:
x - x coordinates of the points
y - y coordinates of the points
col - colour of each point, null means use default colour
len - number of points
pf_relative - coordinates are relative to playfield, otherwise view

drawRect

void drawRect(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              double thickness,
              JGColor color)
Set colour/thickness and draw rectangle. Coordinates are relative to playfield.

Parameters:
centered - indicates (x,y) is center instead of topleft.

drawRect

void drawRect(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered)
Draw rectangle in default colour and thickness. Coordinates are relative to playfield.

Parameters:
centered - indicates (x,y) is center instead of topleft.

drawRect

void drawRect(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              boolean pf_relative)
Draw rectangle in default colour and thickness.

Parameters:
centered - indicates (x,y) is center instead of topleft.
pf_relative - coordinates are relative to playfield, otherwise view

drawRect

void drawRect(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              boolean pf_relative,
              JGColor[] shadecol)
Draw shaded rectangle. On non-opengl platforms, rectangle is drawn in default colour.

Parameters:
shadecol - colors topleft,topright,botright,botleft corners

drawRect

void drawRect(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              boolean pf_relative,
              JGColor[] shadecol,
              java.lang.String tileimage)
Draw shaded or patterned rectangle. On non-opengl platforms, rectangle is drawn in default colour.

Parameters:
shadecol - colors topleft,topright,botright,botleft corners

drawOval

void drawOval(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              double thickness,
              JGColor color)
Set thickness/colour and draw oval. Coordinates are relative to playfield.

Parameters:
centered - indicates (x,y) is center instead of topleft.

drawOval

void drawOval(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered)
Draw oval with default thickness and colour. Coordinates are relative to playfield.

Parameters:
centered - indicates (x,y) is center instead of topleft.

drawOval

void drawOval(double x,
              double y,
              double width,
              double height,
              boolean filled,
              boolean centered,
              boolean pf_relative)
Draw oval with default thickness and colour.

Parameters:
centered - indicates (x,y) is center instead of topleft.
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

void drawImage(double x,
               double y,
               java.lang.String imgname)
Draw image with given ID. Coordinates are relative to playfield.


drawImage

void drawImage(double x,
               double y,
               java.lang.String imgname,
               boolean pf_relative)
Draw image with given ID.

Parameters:
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

void drawImage(double x,
               double y,
               java.lang.String imgname,
               JGColor blend_col,
               double alpha,
               double rot,
               double scale,
               boolean pf_relative)
Extended version of drawImage for OpenGL or Android. On platforms without support for accelerated blending, rotation, scaling, this call is equivalent to drawImage(x,y,imgname,pf_relative). rotation and scaling are centered around the image center.

Parameters:
blend_col - colour to blend with image, null=(alpha,alpha,alpha)
alpha - alpha (blending) value, 0=transparent, 1=opaque
rot - rotation of object in degrees (radians)
scale - scaling of object (1 = normal size).

drawImage

void drawImage(java.lang.String imgname,
               double x,
               double y)
Draw image with given ID, new version. Coordinates are relative to playfield.


drawImage

void drawImage(java.lang.String imgname,
               double x,
               double y,
               boolean pf_relative)
Draw image with given ID, new version.

Parameters:
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

void drawImage(java.lang.String imgname,
               double x,
               double y,
               boolean pf_relative,
               JGColor blend_col,
               double alpha,
               double rot,
               double scale)
Extended version of drawImage for OpenGL or Android, new version. On platforms without support for accelerated blending, rotation, scaling, this call is equivalent to drawImage(x,y,imgname,pf_relative). rotation and scaling are centered around the image center.

Parameters:
blend_col - colour to blend with image, null=(alpha,alpha,alpha)
alpha - alpha (blending) value, 0=transparent, 1=opaque
rot - rotation of object in degrees (radians)
scale - scaling of object (1 = normal size).

drawString

void drawString(java.lang.String str,
                double x,
                double y,
                int align,
                JGFont font,
                JGColor color)
Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1). Use given font and colour; filling in null for either means ignore. Unlike the other draw functions, for strings, coordinates are relative to view by default. An outline is drawn around the text when defined by setTextOutline.

Parameters:
align - text alignment, -1=left, 0=center, 1=right

drawString

void drawString(java.lang.String str,
                double x,
                double y,
                int align)
Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1). Use current font and colour. Unlike the other draw functions, for strings, coordinates are relative to view by default. An outline is drawn around the text when defined by setTextOutline.

Parameters:
align - text alignment, -1=left, 0=center, 1=right

drawString

void drawString(java.lang.String str,
                double x,
                double y,
                int align,
                boolean pf_relative)
Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1). Use current font and colour. An outline is drawn around the text when defined by setTextOutline.

Parameters:
align - text alignment, -1=left, 0=center, 1=right
pf_relative - coordinates are relative to playfield, otherwise view

drawImageString

void drawImageString(java.lang.String string,
                     double x,
                     double y,
                     int align,
                     java.lang.String imgmap,
                     int char_offset,
                     int spacing)
Draws a single line of text using an image map as font; text alignment is same as drawString. Typically, an image font only defines the ASCII character range 32-96. In this case, set char_offset to 32, and use only the uppercase letters. Coordinates are relative to view.

Parameters:
align - text alignment, -1=left, 0=center, 1=right
imgmap - name of image map
char_offset - ASCII code of first image of image map
spacing - number of pixels to skip between letters

drawImageString

void drawImageString(java.lang.String string,
                     double x,
                     double y,
                     int align,
                     java.lang.String imgmap,
                     int char_offset,
                     int spacing,
                     boolean pf_relative)
Draws a single line of text using an image map as font; text alignment is same as drawString. Typically, an image font only defines the ASCII character range 32-96. In this case, set char_offset to 32, and use only the uppercase letters.

Parameters:
align - text alignment, -1=left, 0=center, 1=right
imgmap - name of image map
char_offset - ASCII code of first image of image map
spacing - number of pixels to skip between letters
pf_relative - coordinates are relative to playfield, otherwise view

getMousePos

JGPoint getMousePos()
Get current mouse position in logical coordinates, inverse projected through last set view zoom/rotate setting.


getMouseX

int getMouseX()
Get current mouse X position


getMouseY

int getMouseY()
Get current mouse Y position


getMouseButton

boolean getMouseButton(int nr)
Get state of button.

Parameters:
nr - 1=button 1 ... 3 = button 3
Returns:
true=pressed, false=released

clearMouseButton

void clearMouseButton(int nr)
Set state of button to released.

Parameters:
nr - 1=button 1 ... 3 = button 3

setMouseButton

void setMouseButton(int nr)
Set state of button to pressed.

Parameters:
nr - 1=button 1 ... 3 = button 3

getMouseInside

boolean getMouseInside()
Check if mouse is inside game window


getKey

boolean getKey(int key)
Get the key status of the given key.


clearKey

void clearKey(int key)
Set the key status of a key to released.


setKey

void setKey(int key)
Set the key status of a key to pressed.


getLastKey

int getLastKey()
Get the keycode of the key that was pressed last, 0=none.


getLastKeyChar

char getLastKeyChar()
Get the keycode of the key that was pressed last, 0=none.


clearLastKey

void clearLastKey()
Clear the lastkey status.


getKeyDesc

java.lang.String getKeyDesc(int key)
Get a printable string describing the key.


getKeyCode

int getKeyCode(java.lang.String keydesc)
Obtain key code from printable string describing the key, the inverse of getKeyDesc. The string is trimmed and lowercased.


hasAccelerometer

boolean hasAccelerometer()
returns true if device has accelerometer (currently only android)


getAccelX

double getAccelX()
get accelerometer vector X coordinate


getAccelY

double getAccelY()
get accelerometer vector Y coordinate


getAccelZ

double getAccelZ()
get accelerometer vector Z coordinate (positive = towards user)


getAccelVec

double[] getAccelVec()
get double[3] vector representing acceleration


defineAnimation

void defineAnimation(java.lang.String id,
                     java.lang.String[] frames,
                     double speed)
Define new animation sequence. Speed must be >= 0.

Parameters:
id - the name by which the animation is known
frames - an array of image names that should be played in sequence
speed - the sequence speed: the number of animation steps per frame

defineAnimation

void defineAnimation(java.lang.String id,
                     java.lang.String[] frames,
                     double speed,
                     boolean pingpong)
Define new animation sequence. Speed must be >= 0.

Parameters:
id - the name by which the animation is known
frames - an array of image names that should be played in sequence
speed - the sequence speed: the number of animation steps per frame
pingpong - true=play the images in forward order, then in reverse

getAnimation

Animation getAnimation(java.lang.String id)
Get animation definition, don't call directly. This is used by JGObjects to get animations.


getConfigPath

java.lang.String getConfigPath(java.lang.String filename)
Returns path to writable location for a file with the given name. Basically it uses [user.home] / .jgame / [filename], with "/" being the system path separator. In case [user.home] / .jgame does not exist, it is created. In case .jgame is not a directory, null is returned. In case the file does not exist yet, an empty file is created.

Returns:
path to writable file, or null if not possible

invokeUrl

int invokeUrl(java.lang.String url,
              java.lang.String target)
Execute or go to URL (action depends on file type).

Returns:
0 if fail; 1 if success; -1 if the status is unknown

and

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


random

double random(double min,
              double max)
A floating-point random number between min and max


random

double random(double min,
              double max,
              double interval)
Generates discrete random number between min and max inclusive, with steps of interval. Epsilon is added to max to ensure there are no rounding error problems with the interval. So, random(0.0, 4.2, 2.1) generates either 0.0, 2.1, or 4.2 with uniform probabilities. If max is halfway between interval steps, max is treated as exclusive. So, random(0.0,5.0,2.1) generates 0.0, 2.1, 4.2 with uniform probabilities. If you need integer ranges, be sure to use the integer version to avoid rounding problems.


random

int random(int min,
           int max,
           int interval)
Generates discrete random number between min and max inclusive, with steps of interval, integer version. If max is halfway between two interval steps, it is treated as exclusive.


atan2

double atan2(double y,
             double x)
Replacement for Math.atan2 for the sake of MIDP portability. The JRE implementation simply uses Math.atan2, for MIDP a short and fast Math.atan2 replacement is used, with average numerical error less than 0.001 radians, maximum error 0.005 radians.


getTileIndex

JGPoint getTileIndex(double x,
                     double y)
Get tile index of the tile the coordinate is on.


getTileCoord

JGPoint getTileCoord(int tilex,
                     int tiley)
Get pixel coordinate corresponding to the top left of the tile at the given index


getTileCoord

JGPoint getTileCoord(JGPoint tileidx)
Get pixel coordinate corresponding to the top left of the tile at the given index


snapToGridX

double snapToGridX(double x,
                   double gridsnapx)
Snap to grid, double version. Epsilon is added to the gridsnap value, so that isXAligned(x,margin) always implies that snapToGridX(x,margin) will snap.

Parameters:
x - position to snap
gridsnapx - snap margin, 0.0 means no snap

snapToGridY

double snapToGridY(double y,
                   double gridsnapy)
Snap to grid, double version. Epsilon is added to the gridsnap value, so that isYAligned(y,margin) always implies that snapToGridY(y,margin) will snap.

Parameters:
y - position to snap
gridsnapy - snap margin, 0.0 means no snap

snapToGrid

void snapToGrid(JGPoint p,
                int gridsnapx,
                int gridsnapy)
Snap p to grid in case p is close enough to the grid lines. Note: this function only handles integers so it should not be used to snap an object position.


isXAligned

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


isYAligned

boolean isYAligned(double y,
                   double margin)
Returns true if y falls within margin of the tile snap grid. Epsilon is added to the margin, so that isYAligned(1.0000, 1.0000) always returns true.


getXAlignOfs

double getXAlignOfs(double x)
Returns the difference between position and the closest tile-aligned position.


getYAlignOfs

double getYAlignOfs(double y)
Returns the difference between position and the closest tile-aligned position.


getXDist

double getXDist(double x1,
                double x2)
Calculates length of the shortest path between x1 and x2, with x1, x2 being playfield coordinates, taking into account the wrap setting.


getYDist

double getYDist(double y1,
                double y2)
Calculates length of the shortest path between y1 and y2, with y1, y2 being playfield coordinates, taking into account the wrap setting.


enableAudio

void enableAudio()
Enable audio, restart any audio loops.


disableAudio

void disableAudio()
Disable audio, stop all currently playing audio. Audio commands will be ignored, except that audio loops (music, ambient sounds) are remembered and will be restarted once audio is enabled again.


defineAudioClip

void defineAudioClip(java.lang.String clipid,
                     java.lang.String filename)
Associate given clipid with a filename. Files are loaded from the resource path. Java 1.2+ supports at least: midi and wav files.


lastPlayedAudio

java.lang.String lastPlayedAudio(java.lang.String channel)
Returns the audioclip that was last played, null if audio was stopped with stopAudio. Note the clip does not actually have to be playing; it might have finished playing already.


playAudio

void playAudio(java.lang.String clipid)
Play audio clip on unnamed channel, which means it will not replace another clip, and cannot be stopped. The clip is not looped. When this method is called multiple times with the same sample within the same frame, it is played only once.


playAudio

void playAudio(java.lang.String channel,
               java.lang.String clipid,
               boolean loop)
Play clip on channel with given name. Will replace any other clip already playing on the channel. Will restart if the clip is already playing and either this call or the already playing one are not specified as looping. If both are looping, the looped sound will continue without restarting. If you want the looping sound to be restarted, call stopAudio first. Note the channel "music" is reserved for enabling/disabling music separately in future versions.


stopAudio

void stopAudio(java.lang.String channel)
Stop one audio channel.


stopAudio

void stopAudio()
Stop all audio channels.


storeWriteInt

void storeWriteInt(java.lang.String id,
                   int value)
Writes integer to store under given ID


storeWriteDouble

void storeWriteDouble(java.lang.String id,
                      double value)
Writes double to store under given ID


storeWriteString

void storeWriteString(java.lang.String id,
                      java.lang.String value)
Writes string to store under given ID


storeRemove

void storeRemove(java.lang.String id)
Remove record if it exists


storeExists

boolean storeExists(java.lang.String id)
Checks if item exists in store


storeReadInt

int storeReadInt(java.lang.String id,
                 int undef)
Reads int from store, use undef if ID not found


storeReadDouble

double storeReadDouble(java.lang.String id,
                       double undef)
Reads double from store, use undef if ID not found


storeReadString

java.lang.String storeReadString(java.lang.String id,
                                 java.lang.String undef)
Reads String from store, use undef if ID not found


optsAddTitle

void optsAddTitle(java.lang.String title)
Adds title to be displayed above subsequent items. Default title of initial items is "Preferences". Call this before defining any items to override the default title.


optsAddNumber

void optsAddNumber(java.lang.String varname,
                   java.lang.String title,
                   java.lang.String desc,
                   int decimals,
                   double lower,
                   double upper,
                   double step,
                   double initial)
adds (int or float) number that can be configured with a slider. Type is double if decimals!=0, int otherwise.

Parameters:
decimals - number is int if 0

optsAddBoolean

void optsAddBoolean(java.lang.String varname,
                    java.lang.String title,
                    java.lang.String desc,
                    boolean initial)
Adds boolean that can be configured with a checkbox. Actual type is int (0 or 1)


optsAddEnum

void optsAddEnum(java.lang.String varname,
                 java.lang.String title,
                 java.lang.String desc,
                 java.lang.String[] values,
                 int initial)
Adds enum that can be configured with radio buttons. Actual type is int, 0 for first item, 1 for second item, etc.


optsAddKey

void optsAddKey(java.lang.String varname,
                java.lang.String title,
                java.lang.String desc,
                int initial)
Adds "key" option that can be configured by selecting a key or button on the device. Actual type is int.


optsAddString

void optsAddString(java.lang.String varname,
                   java.lang.String title,
                   java.lang.String desc,
                   int maxlen,
                   boolean isPassword,
                   java.lang.String initial)
Adds String that can be configured by typing text.


optsClear

void optsClear()
Clear all previous option definitions.