-
Notifications
You must be signed in to change notification settings - Fork 83
The Render Package
Oak's render subpackage handles all operations related to drawing elements to window. This includes primitive types that can be drawn, loading of files and sprite sheets, and providing handlers to organize draw order. render provides subpackages of its own for specific operations on drawable elements and specific subtypes of drawable elements.
// A Renderable is anything which can
// be drawn at a given draw layer, undrawn,
// and set in a particular position.
//
// Basic Implementing struct: Sprite
type Renderable interface {
Draw(buff draw.Image, xOff, yOff float64)
GetDims() (int, int)
Positional
Layered
physics.Attachable
}The Renderable interface defines all types that can be drawn in oak's draw stack. Oak provides several implementations of this interface that should satisfy all basic use cases, and when creating your own implementation of the interface you can almost always rely on composing one of the built in types to satisfy most of these functions.
The lesser interfaces making up a Renderable provide the ability to set and manipulate 2D position and manipulate an element's draw layer. physics.Attachable allows different 2D elements to be attached to one another so that when one moves, so does the other.
// A Modifiable is a Renderable that has functions to change its
// underlying image.
type Modifiable interface {
Renderable
GetRGBA() *image.RGBA
Modify(...mod.Mod) Modifiable
Filter(...mod.Filter)
Copy() Modifiable
}Most Implementations of Renderable that Oak provides also implement Modifiable. This interface catches each sort of image manipulation function into the Modify and Filter functions, the former to change an image and create a new image, and the latter to change an image in place.
-
Sprite:
Spriteis the most basic implementation of aRenderable, combining a 2D position, a draw layer, and a color buffer. When this is drawn to the window it's color buffer will be set at it's 2D position in the world. As with allRenderables, for draw stack items that respect layers aSpriteat a higher layer will be visible on top of a Sprite at a lower layer. -
Composite: A
Compositeis equivalent to a list forRenderables. There are two types ofComposite, theComposite, andCompositeR, where the former is made up of theModifiableinterface and the latter of theRenderableinterface. Most implementations ofRenderablealso satisfyModifiablebut if you are working withTexttypes or using this as a draw stack element you will need to useCompositeR. -
Switch: A
Switchis a Renderable type that stores multipleModifiables but at one time will only draw one of them, keyed by strings. This is ideal for something like an animating character that changes animation based on input. -
Sequence: A
Sequenceis a series ofModifiables that will be drawn in order. Sequences have a frames per second rate for how fast they changeModifiables, and each keeps track of whether they are allowed to be interrupted by other animations. When aSequencereaches its last frame it will trigger theAnimationEndevent on its associated CID if it was assigned one. -
Reverting: A
Revertingtype is aModifiableextension that can revert sets of modifications and restore old renderable elements. -
Polygon: A
Polygonis a extension of aSpritewhich stores point locations and a bounding rectangle so it can be filled with color to create a shape. -
Text:
Textis created through therender.Fonttype and stores anyfmt.Stringer. This means that a basicTexttype can store actively changing text like score or a timer. Because of this,Textis not aModifiable, but can be converted to one throughToSprite.
in progress
in progress
in progress
in progress
in progress
in progress
in progress