From 4360595ed673a268c06fc0fb2f2e9e9cc8306d49 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 4 Jan 2016 11:29:57 -0800 Subject: [PATCH] Fix to pistol.js so muzzle flash particle system doesn't stick around forever --- examples/toybox/pistol/pistol.js | 68 +++++++++++++------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index 7fb05d992f..e0f063d463 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -37,6 +37,13 @@ this.bulletForce = 10; this.showLaser = false; + this.laserOffsets = { + y: 0.095 + }; + this.firingOffsets = { + z: 0.16 + } + }; Pistol.prototype = { @@ -272,46 +279,12 @@ }); }, 100); - Entities.editEntity(this.flash, { - isEmitting: true - }); - Script.setTimeout(function() { - Entities.editEntity(_this.flash, { - isEmitting: false - }); - }, 100) - - }, - - preload: function(entityID) { - this.entityID = entityID; - this.laser = Overlays.addOverlay("line3d", { - start: ZERO_VECTOR, - end: ZERO_VECTOR, - color: COLORS.RED, - alpha: 1, - visible: true, - lineWidth: 2 - }); - this.laserOffsets = { - y: 0.095 - }; - this.firingOffsets = { - z: 0.16 - } - var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); - var position = gunProps.position; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - this.firingDirection = Quat.getFront(rotation); - var upVec = Quat.getUp(rotation); - this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y)); - this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z)) - - this.flash = Entities.addEntity({ + var flash = Entities.addEntity({ type: "ParticleEffect", position: this.barrelPoint, "name": "Muzzle Flash", - isEmitting: false, + lifetime: 4, + parentID: this.entityID, "color": { red: 228, green: 128, @@ -363,14 +336,27 @@ "additiveBlending": true, "textures": "http://ericrius1.github.io/PartiArt/assets/star.png" }); + Script.setTimeout(function() { + Entities.editEntity(flash, { + isEmitting: false + }); + }, 100) - Script.setTimeout(function() { - Entities.editEntity(_this.flash, {parentID: _this.entityID}); - }, 500) + }, + preload: function(entityID) { + this.entityID = entityID; + this.laser = Overlays.addOverlay("line3d", { + start: ZERO_VECTOR, + end: ZERO_VECTOR, + color: COLORS.RED, + alpha: 1, + visible: true, + lineWidth: 2 + }); }, }; // entity scripts always need to return a newly constructed object of our type return new Pistol(); -}); +}); \ No newline at end of file