Fix ParticleSystem customs not working issue (#3000)

This commit is contained in:
pandamicro
2018-07-20 15:11:07 +08:00
committed by Jare Guo
parent 61c5fb8174
commit 0a4ede7521
2 changed files with 14 additions and 14 deletions
+9 -11
View File
@@ -921,16 +921,17 @@ var ParticleSystem = cc.Class({
}
self._plistFile = file.nativeUrl;
if (self._custom) {
self._initTextureWithDictionary(content);
if (!self.spriteFrame) {
if (file.texture) {
self.spriteFrame = new cc.SpriteFrame(file.texture);
}
else {
self._initTextureWithDictionary(content);
}
}
else {
if (!self._custom) {
self._initWithDictionary(content);
}
if (file.texture) {
self.spriteFrame = new cc.SpriteFrame(file.texture);
}
});
}
},
@@ -1094,10 +1095,7 @@ var ParticleSystem = cc.Class({
_onTextureLoaded: function (event) {
this._texture = this._spriteFrame.getTexture();
// Mark render data dirty
if (this._renderData) {
this._renderData.uvDirty = true;
}
this._simulator.updateUVs(true);
// Reactivate material
this._activateMaterial();
},
+5 -3
View File
@@ -191,13 +191,15 @@ Simulator.prototype.emitParticle = function (pos) {
}
};
Simulator.prototype.updateUVs = function (particleCount) {
Simulator.prototype.updateUVs = function (force) {
let particleCount = this.particles.length;
if (this.sys._buffer && this.sys._spriteFrame) {
const FLOAT_PER_PARTICLE = 4 * this.sys._vertexFormat._bytes / 4;
let vbuf = this.sys._buffer._vData;
let uv = this.sys._spriteFrame.uv;
for (let i = this._uvFilled; i < particleCount; i++) {
let start = force ? 0 : this._uvFilled;
for (let i = start; i < particleCount; i++) {
let offset = i * FLOAT_PER_PARTICLE;
vbuf[offset+2] = uv[0];
vbuf[offset+3] = uv[1];
@@ -303,7 +305,7 @@ Simulator.prototype.step = function (dt) {
// Fill up uvs
if (particleCount > this._uvFilled) {
this.updateUVs(particleCount);
this.updateUVs();
}
// Used to reduce memory allocation / creation within the loop