Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'this.add.renderTexture' and then 'game.destroy(true)' error. #4849

Closed
cengbin opened this issue Nov 6, 2019 · 5 comments
Closed

Use 'this.add.renderTexture' and then 'game.destroy(true)' error. #4849

cengbin opened this issue Nov 6, 2019 · 5 comments

Comments

@cengbin
Copy link

cengbin commented Nov 6, 2019

<script src="https://cdn.jsdelivr.net/npm/phaser@3.20.1/dist/phaser-arcade-physics.min.js"></script>
<script>
  var game = new Phaser.Game({
    type: Phaser.AUTO,
    transparent: true,
    backgroundColor: 0x1099bb,
    scene: {
      preload: preload,
      create: create
    }
  });

  function preload() {
    // this.load.image('number_0.png', '../assets/number_0.png')
    // this.load.image('number_1.png', '../assets/number_1.png')
  }

  function create() {
    let bigMap = this.add.renderTexture(0, 0, 1000, 1000)
    // bigMap.draw('number_0.png', 0, 0)
    // bigMap.draw('number_1.png', 32, 0)

    var circle = this.add.circle(200, 200, 80, 0x6666ff);
    bigMap.draw(circle, 100, 100)

    setTimeout(() => {
      game.destroy(true)
    }, 1000)
  }
</script>

A881CF5A-ED8E-4F84-A0D8-C6D2744F2337

@photonstorm
Copy link
Collaborator

Your example works fine for me, as long as I don't use setTimeout to destroy the game - which you should never do, as it's outside the game flow.

Here's a test I created: http://labs.phaser.io/view.html?src=src%5Cgame%20objects%5Crender%20texture%5Cdestroy%20game%20with%20render%20texture.js&v=dev

@cengbin
Copy link
Author

cengbin commented Nov 25, 2019

Your example works fine for me, as long as I don't use setTimeout to destroy the game - which you should never do, as it's outside the game flow.

Here's a test I created: http://labs.phaser.io/view.html?src=src%5Cgame%20objects%5Crender%20texture%5Cdestroy%20game%20with%20render%20texture.js&v=dev

Thank you. Hopefully there will be more information about using Phaser to create games with aspects like this that require special processing for development. Thank you.(谢谢您。希望有多一些关于使用Phaser创建游戏 像这种需要特殊处理方面的介绍便于开发,谢谢。)

@rexrainbow
Copy link
Contributor

rexrainbow commented Nov 25, 2019

Sorry for duplicated issue (#4876).
In Rich's testing, it saves texture of rendertexture to 'bubbleboy', in line 32. If change the testing to this :

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    backgroundColor: '#2d2d88',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

var rt;
var bubbles = [];

function preload ()
{
    this.load.image('dude', 'assets/sprites/phaser-dude.png');
}

function create ()
{
    rt = this.add.renderTexture(0, 0, 80, 80);

    var circle = this.add.circle(0, 0, 40, 0x6666ff).setAlpha(0.5).setVisible(false);

    rt.draw(circle, 40, 40);
    rt.draw('dude', 24, 20);

    this.input.on('pointerup', function () {

        game.destroy(true);

    });
}

Error message will still show on console.

@cengbin
Copy link
Author

cengbin commented Nov 26, 2019

Sorry for duplicated issue (#4876).
In Rich's testing, it saves texture of rendertexture to 'bubbleboy', in line 32. If change the testing to this :

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    backgroundColor: '#2d2d88',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

var rt;
var bubbles = [];

function preload ()
{
    this.load.image('dude', 'assets/sprites/phaser-dude.png');
}

function create ()
{
    rt = this.add.renderTexture(0, 0, 80, 80);

    var circle = this.add.circle(0, 0, 40, 0x6666ff).setAlpha(0.5).setVisible(false);

    rt.draw(circle, 40, 40);
    rt.draw('dude', 24, 20);

    this.input.on('pointerup', function () {

        game.destroy(true);

    });
}

Error message will still show on console.

this.input.on('pointerup', function () {
        rt.destroy()
        game.destroy(true);
    });

这样可以解决问题,我觉得Phaser官方应该修复解决这个问题。

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants