PDG engine v0.9.5
 All Classes Namespaces Functions Variables Groups Pages
Classes | Variables
Graphics

Things related to drawing graphics on screen. More...

Collaboration diagram for Graphics:

Classes

class  Color
 color in RGB space, with optional alpha More...
 
class  Font
 font for text drawing and measuring (GUI Only) More...
 
class  GraphicsManager
 Used to create and track ports (GUI Only) More...
 
class  Image
 A bitmap image that can be blitted onto the screen. More...
 
class  ImageStrip
 bitmap image containing a number of frames that can be blitted onto the screen More...
 
class  ISpriteDrawHelper
 helper for drawing sprite overlays and add-on effects More...
 
class  Offset
 offset within a 2D coordinate system More...
 
class  Point
 point for 2D coordinate system More...
 
class  Port
 area in which drawing is done, a viewport (GUI Only) More...
 
struct  PortDrawEvent
 a port needs to be redrawn (GUI Only) More...
 
struct  PortResizedEvent
 a port has been resized (GUI Only) More...
 
class  Quad
 4 point polygon in 2D system More...
 
class  Rect
 Rectangle for 2D coordinate system. More...
 
class  ResourceManager
 used for loading resources More...
 
class  RotatedRect
 rectangle with rotation for 2D coordinate system. More...
 
class  Vector
 vector (magnitude and direction) within a 2D coordinate system. More...
 

Variables

const action_DrawPortComplete = 43
 eventType_SpriteLayer action: all drawing for every SpriteLayer has completed More...
 
const action_ErasePort = 40
 eventType_SpriteLayer action: about to start drawing each SpriteLayer More...
 
const action_PostDrawLayer = 42
 eventType_SpriteLayer action: completed rendering for a particular SpriteLayer More...
 
const action_PreDrawLayer = 41
 eventType_SpriteLayer action: about to render a particular SpriteLayer More...
 

Detailed Description

Things related to drawing graphics on screen.


Class Documentation

class pdg::ISpriteDrawHelper

helper for drawing sprite overlays and add-on effects

Warning
API Stability: 1 - Experimental. This API was introduced recently and gotten little or no real use. It may change or be removed in future versions. It may not be completely implemented and may be missing important pieces of functionality. Please try it out and provide feedback.

Implement this interface to do extra drawing stuff for a specific Sprite then start using it by calling the sprite's setDrawHelper() method. You can only have one Sprite Draw Helper attached to a particular sprite for normal drawing (before the sprite would normally draw) and one for post draw (after the sprite has been drawn)

For those coding in Javascript, there is an implementation of ISpriteDrawHelper that maps a function definition to the draw call. So to create a helper:

var myHelper = new pdg.ISpriteDrawHelper(function(sprite, port) {
console.log("in my sprite draw helper for " + sprite );
var r = sprite.getLayer().layerToPortRect(sprite.getFrameRotatedBounds());
port.fillRect(r, "black");
port.frameRect(r, "white");
return false; // don't let sprite draw itself (ignored for post draw)
});
mySprite.setDrawHelper(myHelper);

If you need something more complex, you can also use classify to create a new Javascript class that derives from pdg.ISpriteDrawHelper, and it will call the draw() method of your class. For example:

classify(pdg.ISpriteDrawHelper, 'MyDrawHelperClass', function() {
def('draw', function(sprite, port) {
console.log("MyDrawHelperClass.draw(" + sprite + ")" );
return true; // let sprite draw itself (ignored for post draw)
});
});
mySprite.setDrawHelper( new MyDrawHelperClass() );

Your Custom Function:

As you can see from the examples above, your Sprite Draw Helper function (or draw() method) will be called with two parameters, and return a boolean:

Parameters
spritethe Sprite that is being drawn
portthe Port where the sprite should be drawn
Returns
true if the normal Sprite drawing should happen; or false if the normal Sprite drawing should be skipped. This return result only applies when called for pre-draw. If the helper is installed for as a post-draw helper, using setSpritePostDraw(), then the return result is ignored.
See Also
Sprite.setDrawHelper()
struct pdg::PortDrawEvent

a port needs to be redrawn (GUI Only)

Generated by the GraphicsManager whenever it is time to redraw a Port. All drawing calls should be done during the handling of a eventType_PortDraw.

{ 
    emitter: {},       // the emitter that generated this event
    eventType: 24,     // the event type (eventType_PortDraw)
    port: {},          // the port that needs to be redrawn
    frameNum: 12897    // how many times this event has been generated for this port
}
Note
these events are never generated in a non-GUI build, such as the PDG Node.js plugin
See Also
eventType_PortDraw
Port
GraphicsManager
struct pdg::PortResizedEvent

a port has been resized (GUI Only)

Generated by the GraphicsManager whenever a Port is resized or when the device orientation is changed.

{ 
    emitter: {},       // the emitter that generated this event
    eventType: 15,     // the event type (eventType_PortResized)
    port: {},          // the port that was resized
    screenPos: 0       // one of the screenPos_ constants, in this case screenPos_Normal
}
Note
these events are never generated in a non-GUI build, such as the PDG Node.js plugin
See Also
eventType_PortResized
Port
GraphicsManager

Variable Documentation

action_DrawPortComplete = 43

eventType_SpriteLayer action: all drawing for every SpriteLayer has completed

Emitted once per frame, after all drawing for all layers is done.

See Also
action_ErasePort
action_PostDrawLayer
eventType_SpriteLayer
action_ErasePort = 40

eventType_SpriteLayer action: about to start drawing each SpriteLayer

Emitted once per frame, before the drawing of sprite layers is started.

See Also
action_DrawPortComplete
action_PreDrawLayer
eventType_SpriteLayer
action_PostDrawLayer = 42

eventType_SpriteLayer action: completed rendering for a particular SpriteLayer

Emitted once per layer per frame, after all drawing for that layer is complete.

See Also
action_DrawPortComplete
action_PreDrawLayer
eventType_SpriteLayer
action_PreDrawLayer = 41

eventType_SpriteLayer action: about to render a particular SpriteLayer

Emitted once per layer per frame, before any drawing for that layer is performed.

See Also
action_ErasePort
action_PostDrawLayer
eventType_SpriteLayer

User Comments