A 2D scene renderer.

Passed during Object.sync and Object.drawRec and can be accessed directly via Scene.renderer.



Create a new RenderContext and attach it to specified Scene.



The scene which RenderContext will render.


@:value(false)defaultSmooth:Bool = false

Internal usage

Determines texture filtering method (Linear or Nearest). Not recommended to use - assign Scene.defaultSmooth instead.


When enabled, causes Object to render its children in reverse order.

@:value(1.)globalAlpha:Float = 1.

Current transparency value used for rendering objects. Automatically managed by Object.


When enabled, pixels with alpha value below 0.001 will be discarded.


The 2D scene attached to this RenderContext instance.

onBeginDraw:Drawable ‑> Bool

Sent before Drawable is rendered. Drawable won't be rendered if callback returns false.

onEnterFilter:Object ‑> Bool

Sent before filter begins rendering. Filter (and it's object tree) won't be rendered if callback returns false.

onLeaveFilter:Object ‑> Void

Send after filter has been rendered.


@:value({ filter : false })allocTarget(name:String, filter:Bool = false):Texture

Allocated a cached render target Texture with specified name, filter mode and current Scene.width and Scene.height.


Either precached Texture under same name or newly allocated one.


Internal usage

Should be called before performing a new draw call in order to sync shader data and other parameters.


Internal usage

Prepares RenderContext to begin rendering a new frame.


Prepares rendering with BatchState. Each state draw should be preceded with swapTexture call.

@:access(h2d.Drawable)beginDrawObject(obj:Drawable, texture:Texture):Bool

Prepares rendering of the Drawable object with specified texture.


true if rendering is prepared, false otherwise (see RenderContext.onBeginDraw)


Clears current render target with specified color.

clipRenderZone(x:Float, y:Float, w:Float, h:Float):Void

Pushes new render zone with respect to the old render zone settings by clipping new and old render zones, pushing the intersection area result. Used so that any call to the clipRenderZone respects the already set zone, and can't render outside of it.


Renders the assigned Scene. Same as s2d.drawRec(s2d.renderer).

@:access(h2d.Drawable)drawTile(obj:Drawable, tile:Tile):Bool

Renders a Tile with the transform of the given Drawable.


true if tile was drawn, false otherwise. Tile is not drawn if it's either outside of the rendering area or was cancelled by RenderContext.onBeginDraw.


Internal usage

Performers cleanup after frame is rendered.


Internal usage

Restores previous viewport state prior to camera rendering, removing it from the camera stack.


Internal usage

Finalizes Filter rendering and removes top-most Object from filter stack.


Restores previous render zone settings.


Pops current render target from the target stack. If last texture was removed from the stack, will restore the primary render buffer as a render target.


Internal usage

Applies Camera cam transform to current viewport and pushes it onto the camera stack. Should call RenderContext.popCamera when rendering is complete.


Internal usage

Prepares to render Filter and pushes provided Object onto filter stack.


true if filter is allowed to render, false otherwise (see RenderContext.onEnterFilter)

pushRenderZone(x:Float, y:Float, w:Float, h:Float):Void

Sets rectangular render zone area, saving previous render zone settings. To respect previous render zone area, use RenderContext.clipRenderZone method.

RenderContext.popRenderZone should be called afterwards to clear render zone stack.

@:value({ height : -1, width : -1, startY : 0, startX : 0 })pushTarget(t:Texture, startX:Int = 0, startY:Int = 0, width:Int = -1, height:Int = -1):Void

Sets provided texture as a render target and pushes it onto target stack. If only part of the Texture should be rendered onto, method should be used with pushRenderZone() to avoid rendering outside specified texture area.



Texture to which RenderContext will render to. Texture should be allocated as a render target (have Target flag).


X offset of rendering area on the Texture.


Y offset of rendering area on the Texture.


Width of the clipping area on the Texture. If equals to -1, will use texture width.


Height of the clipping area on the Texture. If equals to -1 will use texture height.


Pushes an array of render targets onto target stack.


Swap current active texture and prepares for next drawcall.

Inherited Variables

Inherited Methods