UNPKG

cocos2dx

Version:
1,607 lines (1,462 loc) 159 kB
/**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2011 Zynga Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ declare var ccui; declare var ccs; declare module cc { var director: Director; var winSize: cc.Size; var view: GLView; var game: Game; var loader: Loader; var visibleRect: { topLeft: cc.Point; topRight: cc.Point; top: cc.Point; bottomLeft: cc.Point; bottomRight: cc.Point; bottom: cc.Point; center: cc.Point; left: cc.Point; right: cc.Point; width: number; height: number; }; var KEY: { backspace: number; tab: number; enter: number; shift: number; //should use shiftkey instead ctrl: number; //should use ctrlkey alt: number; //should use altkey pause: number; capslock: number; escape: number; pageup: number; pagedown: number; end: number; home: number; left: number; up: number; right: number; down: number; insert: number; Delete: number; 0: number; 1: number; 2: number; 3: number; 4: number; 5: number; 6: number; 7: number; 8: number; 9: number; a: number; b: number; c: number; d: number; e: number; f: number; g: number; h: number; i: number; j: number; k: number; l: number; m: number; n: number; o: number; p: number; q: number; r: number; s: number; t: number; u: number; v: number; w: number; x: number; y: number; z: number; num0: number; num1: number; num2: number; num3: number; num4: number; num5: number; num6: number; num7: number; num8: number; num9: number; '*': number; '+': number; '-': number; numdel: number; '/': number; f1: number; //f1-f12 dont work on ie f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; f11: number; f12: number; numlock: number; scrolllock: number; semicolon: number; ',': number; equal: number; '=': number; ';': number; comma: number; dash: number; '.': number; period: number; forwardslash: number; grave: number; '[': number; openbracket: number; ']': number; closebracket: number; backslash: number; quote: number; space: number; }; var SCROLLVIEW_DIRECTION_NONE: number; var SCROLLVIEW_DIRECTION_HORIZONTAL: number; var SCROLLVIEW_DIRECTION_VERTICAL: number; var SCROLLVIEW_DIRECTION_BOTH: number; var TABLEVIEW_FILL_TOPDOWN: number; var TABLEVIEW_FILL_BOTTOMUP: number; var CONTROL_STATE_NORMAL: number; var CONTROL_STATE_HIGHLIGHTED: number; var CONTROL_STATE_DISABLED: number; var CONTROL_STATE_SELECTED: number; var CONTROL_STATE_INITIAL: number; var _RENDER_TYPE_CANVAS: number; var _RENDER_TYPE_WEBGL: number; var eventManager: EventManager; class Game { constructor(); // Game Configurations CONFIG_KEY: { width: string; height: string; modules: string; debugMode: string; showFPS: string; frameRate: string; id: string; renderMode: string; jsList: string; }; // ================================ // Rendering Types // ================================ readonly RENDER_TYPE_CANVAS: number; // Uses 2D Canvas rendering readonly RENDER_TYPE_WEBGL: number; // Uses WebGL rendering readonly RENDER_TYPE_UNKNOWN: number; // Unknown rendering type // ================================ // Debug Modes // ================================ readonly DEBUG_MODE_NONE: number; // No debug info readonly DEBUG_MODE_INFO: number; // Show basic info readonly DEBUG_MODE_WARN: number; // Show warnings readonly DEBUG_MODE_ERROR: number; // Show only errors readonly DEBUG_MODE_INFO_FOR_WEB_PAGE: number; // Display info in a web page readonly DEBUG_MODE_WARN_FOR_WEB_PAGE: number; // Display warnings in a web page readonly DEBUG_MODE_ERROR_FOR_WEB_PAGE: number; // Display errors in a web page // ================================ // Game States // ================================ readonly EVENT_HIDE: string; // Game is hidden readonly EVENT_SHOW: string; // Game is visible readonly STATE_INIT: number; // Game is initializing readonly STATE_CONFIGURED: number; // Game is configured readonly STATE_RUNNING: number; // Game is running onStart: () => void; // Callback when game starts onStop: () => void; // Callback when game stops // Initialization and Running init(config: any): void; run(config?: any, onStart?: Function): void; // Pause and Resume pause(): void; resume(): void; // Other Methods end(): void; restart(): void; prepare(onPrepared?: Function): void; setFrameRate(frameRate: number): void; getFrameRate(): number; getFrameSize(): cc.Size; setFrameSize(width: number, height: number): void; getRenderType(): number; getVersion(): string; } class Touch extends Class { getPreviousLocationInView(): Point; getLocation(): Point; getDelta(); getStartLocationInView(): Point; getStartLocation(): Point; getId(); setTouchInfo(); getLocationInView(); getPreviousLocation(); } class Event extends Class { static TOUCH: number; static KEYBOARD: number; static ACCELERATION: number; static MOUSE: number; static CUSTOM: number; constructor(type: number); getType(): number; stopPropagation(); isStopped(): boolean; getCurrentTarget(); } class EventCustom extends Event { constructor(eventName: string, userData?); getEventName(): string; setUserData(data); getUserData(); } class EventCustomUserData { _eventName: string; _userData: any; } class EventTouch extends Event { static MAX_TOUCHES: number; static EventCode: { BEGAN: number; MOVED: number; ENDED: number; CANCELLED: number }; constructor(arr: Array<cc.Touch>); /** * Returns event code * @returns {number} */ getEventCode(): number; /** * Returns touches of event * @returns {Array} */ getTouches(): Array<cc.Touch>; } class EventMouse extends Event { static NONE: number; static DOWN: number; static UP: number; static MOVE: number; static SCROLL: number; static BUTTON_LEFT: number; static BUTTON_RIGHT: number; static BUTTON_MIDDLE: number; static BUTTON_4: number; static BUTTON_5: number; static BUTTON_6: number; static BUTTON_7: number; static BUTTON_8: number; constructor(eventType: number); /** * Sets scroll data * @param {number} scrollX * @param {number} scrollY */ setScrollData(scrollX: number, scrollY: number); /** * Returns the x axis scroll value * @returns {number} */ getScrollX(): number; /** * Returns the y axis scroll value * @returns {number} */ getScrollY(): number; /** * Sets cursor location * @param {number} x * @param {number} y */ setLocation(x: number, y: number); /** * Returns cursor location * @return {cc.Point} location */ getLocation(): cc.Point; /** * Returns the current cursor location in screen coordinates * @return {cc.Point} */ getLocationInView(): cc.Point; /** * Returns the delta distance from the previous location to current location * @return {cc.Point} */ getDelta(): cc.Point; /** * Returns the X axis delta distance from the previous location to current location * @return {Number} */ getDeltaX(): number; /** * Returns the Y axis delta distance from the previous location to current location * @return {Number} */ getDeltaY(): number; /** * Sets mouse button * @param {number} button */ setButton(button: number); /** * Returns mouse button * @returns {number} */ getButton(): number; /** * Returns location X axis data * @returns {number} */ getLocationX(): number; /** * Returns location Y axis data * @returns {number} */ getLocationY(): number; } class EventAcceleration extends Event { constructor(acc); } class EventKeyboard extends Event { constructor(keyCode: number, isPressed: boolean); } class EventManager { addCustomListener(eventName: string, callback: Function): void; addListener(listener: cc.EventListener | Object, nodeOrPriority?: cc.Node | number): void; dispatchCustomEvent(eventName: string, optionalUserData?): void; dispatchEvent(event: cc.Event): void; isEnabled(): boolean; pauseTarget(node: cc.Node, recursive?: boolean): void; removeAllListeners(): void; removeCustomListeners(customEventName: string): void; removeListener(listener: Function): void; removeListeners(listenerType: number | cc.Node, recursive?: boolean): void; resumeTarget(node: cc.Node, recursive?: boolean): void; setEnabled(enabled: boolean): void; setPriority(listener: Function, fixedPriority: number); } class EventListener extends Class { static UNKNOWN: number; static TOUCH_ONE_BY_ONE: number; static TOUCH_ALL_AT_ONCE: number; static KEYBOARD: number; static MOUSE: number; static ACCELERATION: number; static CUSTOM: number; static create(obj: Object): EventListener; } class ClippingNode extends Node { isInverted(): boolean; setInverted(b: boolean); setStencil(n: Node); getAlphaThreshold(): number; init(n: Node); getStencil(): Node; setAlphaThreshold(a: number); static create(n?: Node): ClippingNode; } class MotionStreak extends Node { reset(); setTexture(t: Texture2D); getTexture(): Texture2D; tintWithColor(c: Color); setBlendFunc(func: { src: number; dst: number }); setStartingPositionInitialized(b: boolean); getBlendFunc(): { src: number; dst: number }; isStartingPositionInitialized(): boolean; isFastMode(): boolean; initWithFade(fade: number, minSeg: number, stroke: number, color: Color, sp: string); initWithFade(fade: number, minSeg: number, stroke: number, color: Color, sp: Texture2D); setFastMode(b: boolean); static create(fade: number, minSeg: number, stroke: number, color: Color, sp: string); static create(fade: number, minSeg: number, stroke: number, color: Color, sp: Texture2D); } class DrawNode extends Node { drawTriangle(p1: Point, p2: Point, p3: Point, p4: Point); getBlendFunc(); onDraw(); clear(); setBlendFunc(); init(); drawDot(point: Point, radius: number, color?: Color); drawQuadBezier(); drawCubicBezier(); drawSegment(from: Point, to: Point, radius: number, color?: Color); drawPoly(points: Array<Point>, fillColor: Color, borderWidth: number, borderColor?: Color); drawCircle( center: Point, radius: number, angle: number, segments, drawLineToCenter: boolean, lineWidth?: number, color?: Color ); static create(): DrawNode; } enum ResolutionPolicy { // The entire application is visible in the specified area without trying to preserve the original aspect ratio. // Distortion can occur, and the application may appear stretched or compressed. EXACT_FIT, // The entire application fills the specified area, without distortion but possibly with some cropping, // while maintaining the original aspect ratio of the application. NO_BORDER, // The entire application is visible in the specified area without distortion while maintaining the original // aspect ratio of the application. Borders can appear on two sides of the application. SHOW_ALL, // The application takes the height of the design resolution size and modifies the width of the internal // canvas so that it fits the aspect ratio of the device // no distortion will occur however you must make sure your application works on different // aspect ratios FIXED_HEIGHT, // The application takes the width of the design resolution size and modifies the height of the internal // canvas so that it fits the aspect ratio of the device // no distortion will occur however you must make sure your application works on different // aspect ratios FIXED_WIDTH, UNKNOWN, } class GLView { constructor(); // Resolution Policy setDesignResolutionSize(width: number, height: number, resolutionPolicy: number): void; getDesignResolutionSize(): cc.Size; setResolutionPolicy(resolutionPolicy: number): void; getResolutionPolicy(): number; // Viewport and Scrolling setViewPortInPoints(x: number, y: number, w: number, h: number): void; getViewportRect(): cc.Rect; setScissorInPoints(x: number, y: number, w: number, h: number): void; isScissorEnabled(): boolean; getScissorRect(): cc.Rect; // Screen Size and Scale getFrameSize(): cc.Size; setFrameSize(width: number, height: number): void; resizeWithBrowserSize(enabled: boolean): void; // Device Pixel Ratio and Zoom getDevicePixelRatio(): number; setContentScaleFactor(scaleFactor: number): void; getContentScaleFactor(): number; // Fullscreen and Orientation enableRetina(enabled: boolean): void; adjustViewPort(enabled: boolean): void; isRetinaEnabled(): boolean; setOrientation(orientation: number): void; getOrientation(): number; // Events on(eventName: string, callback: Function, target?: any): void; off(eventName: string, callback: Function, target?: any): void; } class ScrollView extends Layer { isClippingToBounds(); setContainer(node: cc.Node); setContentOffsetInDuration(); setZoomScaleInDuration(); setBounceable(); getDirection(); getContainer(); updateTweenAction(); getZoomScale(); updateInset(); initWithViewSize(size: Size); pause(); setDirection(d: number); init(); setContentOffset(offset: cc.Point, animate?: boolean); isDragging(); isTouchEnabled(); isBounceable(); setTouchEnabled(bool: boolean); getContentOffset(): cc.Point; resume(); setClippingToBounds(); setViewSize(size: cc.Size); getViewSize(): cc.Size; maxContainerOffset(); isTouchMoved(); isNodeVisible(); minContainerOffset(); setZoomScale(); static create(size?: Size, container?: Node); } class TableView extends ScrollView { updateCellAtIndex(idx: number); setVerticalFillOrder(order: number); scrollViewDidZoom(); _updateContentSize(); getVerticalFillOrder(); removeCellAtIndex(); scrollViewDidScroll(); reloadData(); insertCellAtIndex(); cellAtIndex(idx: number): TableViewCell; dequeueCell(); setDelegate(delegate: any); setDataSource(dataSource: Object); static create(dataSource?: Object, size?: Size, container?: Node); } class TableViewCell extends Node { reset(); getIdx(): number; setIdx(idx: number); } class BuilderReader { static load(fileName: string, owner?: Object, parentSize?: Size); } class BuilderAnimationManager { getRunningSequenceName(): string; runAnimationsForSequenceNamed(seq: string, reset?: boolean); setCompletedAnimationCallback(obj: Object, func: Function); getLastCompletedSequenceName(): string; moveAnimationsFromNode(fromNode: cc.Node, toNode: cc.Node); setAutoPlaySequenceId(id: number); getDocumentCallbackNames(); actionForSoundChannel(); setBaseValue(); getDocumentOutletNodes(); setRootNode(); runAnimationsForSequenceNamedTweenDuration(); addDocumentOutletName(); getRootContainerSize(); setDocumentControllerName(); setObject(); getContainerSize(); actionForCallbackChannel(); getDocumentOutletNames(); addDocumentCallbackControlEvents(); init(); getKeyframeCallbacks(); getDocumentCallbackControlEvents(); setRootContainerSize(); runAnimationsForSequenceIdTweenDuration(); getAutoPlaySequenceId(); addDocumentCallbackName(); getRootNode(); addDocumentOutletNode(); setDelegate(); getSequenceDuration(seq: string): number; addDocumentCallbackNode(); runAnimationsForSequenceNamed(); getSequenceId(seq: string): number; setCallFunc(); getDocumentCallbackNodes(); setSequences(); debug(); getDocumentControllerName(); } export class SpriteFrame { clone(); setRotated(); setTexture(); getOffset(); setRectInPixels(); getTexture(): Texture2D; getRect(): Rect; setOffsetInPixels(); getRectInPixels(); setOriginalSize(); getOriginalSizeInPixels(); setOriginalSizeInPixels(); setOffset(); initWithTexture(); isRotated(); initWithTextureFilename(); setRect(); getOffsetInPixels(); getOriginalSize(); static create( fileName: string, rect: Rect, rotated?: boolean, offset?: Point, originalSize?: Size ): SpriteFrame; static createWithTexture( texture: Texture2D, rect: Rect, rotated?: boolean, offset?: Point, originalSize?: Size ): SpriteFrame; } class Scale9Sprite extends Node { resizableSpriteWithCapInsets(); setInsetBottom(); initWithSpriteFrameName(); setInsetTop(); init(); setPreferredSize(); setSpriteFrame(); initWithBatchNode(); getInsetBottom(); getCapInsets(); updateWithBatchNode(); getInsetRight(); getOriginalSize(); initWithFile(); getInsetTop(); setInsetLeft(); initWithSpriteFrame(); getPreferredSize(); setCapInsets(); getInsetLeft(); setInsetRight(); static create(): Scale9Sprite; static createWithSpriteFrameName(name: string): Scale9Sprite; static createWithSpriteFrame(spFrame: SpriteFrame): Scale9Sprite; } class Texture2D { getMaxT(); getStringForFormat(); initWithImage(); getMaxS(); releaseGLTexture(); hasPremultipliedAlpha(); initWithMipmaps(); getPixelsHigh(); getBitsPerPixelForFormat(); getName(); initWithString(); setMaxT(); drawInRect(); getContentSize(): Size; setAliasTexParameters(); setAntiAliasTexParameters(); generateMipmap(); getDescription(); getPixelFormat(); setGLProgram(); getContentSizeInPixels(); getPixelsWide(); drawAtPoint(); getGLProgram(); hasMipmaps(); setMaxS(); static setDefaultAlphaPixelFormat(); static getDefaultAlphaPixelFormat(); static PVRImagesHavePremultipliedAlpha(); } class TextureCache { reloadTexture(); unbindAllImageAsync(); removeTextureForKey(); removeAllTextures(); addImageAsync(); getDescription(); getCachedTextureInfo(); addImage(fileName: string): Texture2D; unbindImageAsync(); getTextureForKey(); removeUnusedTextures(); removeTexture(); waitForQuit(); } class CallFunc { static create(func: Function, _this?: Object); } class EaseExponentialOut { static create(action: Action); } class EaseBackOut { static create(action: Action); } class EaseBackIn { static create(action: Action); } function pSub(p1: Point, p2: Point): Point; function pAdd(p1: Point, p2: Point): Point; function pLerp(p1: Point, p2: Point, alpha: number): Point; function pDistanceSQ(p1: Point, p2: Point): number; function pDistance(p1: Point, p2: Point): number; function pNeg(); function pMult(v: Point, r: Number): Point; function pMidpoint(): Point; function pDot(); function pCross(); function pPerp(); function pRPerp(); function pProject(); function pRotate(); function pNormalize(p: Point): Point; function pClamp(); function pLengthSQ(); function pLength(v: Point): number; var COCOS2D_DEBUG: number; class ParticleSystem extends Node { getStartSizeVar(); getTexture(); isFull(); getBatchNode(); getStartColor(); getPositionType(); setPosVar(); getEndSpin(); setRotatePerSecondVar(); getStartSpinVar(); getRadialAccelVar(); init(); getEndSizeVar(); setRotation(); setTangentialAccel(); setScaleY(); setScaleX(); getRadialAccel(); setStartRadius(); setRotatePerSecond(); setEndSize(); getGravity(); getTangentialAccel(); setEndRadius(); getSpeed(); getAngle(); setEndColor(); setStartSpin(); setDuration(); initWithTotalParticles(); setTexture(); getPosVar(); updateWithNoTime(); isBlendAdditive(); getSpeedVar(); setPositionType(); stopSystem(); getSourcePosition(); setLifeVar(); setTotalParticles(); setEndColorVar(); updateQuadWithParticle(); getAtlasIndex(); getStartSize(); setStartSpinVar(); resetSystem(); setAtlasIndex(); setTangentialAccelVar(); setEndRadiusVar(); getEndRadius(); isOpacityModifyRGB(); isActive(); setRadialAccelVar(); setStartSize(); setSpeed(); getStartSpin(); getRotatePerSecond(); initParticle(); setEmitterMode(); getDuration(): number; setSourcePosition(); getEndSpinVar(); setBlendAdditive(); setLife(); setAngleVar(); setRotationIsDir(); setEndSizeVar(); setAngle(); setBatchNode(); getTangentialAccelVar(); getEmitterMode(); setEndSpinVar(); initWithFile(); getAngleVar(); setStartColor(); getRotatePerSecondVar(); getEndSize(); getLife(); setSpeedVar(); setAutoRemoveOnFinish(b: boolean); setGravity(); postStep(); setEmissionRate(); getEndColorVar(); getRotationIsDir(); setScale(); getEmissionRate(); getEndColor(); getLifeVar(); setStartSizeVar(); setOpacityModifyRGB(); addParticle(); getStartRadius(); getParticleCount(); getStartRadiusVar(); getBlendFunc(); setStartColorVar(); setEndSpin(); setRadialAccel(); initWithDictionary(); isAutoRemoveOnFinish(); getTotalParticles(); setStartRadiusVar(); setBlendFunc(); getEndRadiusVar(); getStartColorVar(); } class ParticleSystemQuad extends ParticleSystem { setDisplayFrame(sp: SpriteFrame); setTextureWithRect(t: Texture2D, r: Rect); static create(dict?: any); static createWithTotalParticles(n: number); } //#region cocos2d/CCCommon.js /** * copy an new object * @function * @param {object|Array} obj source object * @return {Array|object} */ function clone(obj: any); /** * Function added for JS bindings compatibility. Not needed in cocos2d-html5. * @function * @param {object} jsobj subclass * @param {object} klass superclass */ function associateWithNative(jsobj: any, superclass: any); /** * Is show bebug info on web page * @constant * @type {Boolean} */ var IS_SHOW_DEBUG_ON_PAGE: boolean; function log(...any); function error(...any); function assert(condition: boolean, ...any); function warn(...any); /** * Pop out a message box * @param {String} message * @function */ function MessageBox(message: string); /** * Output Assert message. * @function * @param {Boolean} cond If cond is false, assert. * @param {String} message */ function Assert(cond: boolean, message: string); /** * Update Debug setting. * @function */ function initDebugSetting(); // Enum the language type supportted now /** * English language code * @constant * @type Number */ var LANGUAGE_ENGLISH: number; /** * Chinese language code * @constant * @type Number */ var LANGUAGE_CHINESE: number; /** * French language code * @constant * @type Number */ var LANGUAGE_FRENCH: number; /** * Italian language code * @constant * @type Number */ var LANGUAGE_ITALIAN: number; /** * German language code * @constant * @type Number */ var LANGUAGE_GERMAN: number; /** * Spanish language code * @constant * @type Number */ var LANGUAGE_SPANISH: number; /** * Russian language code * @constant * @type Number */ var LANGUAGE_RUSSIAN: number; //#endregion cocos2d/CCCommon.js //#region cocos2d/CCDirector.js /** * <p> * Class that creates and handle the main Window and manages how<br/> * and when to execute the Scenes.<br/> * <br/> * The cc.Director is also responsible for:<br/> * - initializing the OpenGL context<br/> * - setting the OpenGL pixel format (default on is RGB565)<br/> * - setting the OpenGL pixel format (default on is RGB565)<br/> * - setting the OpenGL buffer depth (default one is 0-bit)<br/> * - setting the projection (default one is 3D)<br/> * - setting the orientation (default one is Protrait)<br/> * <br/> * Since the cc.Director is a singleton, the standard way to use it is by calling:<br/> * - cc.Director.getInstance().methodName(); <br/> * <br/> * The CCDirector also sets the default OpenGL context:<br/> * - GL_TEXTURE_2D is enabled<br/> * - GL_VERTEX_ARRAY is enabled<br/> * - GL_COLOR_ARRAY is enabled<br/> * - GL_TEXTURE_COORD_ARRAY is enabled<br/> * </p> * @class * @extends cc.Class */ export class Director extends Class { getScheduler(): Scheduler; /** * returns a shared instance of the director * @function * @return {cc.Director} */ static getInstance(): Director; /** * initializes cc.Director * @return {Boolean} */ init(): boolean; /** * Draw the scene. This method is called every frame. Don't call it manually. */ drawScene(); /** * end director */ end(); /** * <p> * returns the size of the OpenGL view in points.<br/> * It takes into account any possible rotation (device orientation) of the window * </p> * @return {cc.Size} */ getWinSize(): Size; /** * Replaces the running scene with a new one. The running scene is terminated. ONLY call it if there is a running scene. * @param {cc.Scene} scene */ replaceScene(scene: Scene); /** * <p> * Enters the Director's main loop with the given Scene.<br/> * Call it to run only your FIRST scene.<br/> * Don't call it if there is already a running scene. * </p> * @param {cc.Scene} scene */ runScene(scene: Scene); /** * Get the FPS value * @return {Number} */ getAnimationInterval(): number; /** * Whether or not to display the FPS on the bottom-left corner * @return {Boolean} */ isDisplayStats(): boolean; /** * Display the FPS on the bottom-left corner * @param displayFPS */ setDisplayStats(displayStats: boolean); /** * set Animation Interval * @param {Number} value */ setAnimationInterval(value: number); getTextureCache(): TextureCache; } //#endregion cocos2d/CCDirector.js //#region cocos2d/CCDrawingPrimitives.js /** * <p> * Drawing primitives Utility Class. this class is base class, it contain some render type version: Canvas, WebGL, DOM.<br/> * this class contain some primitive Drawing Method: <br/> * - drawPoint<br/> * - drawLine<br/> * - drawPoly<br/> * - drawCircle<br/> * - drawQuadBezier<br/> * - drawCubicBezier<br/> * You can change the color, width and other property by calling these WebGL API:<br/> * glColor4ub(), glLineWidth(), glPointSize().<br/> * </p> * @class * @extends cc.Class * @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. <br/> * If you are going to make a game that depends on these primitives, I suggest creating a batch. */ export class DrawingPrimitive extends Class { /** * set render context of drawing primitive * @param context */ setRenderContext(context: CanvasRenderingContext2D); /** * returns render context of drawing primitive * @return {CanvasContext} */ getRenderContext(): CanvasRenderingContext2D; /** * Constructor * @param {CanvasContext} renderContext */ constructor(renderContext: CanvasRenderingContext2D); /** * draws a point given x and y coordinate measured in points * @param {cc.Point} point */ drawPoint(point: Point); /** * draws an array of points. * @param {Array} points point of array * @param {Number} numberOfPoints */ drawPoints(points: Point[], numberOfPoints: number); /** * draws a line given the origin and destination point measured in points * @param {cc.Point} origin * @param {cc.Point} destination */ drawLine(origin: Point, destination: Point); /** * draws a rectangle given the origin and destination point measured in points. * @param {cc.Point} origin * @param {cc.Point} destination */ drawRect(origin: Point, destination: Point); /** * draws a solid rectangle given the origin and destination point measured in points. * @param {cc.Point} origin * @param {cc.Point} destination * @param {cc.Color} color */ drawSolidRect(origin: Point, destination: Point, color: Color); /** * draws a poligon given a pointer to cc.Point coordiantes and the number of vertices measured in points. * @param {Array} vertices a pointer to cc.Point coordiantes * @param {Number} numOfVertices the number of vertices measured in points * @param {Boolean} closePolygon The polygon can be closed or open * @param {Boolean} fill The polygon can be closed or open and optionally filled with current color */ drawPoly(vertices: Point[], numOfVertices: number, closePolygon: boolean, fill: boolean); /** * draws a solid polygon given a pointer to CGPoint coordiantes, the number of vertices measured in points, and a color. * @param {Array} poli * @param {Number} numberOfPoints * @param {cc.Color} color */ drawSolidPoly(poli: Point[], numberOfPoints: number, color: Color); /** * draws a circle given the center, radius and number of segments. * @param {cc.Point} center center of circle * @param {Number} radius * @param {Number} angle angle in radians * @param {Number} segments * @param {Boolean} drawLineToCenter */ drawCircle( center: Point, radius: number, angle: number, segments: number, drawLineToCenter: boolean ); /** * draws a quad bezier path * @param {cc.Point} origin * @param {cc.Point} control * @param {cc.Point} destination * @param {Number} segments */ drawQuadBezier(origin: Point, control: Point, destination: Point, segments: number); /** * draws a cubic bezier path * @param {cc.Point} origin * @param {cc.Point} control1 * @param {cc.Point} control2 * @param {cc.Point} destination * @param {Number} segments */ drawCubicBezier( origin: Point, control1: Point, control2: Point, destination: Point, segments: number ); /** * draw a catmull rom line * @param {cc.PointArray} points * @param {Number} segments */ drawCatmullRom(points: Point[], segments: number); /** * draw a cardinal spline path * @param {cc.PointArray} config * @param {Number} tension * @param {Number} segments */ drawCardinalSpline(config: Point[], tension: number, segments: number); // FIXME: Typescript doesn't support abstract classes so we have to put the common // methods from DrawingPrimitiveCanvas and DrawingPrimitiveWebGL here for convenience /** * set the drawing color with 4 unsigned bytes * @param {Number} r red value (0 to 255) * @param {Number} r green value (0 to 255) * @param {Number} r blue value (0 to 255) * @param {Number} a Alpha value (0 to 255) */ setDrawColor(r: number, g: number, b: number, a: number); // ENDFIXME } /** * Canvas of DrawingPrimitive implement version * @class * @extends cc.DrawingPrimitive */ export class DrawingPrimitiveCanvas extends DrawingPrimitive {} /** * Canvas of DrawingPrimitive implement version * @class * @extends cc.DrawingPrimitive */ export class DrawingPrimitiveWebGL extends DrawingPrimitive {} //#endregion cocos2d/CCDrawingPrimitives.js //#region cocos2d/CCLoader.js /** * A class to pre-load resources before engine start game main loop. * @class * @extends cc.Scene */ export class Loader extends Class { static preload(resources: any[], selector: () => void, target: Node): Loader; load( resources: | string | string[] | { srcs: string[]; type: string | 'font' | 'image' | 'json' | 'plist'; name?: string; } | { src: string; type: string | 'font' | 'image' | 'json' | 'plist'; name?: string; } | Array<{ src: string; type: string | 'font' | 'image' | 'json' | 'plist'; name?: string; }>, callback?: (error: any, resource: any) => void ): void; // Load a single resource (image, JSON, plist, etc.) load(url: string, callback?: (error: any, resource: any) => void): void; // Load multiple resources load(resources: string[], callback?: (errors: any[], resources: any[]) => void): void; // Load resources and track progress load( resources: string[], progressCallback?: (completedCount: number, totalCount: number, item: any) => void, completeCallback?: (errors: any[], resources: any[]) => void ): void; // Preload resources for use later // preload(resources: string[], callback?: (errors: any[], resources: any[]) => void): void; // Get a cached resource getRes(url: string): any; // Remove a single cached resource release(url: string): void; // Remove multiple cached resources release(resources: string[]): void; // Remove all cached resources releaseAll(): void; loadTxt(url: string, callback?: (error: any, resource: any) => void): void; loadJson(url: string, callback?: (error: any, resource: any) => void): void; loadImg(url: string, option?: any, callback?: (error: any, resource: any) => void): void; } /** * Used to display the loading screen * @class * @extends cc.Scene */ export class LoaderScene extends Scene { static preload(resources: any[], selector: () => void, target: Node): LoaderScene; } //#endregion cocos2d/CCLoader.js //#region cocos2d/CCScheduler.js /** * <p> * Scheduler is responsible of triggering the scheduled callbacks.<br/> * You should not use NSTimer. Instead use this class.<br/> * <br/> * There are 2 different types of callbacks (selectors):<br/> * - update selector: the 'update' selector will be called every frame. You can customize the priority.<br/> * - custom selector: A custom selector will be called every frame, or with a custom interval of time<br/> * <br/> * The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'. * * </p> * @class * @extends cc.Class * * @example * //register a schedule to scheduler * cc.Director.getInstance().getScheduler().scheduleSelector(selector, this, interval, !this._isRunning); */ export class Scheduler extends Class { setTimeScale(scale: number); performFunctionInCocosThread(func: Function); getTimeScale(): number; } //#endregion cocos2d/CCScheduler.js //#region cocos2d/actions/CCAction.js /** * Base class for cc.Action objects. * @class * @extends cc.Class */ export class Action extends Class { clone(): Action; startWithTarget(target: cc.Node); setOriginalTarget(target: cc.Node); getOriginalTarget(): cc.Node; stop(); update(dt: number); getTarget(): cc.Node; step(dt: number); setTag(tag: number); getTag(): number; setTarget(target: cc.Node); isDone(): boolean; reverse(); } /** * <p>Base class actions that do have a finite time duration.<br/> * Possible actions: <br/> * - An action with a duration of 0 seconds<br/> * - An action with a duration of 35.5 seconds </p> * Infinite time actions are valid * @class * @extends cc.Action */ export class FiniteTimeAction extends Action {} //#endregion cocos2d/actions/CCAction.js //#region cocos2d/actions/CCActionInterval.js /** * <p> An interval action is an action that takes place within a certain period of time. <br/> * It has an start time, and a finish time. The finish time is the parameter<br/> * duration plus the start time.</p> * * <p>These CCActionInterval actions have some interesting properties, like:<br/> * - They can run normally (default) <br/> * - They can run reversed with the reverse method <br/> * - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. </p> * * <p>For example, you can simulate a Ping Pong effect running the action normally and<br/> * then running it again in Reverse mode. </p> * * @class * @extends cc.FiniteTimeAction * @Example * // example * var pingPongAction = cc.Sequence.create(action, action.reverse()); */ export class ActionInterval extends FiniteTimeAction {} /** Runs actions sequentially, one after another * @class * @extends cc.ActionInterval */ export class Sequence extends ActionInterval { /** helper constructor to create an array of sequenceable actions * @param {Array|cc.FiniteTimeAction} tempArray * @return {cc.FiniteTimeAction} * @example * // example * // create sequence with actions * var seq = cc.Sequence.create(act1, act2); * * // create sequence with array * var seq = cc.Sequence.create(actArray); */ static create(...rest: FiniteTimeAction[]): Sequence; } /** Repeats an action a number of times. * To repeat an action forever use the CCRepeatForever action. * @class * @extends cc.ActionInterval */ export class Repeat extends ActionInterval { /** creates a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) * @param {cc.FiniteTimeAction} action * @param {Number} times * @return {cc.Repeat} * @example * // example * var rep = cc.Repeat.create(cc.Sequence.create(jump2, jump1), 5); */ static create(action: FiniteTimeAction, times: number): Repeat; } /** Repeats an action for ever. <br/> * To repeat the an action for a limited number of times use the Repeat action. <br/> * @warning This action can't be Sequenceable because it is not an IntervalAction * @class * @extends cc.ActionInterval */ export class RepeatForever extends ActionInterval { /** * Repeat the acton forever * @param action * @return {cc.RepeatForever} * @example * // example * var repeat = cc.RepeatForever.create(cc.RotateBy.create(1.0, 360)); */ static create(action: FiniteTimeAction): RepeatForever; } /** Spawn a new action immediately * @class * @extends cc.ActionInterval */ export class Spawn extends ActionInterval { /** * @param {Array|cc.FiniteTimeAction}tempArray * @return {cc.FiniteTimeAction} * @example * // example * var action = cc.Spawn.create(cc.JumpBy.create(2, cc.p(300, 0), 50, 4), cc.RotateBy.create(2, 720)); */ static create(...rest: FiniteTimeAction[]): Spawn; } /** Rotates a cc.Node object to a certain angle by modifying it's * rotation attribute. <br/> * The direction will be decided by the shortest angle. * @class * @extends cc.ActionInterval */ export class RotateTo extends ActionInterval { /** * creates the action with separate rotation angles * @param {Number} duration duration in seconds * @param {Number} deltaAngleX deltaAngleX in degrees. * @param {Number} deltaAngleY deltaAngleY in degrees. * @return {cc.RotateTo} * @example * // example * var rotateTo = cc.RotateTo.create(2, 61.0); */ static create(duration: number, deltaAngleX: number, deltaAngleY?: number): RotateTo; } /** Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. * @class * @extends cc.ActionInterval */ export class RotateBy extends ActionInterval { /** * @param {Number} duration druation in seconds * @param {Number} deltaAngleX deltaAngleX in degrees * @param {Number} deltaAngleY deltaAngleY in degrees * @return {cc.RotateBy} * @example * // example * var actionBy = cc.RotateBy.create(2, 360); */ static create(duration: number, deltaAngleX: number, deltaAngleY: number): RotateBy; static create(duration: number, angle: number): RotateBy; } /** Moves a cc.Node object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. * @class * @extends cc.ActionInterval */ export class MoveTo extends ActionInterval { /** * @param {Number} duration duration in seconds * @param {cc.Point} position * @return {cc.MoveTo} * @example * // example * var actionTo = cc.MoveTo.create(2, cc.p(windowSize.width - 40, windowSize.height - 40)); */ static create(duration: number, position: Point): MoveTo; } /** Moves a cc.Node object x,y pixels by modifying it's position attribute. <br/> * x and y are relative to the position of the object. <br/> * @class * @extends cc.MoveTo */ export class MoveBy extends MoveTo { /** * @param {Number} duration duration in seconds * @param {cc.Point} position * @return {cc.MoveBy} * @example * // example * var actionBy = cc.MoveBy.create(2, cc.p(80, 80)); */ static create(duration: number, position: Point): MoveBy; } /** Skews a cc.Node object to given angles by modifying it's skewX and skewY attributes * @class * @extends cc.ActionInterval */ export class SkewTo extends ActionInterval { /** * @param {Number} t time in seconds * @param {Number} sx * @param {Number} sy * @return {cc.SkewTo} * @example * // example * var actionTo = cc.SkewTo.create(2, 37.2, -37.2); */ static create(t: number, sx: number, sy: number): SkewTo; } /** Skews a cc.Node object by skewX and skewY degrees * @class * @extends cc.SkewTo */ export class SkewBy extends SkewTo { /** * @param {Number} t time in seconds * @param {Number} sx sx skew in degrees for X axis * @param {Number} sy sy skew in degrees for Y a