Fixed-delay: Scheduled with schedule(). The ‘n+1’ run is done “period” milliseconds after the beginning of “n” execution (delay on the beginning of an execution influences all the next, and the frequency is changed). Useful for animations and real-time user interaction.
Fixed-rate: Scheduled with scheduleAtFixedRate(). Executed is done according to the first one. A delay will make the next events run on a greater schedule to “catch up”.
Images are either mutable or immutable, depending on how they were created. Immutable images are usually loaded from binary resources. Mutable images are created black and drawn programmatically. If a mutable image is added to a resource (e.g. an alert or an image item) , a “Snapshot” from the image at this moment is used.
Mutable images do not support transparency
PNG standard and its transparency must be supported. Additional formats may be supported.
You can perform a programmatic double-buffering by creating a mutable image and painting to it first and later painting this image to a canvas.
GameLoop is expected to execute at a constant rate, and does not depend on user input.
Differently from the regular canvas, a GameCanvas has its own buffer. Its Graphics may be used at any moment, not only inside paint() method.
Defines no abstract methods, but defines the “(boolean suppressKeyEvents)” constructor. When suppressKeyEvents is true, keyPressed , keyReleased, and keyRepeated methods are not called. This may increase performance.
getGraphics(): Return a graphics to paint on this canvas. Operations on this graphics are not shown until flushGraphics is called. A new instance of graphics is created EVERY TIME this method is called, so this call shall not be placed inside the game loop (it shall be called only once, outside the game loop, and reused for every loop).
flushGraphics() and flushGraphics(x,y,w,h): Sends the offscreen buffer to be displayed. Blocks until the operation is finished. When the parameters are informed, only the defined area is painted.
getKeyStates(): Returns an integer (bit mask) with all keys that were pressed since the last time the method was called. This method is expected to be called at every loop. Each bit represents a pressed key. To check if it was pressed, you use the following code:
Sprite(image,frameWidth,frameHeight): Creates a Sprite from an image. A single image defines a whole frame sequence. Each frame will have a specified size (all frames have the same size). The image width must be multiple of the frameWidth and the same must be true for the frameHeight. Frames may be organized in vertical, horizontal, or in “grid” ordering. Initially the sprite is visible, at (0,0) position, with default framesequence (0,1,2…). On the attached sample (sprite.png), frames are organized as below (the last position (5) is not used by the game):
Checks a collision between two objects. When pixelLevel is used, the objects will only colide if opaque pixels collide (which is much slower than checking rectangle collisions). Collisions only happen if both objects are visible. A collision can be checked between two sprites, between a sprite and a tiledLayer, and between a sprite and any image at (x,y).
Defines the rectangle where collisions are considered. By default, it covers the whole frame size. For instance, if you have a jet that leaves some fog, the collision rectangle shall comprehend only the plane itself, and not the fog. Transformations applied to the sprite are also applied to the collision rectangle.
Defines a grid where frames are applied (like wall tiles): Useful for maps and backgrounds.
.Constructor: TiledLayer(columns,rows,image,tileWidth,tileHeight): Creates a grid with (columns x rows) tiles, and define frames with image/tileWidth/tileHeight. The same logic used to define frames for Sprites is used here. Every cell has the same size, which is the same as the tile’s size ( tileWidth, tileHeight).
After the object is created, all its cells are blank. Tiles are set with setCell () and fillCells ()
Like with Sprites, each frame has an index, but the indexes start at 1, while the Sprites they begin at 0. This is done because cells may be blank (setting 0 as index) and tiles can be animated (using negative indexes).
A tile may be static or animated. A static cell is set calling setCell with the tile’s index (positive value). Animated tiles are created by calling createAnimateTile , which returns the animated tile index. Indexes start with -1, and the indexes decreases as tiles are created. Updating the animated tile must be done manually by calling setAnimatedTile
Controls a list of layers (sprite and tiled layers). Simplifies the rendering process controlling the sequence of objects that will be rendered. Elements are organized on a list. Smaller indexes are closer to the user, and append() adds to the END of the list.
Besides the layer list, it has a view window (x,y,w,h). It defines a window over which rendering is applied. This may be used to perform scrolling. (x,y) defines the rendering origin while the width and height define the window size.
A layer can not be placed twice on the same manager. When a item is re-inserted, it’s first removed and then set to the defined position.