Commit 85298eab authored by wjf's avatar wjf

l

parent eb22fbd4
# project ignores
node_modules
jsconfig111111.json
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -9,21 +9,32 @@
*/
export const VERSION = "1.0";
/**
* 有问题
* 判读window,标记浏览器环境,到时万一淘宝小程序内也有window,再改
*/
//@ts-ignore
export const sysInfo = my.getSystemInfoSync();
/**
* 有问题
*/
export const devicePixelRatio: number = sysInfo.pixelRatio //window.devicePixelRatio || 1;
export const devicePixelRatio: number = window && (window.devicePixelRatio || 1) || my.getSystemInfoSync().pixelRatio;
/**
* 获取设备号iOS Android
* 先判断浏览器环境设备号,没有就是小程序环境
*/
export const osType: "ios" | "android" = sysInfo.platform.toLowerCase()
export const osType: "ios" | "android" | "pc" = navigator && navigator.userAgent && (function () {
let n = navigator.userAgent.toLocaleLowerCase();
let reg1 = /android/;
let reg2 = /iphone|ipod|ipad/;
if (reg1.test(n)) {
return "android";
} else if (reg2.test(n)) {
return "ios"
} else {
return "pc";
}
})()
//@ts-ignore
|| my.getSystemInfoSync().platform.toLowerCase()
let PI: number = Math.PI;
......
......@@ -2,7 +2,7 @@
import { DisplayObject } from './DisplayObject';
import { Rectangle } from "../math/Rectangle";
import { Point } from '../math';
import {CanvasRenderer} from '../renderers/CanvasRenderer';
import { CanvasRenderer } from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
/**
......@@ -49,7 +49,7 @@ export default class Container extends DisplayObject {
* @param {DisplayObject} child
* @return {DisplayObject}
*/
addChild(child: DisplayObject): DisplayObject {
addChild<T extends DisplayObject>(child: T): T {
//默认添加在最顶层
this.addChildAt(child, this.children.length);
return child;
......@@ -61,7 +61,7 @@ export default class Container extends DisplayObject {
* @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added.
*/
addChildAt(child: DisplayObject, index: number): DisplayObject {
addChildAt<T extends DisplayObject>(child: T, index: number): T {
if (!child) return;
let s = this;
......
......@@ -342,8 +342,8 @@ export class Stage extends Container {
} else {
cp = new Point();
}
cp.x = (points[o].x || points[o].b) * s.dpi// devicePixelRatio;
cp.y = (points[o].y || points[o].c) * s.dpi// devicePixelRatio;
cp.x = (points[o].pageX || points[o].x || points[o].b) * s.dpi// devicePixelRatio;
cp.y = (points[o].pageY || points[o].y || points[o].c) * s.dpi// devicePixelRatio;
// my.alert({
// title: JSON.stringify(points[o])
// });
......
......@@ -73,7 +73,7 @@ export class EventDispatcher extends HashObject {
* @example
* this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this);
*/
public addEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): void {
public addEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
if (!type) {
throw new Error("添加侦听的type值为undefined");
}
......@@ -99,14 +99,14 @@ export class EventDispatcher extends HashObject {
let ee: EE = eventTypes[type][i]
if (ee.fn === listener && ee.context === context) {
console.log("已添加过该事件")
return
return s
}
}
eventTypes[type].unshift(new EE(listener, context || s));
if (type.indexOf("onMouse") == 0) {
s._changeMouseCount(type, true);
}
return s
}
/**
......@@ -116,7 +116,7 @@ export class EventDispatcher extends HashObject {
* @param context
* @param useCapture
*/
public once(type: string, listener: Function, context?: any, useCapture: boolean = true): void {
public once(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
if (!type) {
throw new Error("添加侦听的type值为undefined");
}
......@@ -136,6 +136,7 @@ export class EventDispatcher extends HashObject {
if (type.indexOf("onMouse") == 0) {
s._changeMouseCount(type, true);
}
return s
}
/**
......@@ -255,7 +256,7 @@ export class EventDispatcher extends HashObject {
* @param context listener和context都相等的才移除,默认自身
* @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true
*/
public removeEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): void {
public removeEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
let s = this;
let listeners: EE[] = s.eventTypes[type];
if (!useCapture) {
......@@ -279,6 +280,7 @@ export class EventDispatcher extends HashObject {
// }
}
}
return s
}
/**
......
......@@ -8,7 +8,7 @@ import { sign, string2hex, hex2rgb } from '../utils';
import { SHAPES, PI_2, SCALE_MODES, WRAP_MODES, BLEND_MODES } from '../const';
import { DisplayObject } from '../display/DisplayObject';
import Texture from '../texture/Texture';
import {CanvasRenderer} from '../renderers/CanvasRenderer';
import { CanvasRenderer } from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
import buildPoly from './geomBuild/buildPoly';
......@@ -20,7 +20,7 @@ import FillStyle from './styles/FillStyle';
import LineStyle from './styles/LineStyle';
import { GRAPHICS_CURVES, quadraticCurveLength, bezierCurveLength, bezierCurveTo } from './utils';
import Container from '../display/Container';
let canvasRenderer: CanvasRenderer;
const tempMatrix = new Matrix();
const tempPoint = new Point();
const tempColor1 = new Float32Array(4);
......@@ -1353,39 +1353,39 @@ export default class Graphics extends Container {
* @return {Texture} The new texture.
*/
private generateCanvasTexture(scaleMode: number = SCALE_MODES.LINEAR): Texture {
// this.updateLocalBoundsSelf();
// const bounds = this._localBoundsSelf;
// if (!this._canvasBuffer) {
// this._canvasBuffer = RenderTexture.create(bounds.width, bounds.height, scaleMode);
// } else {
// this._canvasBuffer.resize(bounds.width, bounds.height)
// }
// if (!canvasRenderer) {
// canvasRenderer = new CanvasRenderer({});
// }
// this.transform.updateLocalMatrix();
// tempMatrix.copy(this.transform.localMatrix);
// tempMatrix.invert();
// tempMatrix.tx -= bounds.x;
// tempMatrix.ty -= bounds.y;
// canvasRenderer.render(this, this._canvasBuffer, tempMatrix);
// // document.body.appendChild(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas)
// if (!this._texture) {
// this._texture = Texture.fromCanvas(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas, scaleMode, 'graphics');
// this._texture.baseTexture.update();
// } else {
// this._texture.baseTexture.update();
// }
// //可能需要更改_texture,this._texture.baseTexture尺寸
// this.offsetX = bounds.x;
// this.offsetY = bounds.y;
// return this._texture;
return
this.updateLocalBoundsSelf();
const bounds = this._localBoundsSelf;
if (!this._canvasBuffer) {
this._canvasBuffer = RenderTexture.create(bounds.width, bounds.height, scaleMode);
} else {
this._canvasBuffer.resize(bounds.width, bounds.height)
}
if (!canvasRenderer) {
canvasRenderer = new CanvasRenderer(null, 0, 0);
}
this.transform.updateLocalMatrix();
tempMatrix.copy(this.transform.localMatrix);
tempMatrix.invert();
tempMatrix.tx -= bounds.x;
tempMatrix.ty -= bounds.y;
canvasRenderer.render(this, this._canvasBuffer, tempMatrix);
// document.body.appendChild(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas)
if (!this._texture) {
this._texture = Texture.fromCanvas(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas, 'graphics');
this._texture.baseTexture.update();
} else {
this._texture.baseTexture.update();
}
//可能需要更改_texture,this._texture.baseTexture尺寸
this.offsetX = bounds.x;
this.offsetY = bounds.y;
return this._texture;
// return
}
/**
......
......@@ -74,7 +74,8 @@ export class Loader extends EventDispatcher {
// })
}
loadJson(callback, url) {
window["my"].request({
//@ts-ignore
my.request({
url: url,
dataType: "json",
success: (res) => {
......
......@@ -15,6 +15,13 @@ import { mapCanvasBlendModes } from "../utils";
* 暂时不用,用时再说
*/
export class CanvasRenderer extends SystemRenderer {
/**
* 主屏幕渲染上下文
*/
rootContext: CanvasRenderingContext2D;
/**
* 当前使用的上下文
*/
context: CanvasRenderingContext2D;
/**
* 遮罩管理类
......@@ -43,7 +50,7 @@ export class CanvasRenderer extends SystemRenderer {
this.type = RENDERER_TYPE.CANVAS
this._instanceType = "CanvasRenderer";
this.context = context;
this.rootContext = context;
this.maskManager = new CanvasMaskManager(this);
......@@ -73,8 +80,7 @@ export class CanvasRenderer extends SystemRenderer {
//渲染开始前触发
this.dispatchEvent('prerender');
//
let context = this.context;
//是否渲染到主屏幕
let renderingToScreen = !renderTexture;
if (renderTexture) {
......@@ -92,9 +98,14 @@ export class CanvasRenderer extends SystemRenderer {
renderTexture._canvasRenderTarget.resize(renderTexture.width, renderTexture.height);
}
//当前上下文要修改成离屏的
context = renderTexture._canvasRenderTarget.context;
this.context = renderTexture._canvasRenderTarget.context;
} else {
//当前上下文就是根节点的
this.context = this.rootContext;
}
const context = this.context;
if (!renderTexture) {
this._lastObjectRendered = displayObject;
}
......
......@@ -21,10 +21,10 @@ export default class CanvasRenderTarget {
constructor(width: number, height: number) {
this.canvas =createCanvas() //document.createElement('canvas');
// console.log("rd1",this.canvas)
this.resize(width, height);//要先设置尺寸?
this.context = this.canvas.getContext('2d');
// console.log("rd",this.context)
this.resize(width, height);
}
......
......@@ -33,33 +33,39 @@ export class TextField extends Sprite {
super();
this._instanceType = "TextField";
//ios直接
if (osType == "ios") {
// if (osType == "ios") {
var canvas = createCanvas()
canvas.width = 3;
canvas.height = 3;
// canvas.width = 3;
// canvas.height = 3;
if (osType == "ios") {
canvas.width = canvas.height = 3;
} else {//现在只能用canvas2d渲染,所以不能用imageData了,等修复了安卓canvas尺寸问题再改
canvas.width = 300;
canvas.height = 150;
}
this.texture = Texture.fromCanvas(canvas, "textCanvas");
this.canvas = canvas;
this.context = canvas.getContext("2d");
}
//安卓的不能改变离屏canvas的尺寸,所以用750*750的,取imageData
else {
if (!TextField.shareCanvas) {
TextField.shareCanvas = createCanvas();
TextField.shareCanvas.width = TextField.shareCanvas.height = 750;
TextField.shareContext = TextField.shareCanvas.getContext("2d");
}
var baseTexture = new BaseTexture({
data: [],
width: 0,
height: 0,
type: "text",
path: null
});
this.texture = new Texture(baseTexture);
// }
// //安卓的不能改变离屏canvas的尺寸,所以用750*750的,取imageData
// else {
// if (!TextField.shareCanvas) {
// TextField.shareCanvas = createCanvas();
// TextField.shareCanvas.width = TextField.shareCanvas.height = 750;
// TextField.shareContext = TextField.shareCanvas.getContext("2d");
// }
// var baseTexture = new BaseTexture({
// data: [],
// width: 0,
// height: 0,
// type: "text",
// path: null
// });
// this.texture = new Texture(baseTexture);
this.canvas = TextField.shareCanvas;
this.context = TextField.shareContext;
}
// this.canvas = TextField.shareCanvas;
// this.context = TextField.shareContext;
// }
//baseTexture已自动缓存,把texture也缓存,key textCanvas+num 和baseTexture的一致
Texture.addToCache(this.texture, this.texture.baseTexture.textureCacheIds[0]);
......@@ -488,7 +494,7 @@ export class TextField extends Sprite {
if (osType == "ios") {
s.canvas.width = 0;
s.canvas.height = 0;
} else {
} else {//暂时不能用sourceData形式,所以和上面效果一样
s.texture.baseTexture.source.width = 0;
s.texture.baseTexture.source.height = 0;
}
......@@ -598,33 +604,36 @@ export class TextField extends Sprite {
}
}
for (let i = 0; i < realLines.length; i++) {
let ox = 0;
//@ts-ignore 现在貌似小程序的textAlign有点问题,如果修复了再说
if (my) ox = - tx;//移回去
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(realLines[i], 0, upY + i * lineH, maxW);
ctx.strokeText(realLines[i], ox, upY + i * lineH, maxW);
}
ctx.fillText(realLines[i], 0, upY + i * lineH, maxW);
ctx.fillText(realLines[i], ox, upY + i * lineH, maxW);
}
//offset用_anchorTexture代替
s.offsetX = -padding;
s.offsetY = -padding;
// console.log(can)
this.anchorTexture = { x: (padding + 0.5) / canWidth, y: padding / canHeight }
if (osType == "ios") {
// if (osType == "ios") {
s.texture.update();
s._onTextureUpdate();
} else {
var imgData = ctx.getImageData(0, 0, canWidth, canHeight)
var data = {
data: new Uint8Array(imgData.data),
width: canWidth,
height: canHeight,
type: "text",
path: null
}
s.texture.baseTexture._sourceChange(data);
s._onTextureUpdate();
}
// } else {
// var imgData = ctx.getImageData(0, 0, canWidth, canHeight)
// var data = {
// data: new Uint8Array(imgData.data),
// width: canWidth,
// height: canHeight,
// type: "text",
// path: null
// }
// s.texture.baseTexture._sourceChange(data);
// s._onTextureUpdate();
// }
}
......
......@@ -142,7 +142,7 @@ export default class Texture extends EventDispatcher {
this._rotate = Number(rotate || 0);
if (baseTexture.hasLoaded) {
if (baseTexture.hasLoaded) {//对于canvas形式的判断hasLoaded有问题,导致不能监听update,到时改
if (this.noFrame) {
frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height);
// if there is no frame we should monitor for any base texture changes..
......
/**
* ios还有问题,先别用
*/
export function createCanvas(): HTMLCanvasElement {
//@ts-ignore
return my && my._createOffscreenCanvas() || document.createElement("canvas")
return document && document.createElement("canvas") || my._createOffscreenCanvas() || document.createElement("canvas")
}
//每次都要重置
let backupCanvasContext: CanvasRenderingContext2D
......@@ -48,8 +46,8 @@ export function getCreateImage() {
return contentByCanvas && contentByCanvas.createImage || (() => { return new Image() })
}
export function getRequestAnimationFrame() {
return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame
return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame.bind(window)
}
export function getCancelAnimationFrame() {
return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame
return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame.bind(window)
}
......@@ -2,6 +2,7 @@ import { CanvasRenderer } from "../renderers/CanvasRenderer";
import RenderTexture from "../texture/RenderTexture";
import { Matrix, Rectangle } from "../math";
import { DisplayObject } from "../display/DisplayObject";
import { createCanvas } from "./tbminiAdapte";
// 作为将显示对象导出成图片的render渲染器
let _dRender: CanvasRenderer = null;
......@@ -37,7 +38,7 @@ export default function toDisplayDataURL(obj: DisplayObject, rect: Rectangle = n
let x: number = rect ? rect.x : bounds.x;
let y: number = rect ? rect.y : bounds.y;
if (!_dRender) {
var canvas: HTMLCanvasElement = window["my"].createOffscreenCanvas();
var canvas: HTMLCanvasElement = createCanvas();
canvas.width = w;
canvas.height = h;
_dCanvas = canvas
......
......@@ -34,7 +34,7 @@ var Stats = function (canvasId) {
//@ts-ignore
Stats.Panel = function (canvasId, name, fg, bg) {
var min = Infinity, max = 0, round = Math.round;
var PR = 1;
var PR = 3;
var WIDTH = 80 * PR, HEIGHT = 48 * PR,
TEXT_X = 3 * PR, TEXT_Y = 2 * PR,
......@@ -44,13 +44,21 @@ Stats.Panel = function (canvasId, name, fg, bg) {
var GRAPH_SIZE = GRAPH_WIDTH / PR;
var items = [];
var context //= my.createCanvasContext(canvasId);
//@ts-ignore
var context = my.createCanvasContext(canvasId);
my.createCanvas({
id: canvasId,
success: (ccc) => {
context = ccc.getContext("2d")
context.font = 'bold ' + (9 * PR) + 'px Helvetica,Arial,sans-serif';
context.setTextBaseline('top');
// context.setTextBaseline('top');
context.textBaseline = 'top'
drawWithoutGraph(name);
context.draw();
// context.draw();
}
})
return {
update: function (value, maxValue) {
......@@ -68,33 +76,42 @@ Stats.Panel = function (canvasId, name, fg, bg) {
for (var i = 0; i < items.length; i++) {
var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR;
context.setFillStyle(fg);
context.setGlobalAlpha(1);
// context.setFillStyle(fg);
// context.setGlobalAlpha(1);
context.fillStyle = fg;
context.globalAlpha = 1;
context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
// context.setFillStyle(bg);
// context.setGlobalAlpha(0.9);
context.fillStyle = bg;
context.globalAlpha = 0.9;
context.fillRect(startPos, GRAPH_Y, PR, round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT));
}
context.draw();
// context.draw();
}
};
function drawWithoutGraph(text) {
// bg
context.setFillStyle(bg);
context.setGlobalAlpha(1);
// context.setFillStyle(bg);
// context.setGlobalAlpha(1);
context.fillStyle = bg;
context.globalAlpha = 1;
context.fillRect(0, 0, WIDTH, HEIGHT);
// text
context.setFillStyle(fg);
// context.setFillStyle(fg);
context.fillStyle = fg;
context.fillText(text, TEXT_X, TEXT_Y);
// graph bg
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
// context.setFillStyle(bg);
// context.setGlobalAlpha(0.9);
context.fillStyle = bg;
context.globalAlpha = 0.9;
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
}
};
......
/**
* @author mrdoob / http://mrdoob.com/
*/
var Stats = function (canvasId) {
var beginTime = Date.now(), prevTime = beginTime, frames = 0;
//@ts-ignore
var fpsPanel = new Stats.Panel(canvasId, 'FPS', '#0ff', '#002');
return {
begin: function () {
beginTime = Date.now();
},
end: function () {
frames++;
var time = Date.now();
if (time >= prevTime + 1000) {
fpsPanel.update((frames * 1000) / (time - prevTime), 100.0);
prevTime = time;
frames = 0;
}
return time;
},
update: function () {
beginTime = this.end();
},
};
};
//@ts-ignore
Stats.Panel = function (canvasId, name, fg, bg) {
var min = Infinity, max = 0, round = Math.round;
var PR = 1;
var WIDTH = 80 * PR, HEIGHT = 48 * PR,
TEXT_X = 3 * PR, TEXT_Y = 2 * PR,
GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR,
GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR;
var GRAPH_SIZE = GRAPH_WIDTH / PR;
var items = [];
//@ts-ignore
var context = my.createCanvasContext(canvasId);
context.font = 'bold ' + (9 * PR) + 'px Helvetica,Arial,sans-serif';
context.setTextBaseline('top');
drawWithoutGraph(name);
context.draw();
return {
update: function (value, maxValue) {
items.push(value);
while (items.length > GRAPH_SIZE) {
items.shift();
}
min = Math.min(min, value);
max = Math.max(max, value);
drawWithoutGraph(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')');
// graph inner
for (var i = 0; i < items.length; i++) {
var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR;
context.setFillStyle(fg);
context.setGlobalAlpha(1);
context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
context.fillRect(startPos, GRAPH_Y, PR, round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT));
}
context.draw();
}
};
function drawWithoutGraph(text) {
// bg
context.setFillStyle(bg);
context.setGlobalAlpha(1);
context.fillRect(0, 0, WIDTH, HEIGHT);
// text
context.setFillStyle(fg);
context.fillText(text, TEXT_X, TEXT_Y);
// graph bg
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
}
};
export { Stats /*as default*/ };
......@@ -37,6 +37,7 @@ export * from "./sound"
export * from "./tween";
if(window)window["my"]=null
// export * from "./Stats";
/**
......
......@@ -111,7 +111,7 @@ export class SoundChannel extends EventDispatcher {
let url = this.$url;
//延迟一定时间再停止,规避chrome报错
window.setTimeout(function () {
setTimeout(function () {
audio.pause();
Sound.$recycle(url, audio);
}, 200);
......
......@@ -1227,7 +1227,7 @@ export class EventDispatcher extends HashObject {
* @example
* this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this);
*/
addEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): void;
addEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/**
* 监听一次
* @param type
......@@ -1235,7 +1235,7 @@ export class EventDispatcher extends HashObject {
* @param context
* @param useCapture
*/
once(type: string, listener: Function, context?: any, useCapture?: boolean): void;
once(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/**
* 增加或删除相应mouse或touch侦听记数
* @method _changeMouseCount
......@@ -1285,7 +1285,7 @@ export class EventDispatcher extends HashObject {
* @param context listener和context都相等的才移除,默认自身
* @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true
*/
removeEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): void;
removeEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/**
* 移除对象中所有的侦听
* @method removeAllEventListener
......@@ -1336,11 +1336,9 @@ export class Point extends HashObject {
export const VERSION = "1.0";
export const sysInfo: any;
export const devicePixelRatio: number;
export const osType: "ios" | "android";
export const osType: "ios" | "android" | "pc";
export function cos(angle: number): number;
......@@ -2206,9 +2204,9 @@ export function destroyCanvasContent(): void;
export function getCreateImage(): () => HTMLImageElement;
export function getRequestAnimationFrame(): (fun: Function) => number;
export function getRequestAnimationFrame(): any;
export function getCancelAnimationFrame(): (id: any) => void;
export function getCancelAnimationFrame(): any;
export const INT_BITS1 = 32;
......@@ -4633,6 +4631,13 @@ export class CanvasRenderTarget {
}
export class CanvasRenderer extends SystemRenderer {
/**
* 主屏幕渲染上下文
*/
rootContext: CanvasRenderingContext2D;
/**
* 当前使用的上下文
*/
context: CanvasRenderingContext2D;
/**
* 遮罩管理类
......@@ -4901,17 +4906,25 @@ export class BaseTexture extends EventDispatcher {
*/
dispose(): void;
/**
*
* 根据路径
* @param {string} url 路径
*/
static fromUrl(url: string): any;
static fromSource(source: any): BaseTexture;
/**
* 随便啥形式的,比如data,
* @param data
*/
static fromData(data: any): BaseTexture;
/**
* 从离屏canvas创建的
*/
static fromCanvas(canvas: HTMLCanvasElement, origin?: string): any;
static fromImage(image: HTMLImageElement): BaseTexture;
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement): any;
/**
* 根据图片
* @param image
*/
static fromImage(image: HTMLImageElement): any;
static from(anything: string | HTMLCanvasElement | HTMLImageElement): any;
/**
* 加入缓存
* @static
......@@ -5109,9 +5122,9 @@ export class Texture extends EventDispatcher {
*/
static fromUrl(url: string): any;
static fromCanvas(canvas: HTMLCanvasElement, origin?: string): Texture;
static fromSource(source: any): Texture;
static fromData(data: any): Texture;
static fromImage(image: HTMLImageElement): Texture;
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement): any;
static from(anything: string | HTMLCanvasElement | HTMLImageElement): any;
/**
* 加入全局缓存,TextureCache[name]调用
* @static
......@@ -5987,14 +6000,14 @@ export class Container extends DisplayObject {
* @param {DisplayObject} child
* @return {DisplayObject}
*/
addChild(child: DisplayObject): DisplayObject;
addChild<T extends DisplayObject>(child: T): T;
/**
* 在相应index处添加child
* @param {DisplayObject} child - The child to add
* @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added.
*/
addChildAt(child: DisplayObject, index: number): DisplayObject;
addChildAt<T extends DisplayObject>(child: T, index: number): T;
/**
* 只用于交换索引
* @param {DisplayObject} child - First display object to swap
......@@ -7405,5 +7418,124 @@ export class ShowWord extends TextField {
* @param callback 播放完后的回调
*/
playWords(text: string, deltaTime?: number, callback?: Function): void;
}
export interface InnerAudioContext {
src: string;
startTime: number;
autoplay: boolean;
loop: boolean;
obeyMuteSwitch: boolean;
duration: number;
currentTime: number;
paused: boolean;
buffered: number;
volume: number;
isRecordAudioPlayState: boolean;
play: () => void;
pause: () => void;
stop: void;
seek: (postion: number) => void;
destroy: void;
onCanplay: (fun: () => void) => void;
onPlay: (fun: () => void) => void;
onPause: (fun: () => void) => void;
onStop: (fun: () => void) => void;
onEnded: (fun: () => void) => void;
onTimeUpdate: (fun: () => void) => void;
onError: (fun: () => void) => void;
onWaiting: (fun: () => void) => void;
onSeeking: (fun: () => void) => void;
onSeeked: (fun: () => void) => void;
}
export function $pushSoundChannel(channel: SoundChannel): void;
export function $popSoundChannel(channel: SoundChannel): boolean;
export class Sound extends EventDispatcher {
/**
* 记录的路径
*/
private url;
/**
* 有url了,貌似就没必要了
*/
private originAudio;
/**
* @private
*/
private loaded;
constructor();
readonly length: number;
load(url: string): void;
/**
* @inheritDoc
*/
play(startTime?: number, loops?: number): SoundChannel;
/**
* @inheritDoc
*/
close(): void;
/**
* @private
*/
private static audios;
private static clearAudios;
static $clear(url: string): void;
static $pop(url: string): InnerAudioContext;
static $recycle(url: string, audio: InnerAudioContext): void;
}
export class SoundChannel extends EventDispatcher {
/**
* @private
*/
$url: string;
/**
* @private
*/
$loops: number;
/**
* @private
*/
$startTime: number;
/**
* @private
*/
private audio;
private isStopped;
/**
* @private
*/
constructor(audio: InnerAudioContext);
private canPlay;
$play(): void;
/**
* @private
*/
private onPlayEnd;
/**
* @private
* @inheritDoc
*/
stop(): void;
/**
* @private
*/
private _volume;
/**
* @private
* @inheritDoc
*/
/**
* @inheritDoc
*/
volume: number;
/**
* @private
* @inheritDoc
*/
readonly position: number;
}}
declare module "fyge" {export = FYGE;}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment