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

Bug: every RenderTexture draw the same content #3555

Closed
kuoruan opened this issue Apr 13, 2018 · 3 comments
Closed

Bug: every RenderTexture draw the same content #3555

kuoruan opened this issue Apr 13, 2018 · 3 comments

Comments

@kuoruan
Copy link

kuoruan commented Apr 13, 2018

I use a lot of RenderTexture in my project. Today I update to Phaser 3.4, everything goes wrong.
Phaser 3.4

main.js

import 'phaser'
import MainScene from './scene/MainScene'

new Phaser.Game({
  type: Phaser.CANVAS,
  parent: 'content',
  width: 800,
  height: 600,
  scene: [
    MainScene
  ]
})

MainScene.js

import Bunny from "../ui/Bunny";
import Dude from '../ui/Dude'

class MainScene extends Phaser.Scene {
  constructor() {
    super({key: 'MainScene'})
  }

  preload () {
    this.load.setBaseURL('https://labs.phaser.io/')
    this.load.image('bunny', 'assets/sprites/bunny.png')
    this.load.image('dude', 'assets/sprites/phaser-dude.png')
  }

  create () {
    let rt1 = new Bunny({
      scene: this,
      x: 300,
      y: 200,
      width: 100,
      height: 100
    })

    this.add.existing(rt1)

    let rt2 = new Dude({
      scene: this,
      x: 400,
      y: 200,
      width: 100,
      height: 100
    })

    this.add.existing(rt2)
  }
}

export default MainScene

Bunny.js

class Bunny extends Phaser.GameObjects.RenderTexture {
  constructor({scene, x, y, width, height}) {
    super(scene, x, y, width, height)

      let image = this.scene.textures.getFrame('bunny')

      this.save()
      this.scale(this.width / image.width, this.height / image.height)
      this.draw(image.texture, image, 0, 0)
      this.restore()
  }
}

export default Bunny

Dude.js

class Dude extends Phaser.GameObjects.RenderTexture {
  constructor({scene, x, y, width, height}) {
    super(scene, x, y, width, height)

    let image = this.scene.textures.getFrame('dude')
    this.save()
    this.context.save()
    this.scale(this.width / image.width, this.height / image.height)
    this.draw(image.texture, image, 0, 0)
    this.context.restore()
    this.restore()
  }
}

export default Dude

output:
2018-04-13 1 47 20

@samid737
Copy link
Contributor

samid737 commented Apr 13, 2018

exemplified:

v3.4.0.

v3.3.0.

@kuoruan
Copy link
Author

kuoruan commented Apr 13, 2018

@samid737 Thanks.

@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