mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix rendering of particles not using a texture
This commit is contained in:
@@ -263,11 +263,11 @@ gdjs.ParticleEmitterObjectCocosRenderer.prototype.setFlow = function(flow){
|
||||
this.renderer.setEmissionRate(flow);
|
||||
};
|
||||
|
||||
gdjs.ParticleEmitterObjectCocosRenderer.prototype.isTextureValid = function(texture, runtimeScene){
|
||||
gdjs.ParticleEmitterObjectCocosRenderer.prototype.isTextureNameValid = function(texture, runtimeScene){
|
||||
return runtimeScene.getGame().getImageManager().getTexture(texture)._textureLoaded;
|
||||
};
|
||||
|
||||
gdjs.ParticleEmitterObjectCocosRenderer.prototype.setTexture = function(texture, runtimeScene){
|
||||
gdjs.ParticleEmitterObjectCocosRenderer.prototype.setTextureName = function(texture, runtimeScene){
|
||||
var texture = runtimeScene.getGame().getImageManager().getTexture(texture);
|
||||
if(texture._textureLoaded){
|
||||
if(texture.width === texture.height){
|
||||
|
@@ -5,7 +5,11 @@ Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)
|
||||
This project is released under the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {gdjs.RuntimeScene} runtimeScene
|
||||
* @param {gdjs.RuntimeObject} runtimeObject
|
||||
* @param {any} objectData
|
||||
*/
|
||||
gdjs.ParticleEmitterObjectPixiRenderer = function(runtimeScene, runtimeObject, objectData){
|
||||
var texture = null;
|
||||
var graphics = new PIXI.Graphics();
|
||||
@@ -31,7 +35,12 @@ gdjs.ParticleEmitterObjectPixiRenderer = function(runtimeScene, runtimeObject, o
|
||||
}
|
||||
}
|
||||
graphics.endFill();
|
||||
texture = graphics.generateTexture();
|
||||
|
||||
// Render the texture from graphics using the PIXI Renderer.
|
||||
// TODO: could be optimized by generating the texture only once per object type,
|
||||
// instead of at each object creation.
|
||||
var pixiRenderer = runtimeScene.getGame().getRenderer().getPIXIRenderer();
|
||||
texture = pixiRenderer.generateTexture(graphics);
|
||||
|
||||
var config = {
|
||||
color: {
|
||||
@@ -221,13 +230,18 @@ gdjs.ParticleEmitterObjectPixiRenderer.prototype.setFlow = function(flow, tank){
|
||||
(flow < 0 ? 0.001 : (tank - this.emitter.totalParticleCount) / flow);
|
||||
};
|
||||
|
||||
gdjs.ParticleEmitterObjectPixiRenderer.prototype.isTextureValid = function(texture, runtimeScene){
|
||||
return runtimeScene.getGame().getImageManager().getPIXITexture(texture).valid;
|
||||
gdjs.ParticleEmitterObjectPixiRenderer.prototype.isTextureNameValid = function(texture, runtimeScene){
|
||||
var invalidPixiTexture = runtimeScene.getGame().getImageManager().getInvalidPIXITexture();
|
||||
var pixiTexture = runtimeScene.getGame().getImageManager().getPIXITexture(texture);
|
||||
|
||||
return pixiTexture.valid && pixiTexture !== invalidPixiTexture;
|
||||
};
|
||||
|
||||
gdjs.ParticleEmitterObjectPixiRenderer.prototype.setTexture = function(texture, runtimeScene){
|
||||
gdjs.ParticleEmitterObjectPixiRenderer.prototype.setTextureName = function(texture, runtimeScene){
|
||||
var invalidPixiTexture = runtimeScene.getGame().getImageManager().getInvalidPIXITexture();
|
||||
var pixiTexture = runtimeScene.getGame().getImageManager().getPIXITexture(texture);
|
||||
if(pixiTexture.valid){
|
||||
|
||||
if(pixiTexture.valid && pixiTexture !== invalidPixiTexture){
|
||||
this.emitter.particleImages[0] = pixiTexture;
|
||||
}
|
||||
};
|
||||
|
@@ -35,6 +35,7 @@ gdjs.ParticleEmitterObject = function(runtimeScene, objectData){
|
||||
this.rendererType = objectData.rendererType;
|
||||
this.rendererParam1 = objectData.rendererParam1;
|
||||
this.rendererParam2 = objectData.rendererParam2;
|
||||
/** @type string */
|
||||
this.texture = objectData.textureParticleName;
|
||||
this.flow = objectData.flow;
|
||||
this.tank = objectData.tank;
|
||||
@@ -49,7 +50,7 @@ gdjs.ParticleEmitterObject = function(runtimeScene, objectData){
|
||||
this._colorDirty = true;
|
||||
this._sizeDirty = true;
|
||||
this._alphaDirty = true;
|
||||
this._textureDirty = true;
|
||||
this._textureDirty = this.texture !== ''; // Don't mark texture as dirty if not using one.
|
||||
this._flowDirty = true;
|
||||
|
||||
// *ALWAYS* call `this.onCreated()` at the very end of your object constructor.
|
||||
@@ -112,7 +113,7 @@ gdjs.ParticleEmitterObject.prototype.update = function(runtimeScene){
|
||||
this._renderer.setFlow(this.flow, this.tank);
|
||||
}
|
||||
if(this._textureDirty){
|
||||
this._renderer.setTexture(this.texture, runtimeScene);
|
||||
this._renderer.setTextureName(this.texture, runtimeScene);
|
||||
}
|
||||
|
||||
this._posDirty = this._angleDirty = this._forceDirty = this._zoneRadiusDirty = false;
|
||||
@@ -481,7 +482,7 @@ gdjs.ParticleEmitterObject.prototype.getTexture = function(){
|
||||
|
||||
gdjs.ParticleEmitterObject.prototype.setTexture = function(texture, runtimeScene){
|
||||
if(this.texture !== texture){
|
||||
if(this._renderer.isTextureValid(texture, runtimeScene)){
|
||||
if(this._renderer.isTextureNameValid(texture, runtimeScene)){
|
||||
this.texture = texture;
|
||||
this._textureDirty = true;
|
||||
}
|
||||
|
@@ -52,7 +52,9 @@ gdjs.CocosImageManager.prototype.getTexture = function(imageName) {
|
||||
* especially when compiled to a native game on iOS/Android/macOS.
|
||||
*/
|
||||
gdjs.CocosImageManager.prototype.getInvalidTexture = function() {
|
||||
return "res/HelloWorld.png"; //TODO
|
||||
// TODO: use a valid texture from memory and ensure that each usage of _textureLoaded
|
||||
// is updated to compare the texture with invalid texture.
|
||||
return "res/HelloWorld.png";
|
||||
};
|
||||
|
||||
gdjs.CocosImageManager.prototype.isPowerOf2 = function(texture) {
|
||||
|
Reference in New Issue
Block a user