Git Product home page Git Product logo

Comments (2)

bigtimebuddy avatar bigtimebuddy commented on April 29, 2024 2

I looked into this, the reason this is happening is because alpha is only used on the canvas when it is initialized. There are some performance implication by having alpha or not enabled on the canvas, for many browser opaque canvases are faster. Once options are set using canvas.getContext, they cannot be changed. Here's a simple example: https://jsfiddle.net/bigtimebuddy/m9kehdqx/

Here are the initialization methods for each renderer if you'd like to see how it's being used.

Renderer

const alpha = this.renderer.background.alpha < 1;

CanvasRenderer

const alpha = this.renderer.background.alpha < 1;

The workaround is make sure you set alpha to be < 0 when you create the Application or Renderer.

One small suggestion we could make is if the canvas is opaque (because of how you initialized), we could provide a console warning when trying to change the alpha after the fact. Something like:

The canvas has already been initialized as non-transparent. If you'd like to adjust alpha of the canvas after initializing the renderer, please set the initial value less than 1.

Some documentation might also clarify this behavior.

from pixijs.

naramdash avatar naramdash commented on April 29, 2024

I have a same issue on my private project.

    this.#pixiApp.renderer.background.color = "rgb(255,0,0)";
    this.#pixiApp.renderer.background.alpha = 0.5;

background is applied without alpha.
image

Environment

  • pixi.js version: 7.4.0
  • Browser & Version: Ubuntu 22.04 Edge 121.0.2277.83 (Official build) (64-bit)

from pixijs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.