UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

317 lines 14 kB
import Painter from "../rendering/Painter"; import TouchProcessor from "../events/TouchProcessor"; import EventDispatcher from "../events/EventDispatcher"; import Stage from "../display/Stage"; import DisplayObject from "../display/DisplayObject"; import Juggler from "../animation/Juggler"; import Rectangle from "openfl/geom/Rectangle"; import Context3DRenderMode from "openfl/display3D/Context3DRenderMode"; import Context3DProfile from "openfl/display3D/Context3DProfile"; import Context3D from "openfl/display3D/Context3D"; import Stage3D from "openfl/display/Stage3D"; import openfl_display_Stage from "openfl/display/Stage"; import Sprite from "openfl/display/Sprite"; import Vector from "openfl/Vector"; declare namespace starling.core { /** * Dispatched when a new render context is created. The 'data' property references the context. */ export class Starling extends EventDispatcher { /** * Creates a new Starling instance. * * @param rootClass A subclass of 'starling.display.DisplayObject'. It will be created * * as soon as initialization is finished and will become the first child * * of the Starling stage. Pass <code>null</code> if you don't want to * * create a root object right away. (You can use the * * <code>rootClass</code> property later to make that happen.) * * @param stage The Flash (2D) stage. * * @param viewPort A rectangle describing the area into which the content will be * * rendered. Default: stage size * * @param stage3D The Stage3D object into which the content will be rendered. If it * * already contains a context, <code>sharedContext</code> will be set * * to <code>true</code>. Default: the first available Stage3D. * * @param renderMode The Context3D render mode that should be requested. * * Use this parameter if you want to force "software" rendering. * * @param profile The Context3D profile that should be requested. * * * * <ul> * * <li>If you pass a profile String, this profile is enforced.</li> * * <li>Pass an Array of profiles to make Starling pick the first * * one that works (starting with the first array element).</li> * * <li>Pass the String "auto" to make Starling pick the best available * * profile automatically.</li> * * </ul> * */ constructor(rootClass: any, stage: openfl_display_Stage, viewPort?: Rectangle, stage3D?: Stage3D, renderMode?: Context3DRenderMode, profile?: any, sharedContext?: boolean); /** * The version of the Starling framework. */ static VERSION: string; /** * The currently active Starling instance. */ static get current(): Starling; /** * All Starling instances. <p>CAUTION: not a copy, but the actual object! Do not modify!</p> */ static get all(): Vector<Starling>; /** * The render context of the currently active Starling instance. */ static get currentContext(): Context3D; /** * The default juggler of the currently active Starling instance. */ static get currentJuggler(): Juggler; /** * The contentScaleFactor of the currently active Starling instance. */ static get currentContentScaleFactor(): number; /** * Indicates if multitouch input should be supported. You can enable or disable * * multitouch at any time; just beware that any current touches will be cancelled. */ static get multitouchEnabled(): boolean; static set multitouchEnabled(value: boolean) /** * Disposes all children of the stage and the render context; removes all registered * * event listeners. */ dispose(): void; /** * Calls <code>advanceTime()</code> (with the time that has passed since the last frame) * * and <code>render()</code>. */ nextFrame(): void; /** * Dispatches ENTER_FRAME events on the display list, advances the Juggler * * and processes touches. */ advanceTime(passedTime: number): void; /** * Renders the complete display list. Before rendering, the context is cleared; afterwards, * * it is presented (to avoid this, enable <code>shareContext</code>). * * * * <p>This method also dispatches an <code>Event.RENDER</code>-event on the Starling * * instance. That's the last opportunity to make changes before the display list is * * rendered.</p> */ render(): void; /** * Stops Starling right away and displays an error message on the native overlay. * * This method will also cause Starling to dispatch a FATAL_ERROR event. */ stopWithFatalError(message: string): void; /** * Make this Starling instance the <code>current</code> one. */ makeCurrent(): void; /** * As soon as Starling is started, it will queue input events (keyboard/mouse/touch); * * furthermore, the method <code>nextFrame</code> will be called once per Flash Player * * frame. (Except when <code>shareContext</code> is enabled: in that case, you have to * * call that method manually.) */ start(): void; /** * Stops all logic and input processing, effectively freezing the app in its current state. * * Per default, rendering will continue: that's because the classic display list * * is only updated when stage3D is. (If Starling stopped rendering, conventional Flash * * contents would freeze, as well.) * * * * <p>However, if you don't need classic Flash contents, you can stop rendering, too. * * On some mobile systems (e.g. iOS), you are even required to do so if you have * * activated background code execution.</p> * */ stop(suspendRendering?: boolean): void; /** * Makes sure that the next frame is actually rendered. * * * * <p>When <code>skipUnchangedFrames</code> is enabled, some situations require that you * * manually force a redraw, e.g. when a RenderTexture is changed. This method is the * * easiest way to do so; it's just a shortcut to <code>stage.setRequiresRedraw()</code>. * * </p> * */ setRequiresRedraw(): void; /** * Indicates if this Starling instance is started. */ get isStarted(): boolean; /** * The default juggler of this instance. Will be advanced once per frame. */ get juggler(): Juggler; /** * The painter, which is used for all rendering. The same instance is passed to all * * <code>render</code>methods each frame. */ get painter(): Painter; /** * The render context of this instance. */ get context(): Context3D; /** * Indicates if multitouch simulation with "Shift" and "Ctrl"/"Cmd"-keys is enabled. * * @default false */ get simulateMultitouch(): boolean; set simulateMultitouch(value: boolean) /** * Indicates if Stage3D render methods will report errors. It's recommended to activate * * this when writing custom rendering code (shaders, etc.), since you'll get more detailed * * error messages. However, it has a very negative impact on performance, and it prevents * * ATF textures from being restored on a context loss. Never activate for release builds! * * * * @default false */ get enableErrorChecking(): boolean; set enableErrorChecking(value: boolean) /** * The antialiasing level. 0 - no antialasing, 16 - maximum antialiasing. @default 0 */ get antiAliasing(): number; set antiAliasing(value: number) /** * The viewport into which Starling contents will be rendered. */ get viewPort(): Rectangle; set viewPort(value: Rectangle) /** * The ratio between viewPort width and stage width. Useful for choosing a different * * set of textures depending on the display resolution. */ get contentScaleFactor(): number; /** * A Flash Sprite placed directly on top of the Starling content. Use it to display native * * Flash components. */ get nativeOverlay(): Sprite; /** * If enabled, touches or mouse events on the native overlay won't be propagated to * * Starling. @default false */ get nativeOverlayBlocksTouches(): boolean; set nativeOverlayBlocksTouches(value: boolean) /** * Indicates if a small statistics box (with FPS, memory usage and draw count) is * * displayed. * * * * <p>Beware that the memory usage should be taken with a grain of salt. The value is * * determined via <code>System.totalMemory</code> and does not take texture memory * * into account. It is recommended to use Adobe Scout for reliable and comprehensive * * memory analysis.</p> * */ get showStats(): boolean; set showStats(value: boolean) /** * Displays the statistics box at a certain position. */ showStatsAt(horizontalAlign?: string, verticalAlign?: string, scale?: number): void; /** * The Starling stage object, which is the root of the display tree that is rendered. */ get stage(): Stage; /** * The Flash Stage3D object Starling renders into. */ get stage3D(): Stage3D; /** * The Flash (2D) stage object Starling renders beneath. */ get nativeStage(): openfl_display_Stage; /** * The instance of the root class provided in the constructor. Available as soon as * * the event 'ROOT_CREATED' has been dispatched. */ get root(): DisplayObject; /** * The class that will be instantiated by Starling as the 'root' display object. * * Must be a subclass of 'starling.display.DisplayObject'. * * * * <p>If you passed <code>null</code> as first parameter to the Starling constructor, * * you can use this property to set the root class at a later time. As soon as the class * * is instantiated, Starling will dispatch a <code>ROOT_CREATED</code> event.</p> * * * * <p>Beware: you cannot change the root class once the root object has been * * instantiated.</p> * */ get rootClass(): any; set rootClass(value: any) /** * Indicates if another Starling instance (or another Stage3D framework altogether) * * uses the same render context. If enabled, Starling will not execute any destructive * * context operations (e.g. not call 'configureBackBuffer', 'clear', 'present', etc. * * This has to be done manually, then. @default false */ get shareContext(): boolean; set shareContext(value: boolean) /** * The Context3D profile of the current render context, or <code>null</code> * * if the context has not been created yet. */ get profile(): Context3DProfile; /** * Indicates that if the device supports HiDPI screens Starling will attempt to allocate * * a larger back buffer than indicated via the viewPort size. Note that this is used * * on Desktop only; mobile AIR apps still use the "requestedDisplayResolution" parameter * * the application descriptor XML. @default false */ get supportHighResolutions(): boolean; set supportHighResolutions(value: boolean) /** * If enabled, the Stage3D back buffer will change its size according to the browser zoom * * value - similar to what's done when "supportHighResolutions" is enabled. The resolution * * is updated on the fly when the zoom factor changes. Only relevant for the browser plugin. * * @default false */ get supportBrowserZoom(): boolean; set supportBrowserZoom(value: boolean) /** * When enabled, Starling will skip rendering the stage if it hasn't changed since the * * last frame. This is great for apps that remain static from time to time, since it will * * greatly reduce power consumption. You should activate this whenever possible! * * * * <p>The reason why it's disabled by default is just that it causes problems with Render- * * and VideoTextures. When you use those, you either have to disable this property * * temporarily, or call <code>setRequiresRedraw()</code> (ideally on the stage) whenever * * those textures are changing. Otherwise, the changes won't show up.</p> * * * * @default false * */ get skipUnchangedFrames(): boolean; set skipUnchangedFrames(value: boolean) /** * The TouchProcessor is passed all mouse and touch input and is responsible for * * dispatching TouchEvents to the Starling display tree. If you want to handle these * * types of input manually, pass your own custom subclass to this property. */ get touchProcessor(): TouchProcessor; set touchProcessor(value: TouchProcessor) /** * When enabled, all touches that start very close to the screen edges are discarded. * * On mobile, such touches often indicate swipes that are meant to use OS features. * * Per default, margins of 15 points at the top, bottom, and left side of the screen are * * checked. Call <code>starling.touchProcessor.setSystemGestureMargins()</code> to adapt * * the margins in each direction. @default true on mobile, false on desktop * */ get discardSystemGestures(): boolean; set discardSystemGestures(value: boolean) /** * The number of frames that have been rendered since this instance was created. */ get frameID(): number; /** * Indicates if the Context3D object is currently valid (i.e. it hasn't been lost or * * disposed). */ get contextValid(): boolean; } } export default starling.core.Starling;