Renderer

Wrapper for Draw2D calls, so that we can keep track of how much is being drawn per frame

Properties

  • nextSceneObjectId (integer)
  • minimumFrameRateTarget (integer) — Frame rate target - the game will reduce quality if this target is not met
  • onlyDrawWhenInFrame (boolean)
  • drawDebugCells (boolean)
  • drawDebugTrianglePoints (boolean)
  • camera (Camera)
  • triangleCache (dynamic)
  • frameCount (integer)
  • bmpPool (BGE.ScratchBitmapPool)
  • game (BGE.Game)
  • name (string)
  • statsString (string)
  • resources (dynamic)
  • dummyScreen (roScreen)

Constructor

new Renderer( draw2d: ifDraw2d, mainGame?: BGE.Game, cam?: BGE.Camera, options?: RendererOptions, ): Renderer

Parameters

  • draw2d (ifDraw2d)
  • mainGame (BGE.Game, optional, default: "invalid")
  • cam (BGE.Camera, optional, default: "invalid")
  • options (RendererOptions, optional, default: "{useBitmapPooling: true}")

Instance Methods

setDraw2d(draw2d: ifDraw2d): void

Parameters

  • draw2d (ifDraw2d)

Returns

  • void

setCamera(camera: Camera): void

Parameters

Returns

  • void

resetDrawCallCounter(): void

Returns

  • void

getDrawCallsLastFrame(): integer

How many draw calls have been issued since resetDrawCallCounter() - i.e. over the course of the current frame. Handy when working out how expensive a scene is to draw.

Returns

  • integer — the number of draw calls so far this frame

addSceneObject(sceneObj: SceneObject): void

Parameters

Returns

  • void

removeSceneObject(sceneObjToRemove: SceneObject): void

Parameters

Returns

  • void

setupCameraForFrame(): void

Returns

  • void

drawScene(): void

Returns

  • void

onSwapBuffers(): void

Returns

  • void

worldPointToCanvasPoint( pWorld: BGE.Math.Vector, ): BGE.Math.Vector

Parameters

  • pWorld (BGE.Math.Vector)

Returns

  • BGE.Math.Vector

getRayFromCameraToWorldPoint( pWorld: BGE.Math.Vector, ): BGE.Math.Vector

Parameters

  • pWorld (BGE.Math.Vector)

Returns

  • BGE.Math.Vector

drawLine( x: float, y: float, endX: float, endY: float, rgba: integer, ): boolean

Parameters

  • x (float)
  • y (float)
  • endX (float)
  • endY (float)
  • rgba (integer)

Returns

  • boolean

drawLineTo( draw2d: ifDraw2d, x: float, y: float, endX: float, endY: float, rgba: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (float)
  • y (float)
  • endX (float)
  • endY (float)
  • rgba (integer)

Returns

  • boolean

drawSquare( x: float, y: float, sideLength: float, rgba: integer, ): boolean

Parameters

  • x (float)
  • y (float)
  • sideLength (float)
  • rgba (integer)

Returns

  • boolean

drawSquareTo( draw2d: ifDraw2d, x: float, y: float, sideLength: float, rgba: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (float)
  • y (float)
  • sideLength (float)
  • rgba (integer)

Returns

  • boolean

drawRectangle( x: float, y: float, width: float, height: float, rgba: integer, ): boolean

Parameters

  • x (float)
  • y (float)
  • width (float)
  • height (float)
  • rgba (integer)

Returns

  • boolean

drawRectangleTo( draw2d: ifDraw2d, x: float, y: float, width: float, height: float, rgba: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (float)
  • y (float)
  • width (float)
  • height (float)
  • rgba (integer)

Returns

  • boolean

drawText( text: string, x: integer, y: integer, color?: integer, font?: roFont, horizAlign?: string, vertAlign?: string, ): boolean

Draws text to the screen

Parameters

  • text (string) — the test to display
  • x (integer)
  • y (integer)
  • color (integer, optional, default: -1) — RGBA color to use
  • font (roFont, optional, default: "invalid") — Font object to use (uses default font if none provided)
  • horizAlign (string, optional, default: "\"left\"") — Horizontal Alignment - "left", "right" or "center"
  • vertAlign (string, optional, default: "\"top\"") — Vertical Alignment - "top", "bottom" or "center"

Returns

  • boolean

drawTextTo( draw2d: ifDraw2d, text: string, x: integer, y: integer, color?: integer, font?: roFont, horizAlign?: string, vertAlign?: string, lineSpace?: integer, ): boolean

Draws text to a canvas

Parameters

  • draw2d (ifDraw2d)
  • text (string) — the test to display
  • x (integer)
  • y (integer)
  • color (integer, optional, default: -1) — RGBA color to use
  • font (roFont, optional, default: "invalid") — Font object to use (uses default font if none provided)
  • horizAlign (string, optional, default: "\"left\"") — Horizontal Alignment - "left", "right" or "center"
  • vertAlign (string, optional, default: "\"top\"") — Vertical Alignment - "top", "bottom" or "center"
  • lineSpace (integer, optional, default: 0) — Additional space between lines

Returns

  • boolean

drawTransformedObject( x: float, y: float, scaleX: float, scaleY: float, theta: float, region: ifDraw2d, rgba?: integer, ): boolean

NOTE: This function is unsafe! It creates an roBitmap of the required size to be able to both scale and rotate the drawing, this action requires free video memory of the appropriate amount.

Parameters

  • x (float)
  • y (float)
  • scaleX (float)
  • scaleY (float)
  • theta (float)
  • region (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawTransformedObjectTo( draw2d: ifDraw2d, x: float, y: float, scale_x: float, scale_y: float, theta: float, region: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (float)
  • y (float)
  • scale_x (float)
  • scale_y (float)
  • theta (float)
  • region (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawPinnedCorners( cornerPoints: BGE.Math.CornerPoints, drawableRegion: BGE.RendererHelpers.RegionWithId, options?: DrawPinnedCornersOptions, color?: integer, ): boolean

Parameters

  • cornerPoints (BGE.Math.CornerPoints)
  • drawableRegion (BGE.RendererHelpers.RegionWithId)
  • options (DrawPinnedCornersOptions, optional, default: "{}")
  • color (integer, optional, default: -1)

Returns

  • boolean

drawRotatedImageWithCenterTo( draw2d: ifDraw2d, srcRegion: ifDraw2d, srcRotationPoint: BGE.Math.Vector, theta: float, translation?: BGE.Math.Vector, drawScale?: BGE.Math.Vector, ): boolean

Rotates a region about a point, and draws it on a given draw2d with a given scale and translation

Parameters

  • draw2d (ifDraw2d) — the final destination for the drawing
  • srcRegion (ifDraw2d) — the source region to draw from
  • srcRotationPoint (BGE.Math.Vector) — the position in srcRegion to rotate about, relative to the region's pretranslation
  • theta (float) — the angle to rotate by (in radians)
  • translation (BGE.Math.Vector, optional, default: "BGE.Math.VectorOps.create()") — the translation to apply after rotation
  • drawScale (BGE.Math.Vector, optional, default: "BGE.Math.createScaleVector(1)") — the scale to apply when drawing

Returns

  • boolean — did the drawing succeed

makeIntoTriangle( srcRegionWithId: BGE.RendererHelpers.RegionWithId, points: dynamic, makeAcute?: boolean, useCache?: boolean, ): BGE.RendererHelpers.TriangleBitmap

Parameters

  • srcRegionWithId (BGE.RendererHelpers.RegionWithId)
  • points (dynamic)
  • makeAcute (boolean, optional, default: false)
  • useCache (boolean, optional, default: false)

Returns

  • BGE.RendererHelpers.TriangleBitmap

drawBitmapTriangle( srcRegionWithId: BGE.RendererHelpers.RegionWithId, srcPoints: dynamic, destPoints: dynamic, rgba?: integer, ): boolean

Draws a bitmap warped from srcPoints onto destPoints, directly to this renderer's own canvas. See drawBitmapTriangleTo() for the note about staged scratch bitmaps.

Parameters

  • srcRegionWithId (BGE.RendererHelpers.RegionWithId) — the region to draw from
  • srcPoints (dynamic)
  • destPoints (dynamic)
  • rgba (integer, optional, default: -1)

Returns

  • boolean — true if it worked

drawBitmapTriangleTo( draw2d: ifDraw2d, srcRegionWithId: BGE.RendererHelpers.RegionWithId, srcPoints: dynamic, destPoints: dynamic, rgba?: integer, ): boolean

NOTE: This method uses temporary bitmaps. In order not to re-use them for subsequent calls they are staged for return to the bitmap pool. You need to manually call bmpPool.returnStagedRegions() to return them after you're sure all the drawing to the surface is done

Parameters

  • draw2d (ifDraw2d)
  • srcRegionWithId (BGE.RendererHelpers.RegionWithId) — the region to draw from
  • srcPoints (dynamic)
  • destPoints (dynamic)
  • rgba (integer, optional, default: -1)

Returns

  • boolean — true if it worked

drawPinnedCornersTo( draw2d: ifDraw2d, cornerPoints: BGE.Math.CornerPoints, drawableRegion: BGE.RendererHelpers.RegionWithId, options?: DrawPinnedCornersOptions, color?: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • cornerPoints (BGE.Math.CornerPoints)
  • drawableRegion (BGE.RendererHelpers.RegionWithId)
  • options (DrawPinnedCornersOptions, optional, default: "{}")
  • color (integer, optional, default: -1)

Returns

  • boolean

drawCircleOutline( line_count: integer, x: float, y: float, radius: float, rgba: integer, ): boolean

Parameters

  • line_count (integer)
  • x (float)
  • y (float)
  • radius (float)
  • rgba (integer)

Returns

  • boolean

drawRectangleOutline( x: float, y: float, width: float, height: float, rgba: integer, lineWidth?: integer, ): boolean

Draws the outline of an axis-aligned rectangle

Parameters

  • x (float) — left edge
  • y (float) — top edge
  • width (float)
  • height (float)
  • rgba (integer) — color to stroke with
  • lineWidth (integer, optional, default: 1) — stroke thickness in pixels, drawn inwards from the given bounds

Returns

  • boolean — true if anything was drawn

drawRectangleOutlineTo( draw2d: ifDraw2d, x: float, y: float, width: float, height: float, rgba: integer, lineWidth?: integer, ): boolean

Draws the outline of an axis-aligned rectangle to the given surface

Parameters

  • draw2d (ifDraw2d) — surface to draw to
  • x (float) — left edge
  • y (float) — top edge
  • width (float)
  • height (float)
  • rgba (integer) — color to stroke with
  • lineWidth (integer, optional, default: 1) — stroke thickness in pixels, drawn inwards from the given bounds

Returns

  • boolean — true if anything was drawn

drawPolygonOutline( pointsArray: Array.<BGE.Math.Vector>, colorRgba: integer, lineWidth?: integer, ): boolean

Draws the outline of a polygon, connecting each point to the next and the last back to the first

Parameters

  • pointsArray (Array.<BGE.Math.Vector>) — points in outline (perimeter) order, not bounds order
  • colorRgba (integer) — color to stroke with
  • lineWidth (integer, optional, default: 1) — stroke thickness in pixels - approximated by nested outlines shrunk towards the polygon's center

Returns

  • boolean — true if anything was drawn

drawPolygonOutlineTo( draw2d: ifDraw2d, pointsArray: Array.<BGE.Math.Vector>, colorRgba: integer, lineWidth?: integer, ): boolean

Draws the outline of a polygon to the given surface

Parameters

  • draw2d (ifDraw2d) — surface to draw to
  • pointsArray (Array.<BGE.Math.Vector>) — points in outline (perimeter) order, not bounds order
  • colorRgba (integer) — color to stroke with
  • lineWidth (integer, optional, default: 1) — stroke thickness in pixels - approximated by nested outlines shrunk towards the polygon's center

Returns

  • boolean — true if anything was drawn

drawObject( x: integer, y: integer, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • x (integer)
  • y (integer)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawObjectTo( draw2d: ifDraw2d, x: integer, y: integer, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (integer)
  • y (integer)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawScaledObject( x: integer, y: integer, scaleX: float, scaleY: float, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • x (integer)
  • y (integer)
  • scaleX (float)
  • scaleY (float)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawScaledObjectTo( draw2d: ifDraw2d, x: integer, y: integer, scaleX: float, scaleY: float, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (integer)
  • y (integer)
  • scaleX (float)
  • scaleY (float)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawRotatedObject( x: integer, y: integer, theta: float, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • x (integer)
  • y (integer)
  • theta (float)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawRotatedObjectTo( draw2d: ifDraw2d, x: integer, y: integer, theta: float, src: ifDraw2d, rgba?: integer, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • x (integer)
  • y (integer)
  • theta (float)
  • src (ifDraw2d)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawRegion( regionToDraw: ifDraw2d, x: float, y: float, scaleX?: float, scaleY?: float, rotation?: float, rgba?: integer, ): boolean

Parameters

  • regionToDraw (ifDraw2d)
  • x (float)
  • y (float)
  • scaleX (float, optional, default: 1)
  • scaleY (float, optional, default: 1)
  • rotation (float, optional, default: 0)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawRegionTo( canvasDrawTo: ifDraw2d, regionToDraw: ifDraw2d, x: float, y: float, scaleX?: float, scaleY?: float, rotation?: float, rgba?: integer, ): boolean

Parameters

  • canvasDrawTo (ifDraw2d)
  • regionToDraw (ifDraw2d)
  • x (float)
  • y (float)
  • scaleX (float, optional, default: 1)
  • scaleY (float, optional, default: 1)
  • rotation (float, optional, default: 0)
  • rgba (integer, optional, default: -1)

Returns

  • boolean

drawTriangle( points: dynamic, x: float, y: float, rgba: integer, allowQuickDraw?: boolean, ): boolean

Parameters

  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • allowQuickDraw (boolean, optional, default: false)

Returns

  • boolean

drawTriangleTo( canvasDrawTo: ifDraw2d, points: dynamic, x: float, y: float, rgba: integer, allowQuickDraw?: boolean, ): boolean

Parameters

  • canvasDrawTo (ifDraw2d)
  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • allowQuickDraw (boolean, optional, default: false)

Returns

  • boolean

drawPolygon( points: dynamic, x: float, y: float, rgba: integer, allowQuickDraw?: boolean, ): boolean

Parameters

  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • allowQuickDraw (boolean, optional, default: false)

Returns

  • boolean

drawPolygonTo( canvasDrawTo: ifDraw2d, points: dynamic, x: float, y: float, rgba: integer, allowQuickDraw?: boolean, ): boolean

Parameters

  • canvasDrawTo (ifDraw2d)
  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • allowQuickDraw (boolean, optional, default: false)

Returns

  • boolean

drawPolygonAsRectangles( canvasDrawTo: ifDraw2d, points: dynamic, x: float, y: float, rgba: integer, options?: LevelOfDetailOptions, ): boolean

Parameters

  • canvasDrawTo (ifDraw2d)
  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • options (LevelOfDetailOptions, optional, default: "{levelOffset: 0, levelOfDetail: 2}")

Returns

  • boolean

drawPolygonAsRectanglesTo( canvasDrawTo: ifDraw2d, points: dynamic, x: float, y: float, rgba: integer, options?: LevelOfDetailOptions, ): boolean

Draw a filled convex polygon with rectangles

Parameters

  • canvasDrawTo (ifDraw2d)
  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • options (LevelOfDetailOptions, optional, default: "{levelOffset: 0, levelOfDetail: 2}")

Returns

  • boolean

drawTriangleAsRaysTo( canvasDrawTo: ifDraw2d, points: dynamic, x: float, y: float, rgba: integer, options?: LevelOfDetailOptions, ): boolean

Parameters

  • canvasDrawTo (ifDraw2d)
  • points (dynamic)
  • x (float)
  • y (float)
  • rgba (integer)
  • options (LevelOfDetailOptions, optional, default: "{levelOffset: 0, levelOfDetail: 2}")

Returns

  • boolean

getCanvasSize(): BGE.Math.Vector

Returns

  • BGE.Math.Vector

getCanvasCenter(): BGE.Math.Vector

Returns

  • BGE.Math.Vector

isInsideCanvas( originalX: float, originalY: float, draw2d: object, x: float, y: float, width: float, height: float, rotation?: float, ): boolean

Checks to see if a rectangle will be in a Draw2d Canvas

Parameters

  • originalX (float)
  • originalY (float)
  • draw2d (object)
  • x (float)
  • y (float)
  • width (float)
  • height (float)
  • rotation (float, optional, default: 0) — in radians

Returns

  • boolean — true if this rectangle overlaps with the canvas

drawTrianglePoints( points: dynamic, size?: integer, offset?: PositionXY, drawRegardlessOfDebugValue?: boolean, ): boolean

Parameters

  • points (dynamic)
  • size (integer, optional, default: 5)
  • offset (PositionXY, optional, default: "{x: 0, y: 0}")
  • drawRegardlessOfDebugValue (boolean, optional, default: false)

Returns

  • boolean

drawTrianglePointsTo( draw2dRegion: object, points: dynamic, size?: integer, offset?: PositionXY, drawRegardlessOfDebugValue?: boolean, ): boolean

Parameters

  • draw2dRegion (object)
  • points (dynamic)
  • size (integer, optional, default: 5)
  • offset (PositionXY, optional, default: "{x: 0, y: 0}")
  • drawRegardlessOfDebugValue (boolean, optional, default: false)

Returns

  • boolean

drawTriangleOutline( pointsArray: dynamic, colorRgba: integer, offset?: PositionXY, ): boolean

Parameters

  • pointsArray (dynamic)
  • colorRgba (integer)
  • offset (PositionXY, optional, default: "{x: 0, y: 0}")

Returns

  • boolean

drawTriangleOutlineTo( draw2d: ifDraw2d, pointsArray: dynamic, colorRgba: integer, offset?: PositionXY, ): boolean

Parameters

  • draw2d (ifDraw2d)
  • pointsArray (dynamic)
  • colorRgba (integer)
  • offset (PositionXY, optional, default: "{x: 0, y: 0}")

Returns

  • boolean

addDebugCell(region: ifDraw2d, text?: string): void

Parameters

  • region (ifDraw2d)
  • text (string, optional, default: "\"\"")

Returns

  • void

forceDraw(drawSurface: ifDraw2d): void

Parameters

  • drawSurface (ifDraw2d)

Returns

  • void