Commit be9bee83 authored by wildfirecode's avatar wildfirecode

update

parent 82b0b9a4
module.exports = {
devPort: 8080,
opn:0
}
\ No newline at end of file
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080/egret/",
"webRoot": "${workspaceFolder}"
}
]
}
\ No newline at end of file
No preview for this file type
......@@ -41,6 +41,12 @@
"16705cb4eec": {
"backgroundType": "user",
"backgroundImage": "/Users/wanghongyuan/db-game-template/egret/resource/assets/startScene/startscenebg.jpg",
"backgroundAlpha": 100
"backgroundAlpha": 100,
"backgroundX": 0,
"backgroundY": 0,
"backgroundWidth": -1,
"backgroundHeight": -1,
"useBgImage": true,
"useBgColor": true
}
}
\ No newline at end of file
import { Particle } from "./Particle";
// tslint:disable
export class GravityParticle extends Particle {
public startX: number;
public startY: number;
public velocityX: number;
public velocityY: number;
public radialAcceleration: number;
public tangentialAcceleration: number;
public rotationDelta: number;
public scaleDelta: number;
public alphaDelta: number;
public reset(): void {
super.reset();
this.startX = 0;
this.startY = 0;
this.velocityX = 0;
this.velocityY = 0;
this.radialAcceleration = 0;
this.tangentialAcceleration = 0;
this.rotationDelta = 0;
this.scaleDelta = 0;
}
}
import { ParticleSystem } from "./ParticleSystem";
import { GravityParticle } from "./GravityParticle";
import { Particle } from "./Particle";
// tslint:disable
const enum ParticleKeys {
emitterX,
emitterY,
emitterTime,
maxParticles,
emitterXVariance,
emitterYVariance,
gravityX,
gravityY,
speed,
speedVariance,
lifespan,
lifespanVariance,
emitAngle,
emitAngleVariance,
startSize,
startSizeVariance,
endSize,
endSizeVariance,
startRotation,
startRotationVariance,
endRotation,
endRotationVariance,
radialAcceleration,
radialAccelerationVariance,
tangentialAcceleration,
tangentialAccelerationVariance,
startAlpha,
startAlphaVariance,
endAlpha,
endAlphaVariance,
particleBlendMode,
emitterBoundsX,
emitterBoundsY,
emitterBoundsWidth,
emitterBoundsHeight,
currentParticles
}
export class GravityParticleSystem extends ParticleSystem {
/**
* 表示粒子初始坐标 x 差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#emitterXVariance
*/
private emitterXVariance: number;
/**
* 表示粒子初始坐标 y 差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#emitterYVariance
*/
private emitterYVariance: number;
/**
* 表示粒子存活时间,单位毫秒,取值范围(0,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#lifespan
*/
private lifespan: number;
/**
* 表示粒子存活时间差值,单位毫秒,取值范围(0,Number.MAX_VALUE]且不大于 lifespan
* @member {number} particle.GravityParticleSystem#lifespanVariance
*/
private lifespanVariance: number;
/**
* 表示粒子出现时大小,取值范围(0,Number.MAX_VALUE],粒子将会在存活时间内由 startSize 慢慢变为 endSize
* @member {number} particle.GravityParticleSystem#startSize
*/
private startSize: number;
/**
* 表示粒子出现时大小差值,取值范围(0,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#startSizeVariance
*/
private startSizeVariance: number;
/**
* 表示粒子消失时大小,取值范围(0,Number.MAX_VALUE],粒子将会在存活时间内由 startSize慢慢变为 endSize
* @member {number} particle.GravityParticleSystem#endSize
*/
private endSize: number;
/**
* 表示粒子消失时大小差值,取值范围(0,Number.MAX_VALUE],且不大于endSize
* @member {number} particle.GravityParticleSystem#endSizeVariance
*/
private endSizeVariance: number;
/**
* 表示粒子出现时的角度,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#emitAngle
*/
private emitAngle: number;
/**
* 表示粒子出现时的角度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#emitAngleVariance
*/
private emitAngleVariance: number;
/**
* 表示粒子出现时旋转值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE],粒子将会在存活时间内由 startRotation 慢慢变为 endRotation
* @member {number} particle.GravityParticleSystem#startRotation
*/
private startRotation: number;
/**
* 表示粒子出现时旋转值差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#startRotationVariance
*/
private startRotationVariance: number;
/**
* 表示粒子消失时旋转值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE],粒子将会在存活时间内由 startRotation 慢慢变为 endRotation
* @member {number} particle.GravityParticleSystem#endRotation
*/
private endRotation: number;
/**
* 表示粒子消失时旋转值差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#endRotationVariance
*/
private endRotationVariance: number;
/**
* 表示粒子出现时速度,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#speed
*/
private speed: number;
/**
* 表示粒子出现时速度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#speedVariance
*/
private speedVariance: number;
/**
* 表示粒子水平重力,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#gravityX
*/
private gravityX: number;
/**
* 表示粒子垂直重力,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#gravityX
*/
private gravityY: number;
/**
* 表示粒子径向加速度,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#radialAcceleration
*/
private radialAcceleration: number;
/**
* 表示粒子径向加速度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#radialAccelerationVariance
*/
private radialAccelerationVariance: number;
/**
* 表示粒子切向加速度,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#tangentialAcceleration
*/
private tangentialAcceleration: number;
/**
* 表示粒子切向加速度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#tangentialAccelerationVariance
*/
private tangentialAccelerationVariance: number;
/**
* 表示粒子出现时的 Alpha 透明度值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE],粒子将会在存活时间内由 startAlpha 慢慢变为 endAlpha
* @member {number} particle.GravityParticleSystem#startAlpha
*/
private startAlpha: number;
/**
* 表示粒子出现时的 Alpha 透明度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#startAlphaVariance
*/
private startAlphaVariance: number;
/**
* 表示粒子消失时的 Alpha 透明度值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE],粒子将会在存活时间内由 startAlpha 慢慢变为 endAlpha
* @member {number} particle.GravityParticleSystem#endAlpha
*/
private endAlpha: number;
/**
* 表示粒子消失时的 Alpha 透明度差值,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.GravityParticleSystem#endAlphaVariance
*/
private endAlphaVariance: number;
/**
* 表示粒子使用的混合模式
* @member {number} particle.GravityParticleSystem#blendMode
*/
private particleBlendMode: number;
/**
* 是否完成解析json数据
*/
private $init = false;
constructor(texture: egret.Texture, config: any) {
super(texture, 200);
this.parseConfig(config);
this.emissionRate = this.lifespan / this.maxParticles;
this.particleClass = GravityParticle;
this.$init = true;
}
public start(duration: number = -1): void {
if (egret.nativeRender) {
if (this.emissionRate != 0) {
this.emissionTime = duration;
}
this.$particleConfig[2] = duration;
let configArray = [];
let i = 0;
for (let key in this.$particleConfig) {
configArray.push(i++);
configArray.push(this.$particleConfig[key]);
}
this.$nativeDisplayObject.setCustomData(configArray);
}
else {
super.start(duration);
}
}
public setCurrentParticles(num: number): void {
if (num > this.maxParticles) {
return;
}
let configArray = [];
configArray.push(ParticleKeys.currentParticles);
configArray.push(num);
this.$nativeDisplayObject.setCustomData(configArray);
}
public onPropertyChanges(): void {
if (this.$init == false) {
return;
}
let configArray: Array<number> = [];
configArray.push(ParticleKeys.emitterX);
this.$particleConfig[ParticleKeys.emitterX] = this._emitterX;
configArray.push(this._emitterX);
configArray.push(ParticleKeys.emitterY);
this.$particleConfig[ParticleKeys.emitterY] = this._emitterY;
configArray.push(this._emitterY);
if (this.relativeContentBounds) {
configArray.push(ParticleKeys.emitterBoundsX);
this.$particleConfig[ParticleKeys.emitterBoundsX] = this.relativeContentBounds.x;
configArray.push(this.relativeContentBounds.x);
configArray.push(ParticleKeys.emitterBoundsY);
this.$particleConfig[ParticleKeys.emitterBoundsY] = this.relativeContentBounds.y;
configArray.push(this.relativeContentBounds.y);
configArray.push(ParticleKeys.emitterBoundsWidth);
this.$particleConfig[ParticleKeys.emitterBoundsWidth] = this.relativeContentBounds.width;
configArray.push(this.relativeContentBounds.width);
configArray.push(ParticleKeys.emitterBoundsHeight);
this.$particleConfig[ParticleKeys.emitterBoundsHeight] = this.relativeContentBounds.height;
configArray.push(this.relativeContentBounds.height);
}
this.$nativeDisplayObject.setCustomData(configArray);
}
private parseConfig(config: any): void {
if (egret.nativeRender) {
this._emitterX = getValue(config.emitter.x);
this._emitterY = getValue(config.emitter.y);
}
else {
this.emitterX = getValue(config.emitter.x);
this.emitterY = getValue(config.emitter.y);
}
this.emitterXVariance = getValue(config.emitterVariance.x);
this.emitterYVariance = getValue(config.emitterVariance.y);
this.gravityX = getValue(config.gravity.x);
this.gravityY = getValue(config.gravity.y);
if (config.useEmitterRect == true) {
var bounds: egret.Rectangle = new egret.Rectangle();
bounds.x = getValue(config.emitterRect.x);
bounds.y = getValue(config.emitterRect.y);
bounds.width = getValue(config.emitterRect.width);
bounds.height = getValue(config.emitterRect.height);
this.emitterBounds = bounds;
}
this.maxParticles = getValue(config.maxParticles);
this.speed = getValue(config.speed);
this.speedVariance = getValue(config.speedVariance);
this.lifespan = Math.max(0.01, getValue(config.lifespan));
this.lifespanVariance = getValue(config.lifespanVariance);
this.emitAngle = getValue(config.emitAngle);
this.emitAngleVariance = getValue(config.emitAngleVariance);
this.startSize = getValue(config.startSize);
this.startSizeVariance = getValue(config.startSizeVariance);
this.endSize = getValue(config.endSize);
this.endSizeVariance = getValue(config.endSizeVariance);
this.startRotation = getValue(config.startRotation);
this.startRotationVariance = getValue(config.startRotationVariance);
this.endRotation = getValue(config.endRotation);
this.endRotationVariance = getValue(config.endRotationVariance);
this.radialAcceleration = getValue(config.radialAcceleration);
this.radialAccelerationVariance = getValue(config.radialAccelerationVariance);
this.tangentialAcceleration = getValue(config.tangentialAcceleration);
this.tangentialAccelerationVariance = getValue(config.tangentialAccelerationVariance);
this.startAlpha = getValue(config.startAlpha);
this.startAlphaVariance = getValue(config.startAlphaVariance);
this.endAlpha = getValue(config.endAlpha);
this.endAlphaVariance = getValue(config.endAlphaVariance);
if (egret.nativeRender) {
if (config.blendMode) {
this.particleBlendMode = config.blendMode;
}
}
else {
this.particleBlendMode = config.blendMode;
}
function getValue(value: any): number {
if (typeof value == "undefined") {
return 0;
}
return value;
}
this.$particleConfig = {
0: this.emitterX,
1: this.emitterY,
2: -1, // emitterTime,
3: this.maxParticles,
4: this.emitterXVariance,
5: this.emitterYVariance,
6: this.gravityX,
7: this.gravityY,
8: this.speed,
9: this.speedVariance,
10: this.lifespan,
11: this.lifespanVariance,
12: this.emitAngle,
13: this.emitAngleVariance,
14: this.startSize,
15: this.startSizeVariance,
16: this.endSize,
17: this.endSizeVariance,
18: this.startRotation,
19: this.startRotationVariance,
20: this.endRotation,
21: this.endRotationVariance,
22: this.radialAcceleration,
23: this.radialAccelerationVariance,
24: this.tangentialAcceleration,
25: this.tangentialAccelerationVariance,
26: this.startAlpha,
27: this.startAlphaVariance,
28: this.endAlpha,
29: this.endAlphaVariance,
30: this.particleBlendMode,
31: config.useEmitterRect ? this.relativeContentBounds.x : 0,
32: config.useEmitterRect ? this.relativeContentBounds.y : 0,
33: config.useEmitterRect ? this.relativeContentBounds.width : 0,
34: config.useEmitterRect ? this.relativeContentBounds.height : 0,
35: 0
}
}
public initParticle(particle: Particle): void {
var locParticle: GravityParticle = <GravityParticle>particle;
var lifespan: number = GravityParticleSystem.getValue(this.lifespan, this.lifespanVariance);
locParticle.currentTime = 0;
locParticle.totalTime = lifespan > 0 ? lifespan : 0;
if (lifespan <= 0) {
return;
}
locParticle.x = GravityParticleSystem.getValue(this.emitterX, this.emitterXVariance);
locParticle.y = GravityParticleSystem.getValue(this.emitterY, this.emitterYVariance);
locParticle.startX = this.emitterX;
locParticle.startY = this.emitterY;
var angle: number = GravityParticleSystem.getValue(this.emitAngle, this.emitAngleVariance);
var speed: number = GravityParticleSystem.getValue(this.speed, this.speedVariance);
locParticle.velocityX = speed * egret.NumberUtils.cos(angle);
locParticle.velocityY = speed * egret.NumberUtils.sin(angle);
locParticle.radialAcceleration = GravityParticleSystem.getValue(this.radialAcceleration, this.radialAccelerationVariance);
locParticle.tangentialAcceleration = GravityParticleSystem.getValue(this.tangentialAcceleration, this.tangentialAccelerationVariance);
var startSize: number = GravityParticleSystem.getValue(this.startSize, this.startSizeVariance);
if (startSize < 0.1) {
startSize = 0.1;
}
var endSize: number = GravityParticleSystem.getValue(this.endSize, this.endSizeVariance);
if (endSize < 0.1) {
endSize = 0.1;
}
var textureWidth = this.texture.textureWidth;
locParticle.scale = startSize / textureWidth;
locParticle.scaleDelta = ((endSize - startSize) / lifespan) / textureWidth;
var startRotation: number = GravityParticleSystem.getValue(this.startRotation, this.startRotationVariance);
var endRotation: number = GravityParticleSystem.getValue(this.endRotation, this.endRotationVariance);
locParticle.rotation = startRotation;
locParticle.rotationDelta = (endRotation - startRotation) / lifespan;
var startAlpha: number = GravityParticleSystem.getValue(this.startAlpha, this.startAlphaVariance);
var endAlpha: number = GravityParticleSystem.getValue(this.endAlpha, this.endAlphaVariance);
locParticle.alpha = startAlpha;
locParticle.alphaDelta = (endAlpha - startAlpha) / lifespan;
locParticle.blendMode = this.particleBlendMode;
}
private static getValue(base: number, variance: number): number {
return base + variance * (Math.random() * 2 - 1);
}
public advanceParticle(particle: Particle, dt: number): void {
var locParticle: GravityParticle = <GravityParticle>particle;
dt = dt / 1000;
var restTime: number = locParticle.totalTime - locParticle.currentTime;
dt = restTime > dt ? dt : restTime;
locParticle.currentTime += dt;
var distanceX: number = locParticle.x - locParticle.startX;
var distanceY: number = locParticle.y - locParticle.startY;
var distanceScalar: number = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
if (distanceScalar < 0.01) {
distanceScalar = 0.01;
}
var radialX: number = distanceX / distanceScalar;
var radialY: number = distanceY / distanceScalar;
var tangentialX: number = radialX;
var tangentialY: number = radialY;
radialX *= locParticle.radialAcceleration;
radialY *= locParticle.radialAcceleration;
var temp: number = tangentialX;
tangentialX = -tangentialY * locParticle.tangentialAcceleration;
tangentialY = temp * locParticle.tangentialAcceleration;
locParticle.velocityX += dt * (this.gravityX + radialX + tangentialX);
locParticle.velocityY += dt * (this.gravityY + radialY + tangentialY);
locParticle.x += locParticle.velocityX * dt;
locParticle.y += locParticle.velocityY * dt;
locParticle.scale += locParticle.scaleDelta * dt * 1000;
if (locParticle.scale < 0) {
locParticle.scale = 0;
}
locParticle.rotation += locParticle.rotationDelta * dt * 1000;
locParticle.alpha += locParticle.alphaDelta * dt * 1000;
}
}
// tslint:disable
export class Particle {
/**
* 表示 Particle 实例相对于父级本地坐标的 x 坐标。
* @member {number} particle.Particle#x
*/
public x: number;
/**
* 表示粒子实例相对于父级本地坐标的 y 坐标。
* @member {number} particle.Particle#y
*/
public y: number;
/**
* 表示从注册点开始应用的对象的缩放比例(百分比)。
* @member {number} particle.Particle#scale
* @default 1
*/
public scale: number;
/**
* 表示 Particle 实例距其原始方向的旋转程度,以度为单位
* @member {number} particle.Particle#rotation
* @default 0
*/
public rotation: number;
/**
* 表示粒子的 Alpha 透明度值
* @member {number} particle.Particle#alpha
* @default 1
*/
public alpha: number;
/**
* 表示粒子当前存活时间,以毫秒为单位,取值范围(0,Number.MAX_VALUE],该值超过 totalTime 时,粒子将会被销毁
* @member {number} particle.Particle#currentTime
* @default 0
*/
public currentTime: number;
/**
* 表示粒子的存活总时间,以毫秒为单位,取值范围(0,Number.MAX_VALUE]
* @member {number} particle.Particle#totalTime
* @default 1000
*/
public totalTime: number;
/**
* 表示粒子的混合模式
* @member {number} particle.Particle#blendMode
*/
public blendMode: number;
constructor() {
this.reset();
}
public reset(): void {
this.x = 0;
this.y = 0;
this.scale = 1;
this.rotation = 0;
this.alpha = 1;
this.currentTime = 0;
this.totalTime = 1000;
}
private matrix: egret.Matrix = new egret.Matrix();
public $getMatrix(regX: number, regY: number): egret.Matrix {
var matrix = this.matrix;
matrix.identity();
if (this.rotation % 360) {
var r = this.rotation;
var cos = egret.NumberUtils.cos(r);
var sin = egret.NumberUtils.sin(r);
} else {
cos = 1;
sin = 0;
}
matrix.append(cos * this.scale, sin * this.scale, -sin * this.scale, cos * this.scale, this.x, this.y);
if (regX || regY) {
matrix.tx -= regX * matrix.a + regY * matrix.c;
matrix.ty -= regX * matrix.b + regY * matrix.d;
}
return matrix;
}
}
import { Particle } from "./Particle";
// tslint:disable
export class ParticleSystem extends egret.DisplayObject {
private _pool: Array<Particle> = [];
private frameTime: number = 0;
private particles: Array<Particle> = [];
private _emitterBounds: egret.Rectangle;
//相对当前显示对象坐标系下的内容边界
protected relativeContentBounds: egret.Rectangle;
protected _emitterX: number = 0;
protected _emitterY: number = 0;
/**
* 表示粒子出现总时间,单位毫秒,取值范围(0,Number.MAX_VALUE],-1表示无限时间
* @member {number} particle.ParticleSystem#emissionTime
* @default -1
*/
public emissionTime: number = -1;
/**
* 表示粒子出现间隔,单位毫秒,取值范围(0,Number.MAX_VALUE]
* @member {number} particle.ParticleSystem#emissionRate
*/
public emissionRate: number;
/**
* 表示粒子所使用的纹理
* @member {egret.Texture} particle.ParticleSystem#texture
*/
public texture: egret.Texture;
/**
* 表示粒子系统最大粒子数,超过该数量将不会继续创建粒子,取值范围[1,Number.MAX_VALUE]
* @member {number} particle.ParticleSystem#maxParticles
* @default 200
*/
public maxParticles: number = 200;
/**
* 当前粒子数
* @member {number} particle.ParticleSystem#numParticles
*/
private numParticles: number = 0;
/**
* 表示粒子类,如果设置创建粒子时将创建该类
* @member {number} particle.ParticleSystem#particleClass
*/
public particleClass: any = null;
public $particleConfig: any = null;
constructor(texture: egret.Texture, emissionRate: number) {
super();
if (egret.nativeRender) {
this.initConfig(emissionRate, 0, 0);
this.changeTexture(texture);
}
else {
this.emissionRate = emissionRate;
this.texture = texture;
this.$renderNode = new egret.sys.GroupNode();
//不清除绘制数据
this.$renderNode.cleanBeforeRender = function () { };
}
}
protected createNativeDisplayObject(): void {
this.$nativeDisplayObject = new egret_native.NativeDisplayObject(egret_native.NativeObjectType.PARTICLE_SYSTEM);
}
public initConfig(emissionRate: number, emitterX: number, emitterY: number): void {
this.$particleConfig = [
emissionRate, // emissionRate
emitterX, //emitterX
emitterY, //emitterY
0, //emitterTime
200 //maxParticles
]
this.emissionRate = emissionRate;
this._emitterX = emitterX;
this._emitterY = emitterY;
}
private getParticle(): Particle {
var result: Particle;
if (this._pool.length) {
result = this._pool.pop();
}
else if (this.particleClass) {
result = new this.particleClass();
}
else {
result = new Particle();
}
return result;
}
private removeParticle(particle: Particle): boolean {
var index = this.particles.indexOf(particle);
if (index != -1) {
particle.reset();
this.particles.splice(index, 1);
this._pool.push(particle);
this.numParticles--;
if (this.bitmapNodeList.length > this.numParticles) {
this.bitmapNodeList.length = this.numParticles;
this.$renderNode.drawData.length = this.numParticles;
}
return true;
}
else {
return false;
}
}
public initParticle(particle: Particle): void {
particle.x = this.emitterX;
particle.y = this.emitterY;
particle.currentTime = 0;
particle.totalTime = 1000;
}
/**
* 更新当前显示对象坐标系下的边框界限
* @param emitterRect {egret.Rectangle} 相对发射点坐标系下的界限
*/
private updateRelativeBounds(emitterRect: egret.Rectangle): void {
if (emitterRect) {
if (this.relativeContentBounds == null) {
this.relativeContentBounds = new egret.Rectangle();
}
this.relativeContentBounds.copyFrom(emitterRect);
this.relativeContentBounds.x += this.emitterX;
this.relativeContentBounds.y += this.emitterY;
} else {
this.relativeContentBounds = null;
}
this.mask = this.relativeContentBounds;
}
/**
* 表示当前粒子系统中发射粒子的渲染边界范围,使用以发射点为基准的坐标系
* @member {egret.Rectangle} particle.ParticleSystem#emitterBounds
*/
public set emitterBounds(rect: egret.Rectangle) {
this._emitterBounds = rect;
this.updateRelativeBounds(rect);
if (egret.nativeRender) {
this.onPropertyChanges();
}
}
public get emitterBounds(): egret.Rectangle {
return this._emitterBounds;
}
public onPropertyChanges(): void {
this.$nativeDisplayObject.setCustomData(this.$particleConfig);
}
/**
* 表示粒子出现点X坐标,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.ParticleSystem#emitterX
* @default 0
*/
public set emitterX(value: number) {
this._emitterX = value;
this.updateRelativeBounds(this.emitterBounds);
if (egret.nativeRender) {
this.onPropertyChanges();
}
}
public get emitterX(): number {
return this._emitterX;
}
/**
* 表示粒子出现点Y坐标,取值范围[-Number.MAX_VALUE,Number.MAX_VALUE]
* @member {number} particle.ParticleSystem#emitterY
* @default 0
*/
public set emitterY(value: number) {
this._emitterY = value;
this.updateRelativeBounds(this.emitterBounds);
if (egret.nativeRender) {
this.onPropertyChanges();
}
}
public get emitterY(): number {
return this._emitterY;
}
/**
* 开始创建粒子
* @param duration {number} 粒子出现总时间
*/
public start(duration: number = -1): void {
if (this.emissionRate != 0) {
this.emissionTime = duration;
if (egret.nativeRender) {
this.$particleConfig[3] = duration;
this.$nativeDisplayObject.setCustomData(this.$particleConfig);
}
else {
this.timeStamp = egret.getTimer();
egret.startTick(this.update, this);
}
}
}
/**
* 停止创建粒子
* @param clear {boolean} 是否清除掉现有粒子
*/
public stop(clear: boolean = false): void {
if (egret.nativeRender) {
this.$nativeDisplayObject.setStopToParticle(clear);
return;
}
this.emissionTime = 0;
if (clear) {
this.clear();
egret.stopTick(this.update, this);
}
}
private timeStamp: number;
private update(timeStamp: number): boolean {
var dt: number = timeStamp - this.timeStamp;
this.timeStamp = timeStamp;
//粒子数很少的时候可能会错过添加粒子的时机
if (this.emissionTime == -1 || this.emissionTime > 0) {
this.frameTime += dt;
while (this.frameTime > 0) {
if (this.numParticles < this.maxParticles) {//需要添加粒子
this.addOneParticle();
}
this.frameTime -= this.emissionRate;
}
if (this.emissionTime != -1) {
this.emissionTime -= dt;
if (this.emissionTime < 0) {
this.emissionTime = 0;
}
}
}
var particle: Particle;
var particleIndex: number = 0;
while (particleIndex < this.numParticles) {
particle = <Particle>this.particles[particleIndex];
if (particle.currentTime < particle.totalTime) {
this.advanceParticle(particle, dt);
particle.currentTime += dt;
particleIndex++;
}
else {
this.removeParticle(particle);
}
}
this.$renderDirty = true;
if (this.numParticles == 0 && this.emissionTime == 0) {
egret.stopTick(this.update, this);
this.dispatchEventWith(egret.Event.COMPLETE);
}
return false;
}
private particleMeasureRect: egret.Rectangle = new egret.Rectangle();
private transformForMeasure: egret.Matrix = new egret.Matrix();
private lastRect: egret.Rectangle;
$measureContentBounds(bounds: egret.Rectangle): void {
//如果设置了固定的区域边界则直接使用这个边界,否则进行自动的内容边界测量
if (this.relativeContentBounds) {
bounds.copyFrom(this.relativeContentBounds);
return;
}
if (this.numParticles > 0) {
var texture: egret.Texture = this.texture;
var textureW: number = Math.round(texture.$getScaleBitmapWidth());
var textureH: number = Math.round(texture.$getScaleBitmapHeight());
var totalRect: egret.Rectangle = egret.Rectangle.create();
var particle: Particle;
for (var i: number = 0; i < this.numParticles; i++) {
particle = this.particles[i];
this.transformForMeasure.identity();
this.appendTransform(this.transformForMeasure, particle.x, particle.y, particle.scale, particle.scale, particle.rotation, 0, 0, textureW / 2, textureH / 2);
this.particleMeasureRect.setEmpty();
this.particleMeasureRect.width = textureW;
this.particleMeasureRect.height = textureH;
var tmpRegion: Region = Region.create();
tmpRegion.updateRegion(this.particleMeasureRect, this.transformForMeasure);
if (i == 0) {
totalRect.setTo(tmpRegion.minX, tmpRegion.minY, tmpRegion.maxX - tmpRegion.minX, tmpRegion.maxY - tmpRegion.minY);
} else {
var l: number = Math.min(totalRect.x, tmpRegion.minX);
var t: number = Math.min(totalRect.y, tmpRegion.minY);
var r: number = Math.max(totalRect.right, tmpRegion.maxX);
var b: number = Math.max(totalRect.bottom, tmpRegion.maxY);
totalRect.setTo(l, t, r - l, b - t);
}
Region.release(tmpRegion);
}
//console.log(totalRect.x + "," + totalRect.y + "," + totalRect.width + "," + totalRect.height);
this.lastRect = totalRect;
bounds.setTo(totalRect.x, totalRect.y, totalRect.width, totalRect.height);
egret.Rectangle.release(totalRect);
} else {
if (this.lastRect) {
totalRect = this.lastRect;
bounds.setTo(totalRect.x, totalRect.y, totalRect.width, totalRect.height);
egret.Rectangle.release(totalRect);
this.lastRect = null;
}
}
}
public setCurrentParticles(num: number): void {
if (egret.nativeRender) {
return;
}
for (var i: number = this.numParticles; i < num && this.numParticles < this.maxParticles; i++) {
this.addOneParticle();
}
}
/**
* 更换粒子纹理
* @param texture {egret.Texture} 新的纹理
*/
public changeTexture(texture: egret.Texture): void {
if (this.texture != texture) {
this.texture = texture;
if (egret.nativeRender) {
this.$nativeDisplayObject.setBitmapDataToParticle(texture);
}
else {
//todo 这里可以优化
this.bitmapNodeList.length = 0;
this.$renderNode.drawData.length = 0;
}
}
}
private clear(): void {
while (this.particles.length) {
this.removeParticle(this.particles[0]);
}
this.numParticles = 0;
this.$renderNode.drawData.length = 0;
this.bitmapNodeList.length = 0;
this.$renderDirty = true;
}
private addOneParticle(): void {
//todo 这里可能需要返回成功与否
var particle: Particle = this.getParticle();
this.initParticle(particle);
if (particle.totalTime > 0) {
this.particles.push(particle);
this.numParticles++;
}
}
public advanceParticle(particle: Particle, dt: number): void {
particle.y -= dt / 6;
}
private bitmapNodeList: Array<egret.sys.BitmapNode> = [];
public $updateRenderNode(): void {
if (egret.nativeRender) {
return;
}
if (this.numParticles > 0) {
//todo 考虑不同粒子使用不同的texture,或者使用egret.SpriteSheet
var texture: egret.Texture = this.texture;
var textureW: number = Math.round(texture.$getScaleBitmapWidth());
var textureH: number = Math.round(texture.$getScaleBitmapHeight());
var offsetX = texture.$offsetX;
var offsetY = texture.$offsetY;
var bitmapX = texture.$bitmapX;
var bitmapY = texture.$bitmapY;
var bitmapWidth = texture.$bitmapWidth;
var bitmapHeight = texture.$bitmapHeight;
var particle: Particle;
for (var i: number = 0; i < this.numParticles; i++) {
particle = this.particles[i];
var bitmapNode: egret.sys.BitmapNode;
if (!this.bitmapNodeList[i]) {
bitmapNode = new egret.sys.BitmapNode();
this.bitmapNodeList[i] = bitmapNode;
(<egret.sys.GroupNode>this.$renderNode).addNode(this.bitmapNodeList[i]);
bitmapNode.image = texture.$bitmapData;
bitmapNode.imageWidth = texture.$sourceWidth;
bitmapNode.imageHeight = texture.$sourceHeight;
bitmapNode.drawImage(bitmapX, bitmapY, bitmapWidth, bitmapHeight, offsetX, offsetY, textureW, textureH);
}
bitmapNode = this.bitmapNodeList[i];
bitmapNode.matrix = particle.$getMatrix(textureW / 2, textureH / 2);
bitmapNode.blendMode = particle.blendMode;
bitmapNode.alpha = particle.alpha;
}
}
}
private appendTransform(matrix: egret.Matrix, x: number, y: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number, regX: number, regY: number): egret.Matrix {
if (rotation % 360) {
var r = rotation;// * Matrix.DEG_TO_RAD;
var cos = egret.NumberUtils.cos(r);
var sin = egret.NumberUtils.sin(r);
} else {
cos = 1;
sin = 0;
}
if (skewX || skewY) {
// TODO: can this be combined into a single append?
// skewX *= Matrix.DEG_TO_RAD;
// skewY *= Matrix.DEG_TO_RAD;
matrix.append(egret.NumberUtils.cos(skewY), egret.NumberUtils.sin(skewY), -egret.NumberUtils.sin(skewX), egret.NumberUtils.cos(skewX), x, y);
matrix.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0);
} else {
matrix.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
}
if (regX || regY) {
// prepend the registration offset:
matrix.tx -= regX * matrix.a + regY * matrix.c;
matrix.ty -= regX * matrix.b + regY * matrix.d;
}
return matrix;
}
}
///////////////
let regionPool: Region[] = [];
/**
* @private
*/
class Region {
/**
* @private
* 释放一个Region实例到对象池
*/
public static release(region: Region): void {
regionPool.push(region);
}
/**
* @private
* 从对象池中取出或创建一个新的Region对象。
* 建议对于一次性使用的对象,均使用此方法创建,而不是直接new一个。
* 使用完后调用对应的release()静态方法回收对象,能有效减少对象创建数量造成的性能开销。
*/
public static create(): Region {
let region = regionPool.pop();
if (!region) {
region = new Region();
}
return region;
}
/**
* @private
*/
public minX: number = 0;
/**
* @private
*/
public minY: number = 0;
/**
* @private
*/
public maxX: number = 0;
/**
* @private
*/
public maxY: number = 0;
/**
* @private
*/
public width: number = 0;
/**
* @private
*/
public height: number = 0;
/**
* @private
*/
public area: number = 0;
/**
* @private
*/
private setEmpty(): void {
this.minX = 0;
this.minY = 0;
this.maxX = 0;
this.maxY = 0;
this.width = 0;
this.height = 0;
this.area = 0;
}
/**
* @private
*/
public updateRegion(bounds: egret.Rectangle, matrix: egret.Matrix): void {
if (bounds.width == 0 || bounds.height == 0) {
//todo 理论上应该是空
this.setEmpty();
return;
}
let m = matrix;
let a = m.a;
let b = m.b;
let c = m.c;
let d = m.d;
let tx = m.tx;
let ty = m.ty;
let x = bounds.x;
let y = bounds.y;
let xMax = x + bounds.width;
let yMax = y + bounds.height;
let minX: number, minY: number, maxX: number, maxY: number;
//优化,通常情况下不缩放旋转的对象占多数,直接加上偏移量即可。
if (a == 1.0 && b == 0.0 && c == 0.0 && d == 1.0) {
minX = x + tx - 1;
minY = y + ty - 1;
maxX = xMax + tx + 1;
maxY = yMax + ty + 1;
}
else {
let x0 = a * x + c * y + tx;
let y0 = b * x + d * y + ty;
let x1 = a * xMax + c * y + tx;
let y1 = b * xMax + d * y + ty;
let x2 = a * xMax + c * yMax + tx;
let y2 = b * xMax + d * yMax + ty;
let x3 = a * x + c * yMax + tx;
let y3 = b * x + d * yMax + ty;
let tmp = 0;
if (x0 > x1) {
tmp = x0;
x0 = x1;
x1 = tmp;
}
if (x2 > x3) {
tmp = x2;
x2 = x3;
x3 = tmp;
}
minX = (x0 < x2 ? x0 : x2) - 1;
maxX = (x1 > x3 ? x1 : x3) + 1;
if (y0 > y1) {
tmp = y0;
y0 = y1;
y1 = tmp;
}
if (y2 > y3) {
tmp = y2;
y2 = y3;
y3 = tmp;
}
minY = (y0 < y2 ? y0 : y2) - 1;
maxY = (y1 > y3 ? y1 : y3) + 1;
}
this.minX = minX;
this.minY = minY;
this.maxX = maxX;
this.maxY = maxY;
this.width = maxX - minX;
this.height = maxY - minY;
this.area = this.width * this.height;
}
}
\ No newline at end of file
{
"texture":"ballParticle.png",
"emitter":{"x":364,"y":458}
,"engGreenVariance":0
,"startRotation":-30
,"startBlue":255
,"endRedVariance":0
,"startRotationVariance":0
,"endRotation":0
,"startAlphaVariance":0
,"endSizeVariance":0
,"endRotationVariance":0
,"endGreen":255
,"gravity":{"x":0,"y":-150}
,"startRedVariance":0
,"speedVariance":0
,"endBlue":255
,"startBlueVariance":0
,"startAlpha":0.11764705882352941
,"endRed":255
,"radialAcceleration":0
,"endAlpha":1
,"startRed":255
,"radialAccelerationVariance":0
,"duration":-1
,"tangentialAcceleration":0
,"maxParticles":300
,"blendFactorDestination":"oneMinusSourceAlpha"
,"maxRadius":100
,"speed":10
,"maxRadiusVariance":30
,"lifespan":810
,"tangentialAccelerationVariance":0
,"minRadius":20
,"lifespanVariance":330
,"minRadiusVariance":10
,"startSize":50
,"startGreenVariance":0
,"rotatePerSecond":30
,"startSizeVariance":12.88
,"startGreen":255
,"rotatePerSecondVariance":10
,"endSize":15
,"emitterVariance":{"x":33,"y":16}
,"endBlueVariance":0
,"emitterType":0
,"blendFactorSource":"one"
,"emitAngle":70
,"endAlphaVariance":0
,"emitAngleVariance":360
,"blendMode":1
}
\ No newline at end of file
{
"groups": [
{
"keys": "optionBtn_png,rankBtn_png,recordbtn_png,ruleBtn_png,start_btn_gray_png,start_btn_png,文案_png,e1_png,e2_png,e3_png,e4_png",
"keys": "optionBtn_png,rankBtn_png,recordbtn_png,ruleBtn_png,start_btn_gray_png,start_btn_png,文案_png,e1_png,e2_png,e3_png,e4_png,firePot_png,ballParticle_png,ballParticle_json",
"name": "start"
},
{
......@@ -234,6 +234,21 @@
"url": "assets/startScene/startscenebg.jpg",
"type": "image",
"name": "startscenebg_jpg"
},
{
"url": "assets/particle3/ballParticle.json",
"type": "json",
"name": "ballParticle_json"
},
{
"url": "assets/particle3/ballParticle.png",
"type": "image",
"name": "ballParticle_png"
},
{
"url": "assets/particle3/firePot.png",
"type": "image",
"name": "firePot_png"
}
]
}
\ No newline at end of file
import StartSceneBase from "../../libs/new_wx/components/StartSceneBase";
import { GravityParticleSystem } from "../../libs/Particle/GravityParticleSystem";
// tslint:disable
export default class StartScene extends StartSceneBase {
async start(data?) {
super.start();
await Promise.all([
RES.getResAsync("ballParticle_png"),
RES.getResAsync("ballParticle_json"),
RES.getResAsync("firePot_png")
]);
const bg = new egret.Bitmap();
bg.texture = await RES.getRes("firePot_png");
this.addChild(bg);
bg.x = this.stage.stageWidth / 2 - bg.width / 2 - 50;
bg.y = this.stage.stageHeight / 2 - bg.height / 2 - 210;
bg.scaleX = bg.scaleY = 1.8;
/*** 本示例关键代码段开始 ***/
var system = new GravityParticleSystem(
await RES.getRes("ballParticle_png"),
await RES.getRes("ballParticle_json")
);
this.addChild(system);
system.start();
system.y = this.stage.stageHeight / 2;
system.x = this.stage.stageWidth / 2;
system.emitterX = 0;
system.emitterY = 0;
system.scaleX = system.scaleY = 1.5;
bg.y += 500;
system.y += 500;
/*** 本示例关键代码段结束 ***/
}
}
\ 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