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] v8 NineSliceSprite doesnt works as mask on Sprite #10442

Open
Makio64 opened this issue Apr 12, 2024 · 3 comments
Open

[bug] v8 NineSliceSprite doesnt works as mask on Sprite #10442

Makio64 opened this issue Apr 12, 2024 · 3 comments
Assignees

Comments

@Makio64
Copy link

Makio64 commented Apr 12, 2024

Current Behavior

When a NineSliceSprite is set as a mask of a Sprite , the mask is ignored.

Expected Behavior

When a NineSliceSprite is set as a mask of a Sprite , the mask work.

Steps to Reproduce

		this.container.addChild(this.image)
		this.container.addChild(this.mask9splice)
		this.image.mask = this.mask9splice

Environment

  • pixi.js version: 8.1.0
  • Browser & Version: latest
  • OS & Version: mac os latest
  • Running Example: /

Possible Solution

No response

Additional Information

No response

@GoodBoyDigital
Copy link
Member

Thanks for sharing @Makio64.
is this possible with v7? cheers!

@Makio64
Copy link
Author

Makio64 commented May 1, 2024

@GoodBoyDigital I didnt try v7 but this might be link with the same bug than here : #10491 if it use renderTexture internally, i will try the same kind of workaround and let you know.

@Makio64
Copy link
Author

Makio64 commented May 2, 2024

my current workaround if anyone hit the same problem :

import Stage2d from "@/makio/2d/Stage2d";
import { RenderTexture, Sprite } from "pixi.js";

export default class NineSliceMask extends Sprite{

	constructor(nineSliceSprite){

		let renderTexture = new RenderTexture({
			antialias: true,
			width: nineSliceSprite.width,
			height: nineSliceSprite.height,
		})

		super(renderTexture)

		this.sprite = this.nineSliceSprite = nineSliceSprite
		this.renderTexture = renderTexture

		// add this one to the main stage to
		this.forceRefreshSprite = new Sprite(this.renderTexture)
		this.forceRefreshSprite.alpha = 0
		this.forceRefreshSprite.visible = false

		this.updateTexture()
	}

	drawMask(){
		Stage2d.app.renderer.render({
			container: this.nineSliceSprite,
			target: this.renderTexture,
			clear: true,
		})
	}

	updateTexture(){
		if(this.nineSliceSprite.width != this.renderTexture.width || this.nineSliceSprite.height != this.renderTexture.height){
			console.log('updatesize', this.nineSliceSprite.width, this.nineSliceSprite.height)
			this.renderTexture.resize(this.nineSliceSprite.width, this.nineSliceSprite.height)
		}

		this.drawMask()
		
		// force refresh on one frame, see bug :
		Stage2d.addChild(this.forceRefreshSprite)
		setTimeout(()=>{
			Stage2d.removeChild(this.forceRefreshSprite)
		}, 1)
	}


}

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

2 participants