Commit 16f854c7 authored by rockyl's avatar rockyl

修复onUpdate时间戳是负数的问题

修复了Engine.stop()方法
parent 0a4af8af
......@@ -20,6 +20,11 @@ export default {
file: `dist/index.es.js`,
format: 'es',
},
{
file: `dist/scilla.js`,
format: 'umd',
name,
},
{
file: `dist/index.js`,
format: 'umd',
......
......@@ -12,6 +12,7 @@ import './requestAnimationFrame';
import {AssetsManager} from "../assets-manager";
import {traverse, traversePostorder} from "./utils";
import DataCenter from "../support/DataCenter";
import {getDefByName} from "./interpreter";
/**
* 引擎类
......@@ -44,6 +45,7 @@ export class ScillaEngine {
private tsStart;
private tsLast;
private lastFPS = 0;
private tickId;
private _renderContext: RenderContext;
private _interactContext: InteractContext;
......@@ -109,7 +111,7 @@ export class ScillaEngine {
start() {
this._root.enabled = true;
this.tsStart = Date.now();
this.tsStart = -1;
this.startTick();
}
......@@ -215,14 +217,14 @@ export class ScillaEngine {
this._flush = 0;
}
requestAnimationFrame(this.flush);
this.tickId = requestAnimationFrame(this.flush);
}
/**
* 停止时钟
*/
private stopTick() {
cancelAnimationFrame(this.tickId);
}
/**
......@@ -240,7 +242,7 @@ export class ScillaEngine {
}
}
requestAnimationFrame(this.flush);
this.tickId = requestAnimationFrame(this.flush);
}
/**
......@@ -253,8 +255,11 @@ export class ScillaEngine {
}
private onFrameTick(tsNow) {
if(this.tsStart < 0){
this.tsStart = tsNow;
}
this._renderContext.clear();
const tsNow2 = Date.now();
this.lastFPS = Math.floor(1000 / (tsNow - this.tsLast));
this.tsLast = tsNow;
const ts = tsNow - this.tsStart;
......@@ -267,7 +272,6 @@ export class ScillaEngine {
}, -1, true, function (current) {
current.afterUpdate();
});
//const tsPass = Date.now() - tsNow;
for (let i = 0, li = this.nextTicks.length; i < li; i++) {
const item = this.nextTicks[i];
......@@ -315,11 +319,32 @@ export class ScillaEngine {
/**
* 射线测试获取实体
* 注:暂时只用在编辑器内
*/
getEntitiesByRayTest(x, y) {
getEntitiesByRayTest(x, y, ignoreMask = true) {
const entities = [];
const localPos: any = {};
let rendererDef = getDefByName('components/renderer/Renderer');
traversePostorder(this._root, function (child) {
return child.onInteract(2, event);
})
const transform = child.components[0];
const matrix = transform['getMatrix'](true, true, true);
matrix.transformPoint(x, y, localPos);
const renderers = child.getComponents(rendererDef);
let result = false;
for (let renderer of renderers) {
if ((ignoreMask || !renderer['isUsedToMask']) && renderer['hitTest'](localPos.x, localPos.y)) {
result = true;
break
}
}
if (result) {
entities.push(child);
}
return false;
});
return entities;
}
/**
......
......@@ -90,24 +90,3 @@ export function bubbling(target: Entity, hitParent: (parent: Entity, ...params)
}
}
}
export function hitTest(entity: Entity){
const transform = entity.components[0];
const matrix = transform.getMatrix(true, true, true);
matrix.transformPoint(e.x, e.y, this.localPos);
let result = false;
const renderers = entity.getComponents(Renderer);
for (let renderer of renderers) {
if (renderer.hitTest(this.localPos.x, this.localPos.y)) {
if (!renderer['isUsedToMask']) {
result = true;
break
}
} else if (renderer['isUsedToMask']) {
return false
}
}
return result;
}
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