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

Cannot set Phaser.Tilemap.Tile corner alphas as it is stated in the Documentation #6594

Closed
jcoppage opened this issue Aug 23, 2023 · 1 comment

Comments

@jcoppage
Copy link

jcoppage commented Aug 23, 2023

  • Phaser Version:
    3.60

  • Operating system:
    MacOS

Description

Calling Phaser.Tilemap.Tile.setAlpha(0,0,1,1) Does not render the Tile's texture as expected: The topLeft and topRight corners of each tile of the map2 Tilemap (See Code Below) should be transparent (or faded). But, the Tile remains fully opaque. The Tile.alphaTopLeft and Tile.alphaTopRight properties do indeed change as expected. Tile.setAlpha(.5) does indeed work as expected as well.
Not sure how Phaser Renders Phaser.Tilemap.Tile objects, but it would be nice for this feature to work as it does with rendering Phaser.GameObjects.

Example Test Code

class Example extends Phaser.Scene
{
    controls;

    preload ()
    {
        this.load.tilemapTiledJSON('map', 'assets/tilemaps/maps/desert.json');
        this.load.image('Desert', 'assets/tilemaps/tiles/tmw_desert_spacing.png');
        this.load.image('drawtiles-spaced', 'assets/tilemaps/tiles/drawtiles-spaced.png');
    }

    create ()
    {
        const map = this.make.tilemap({ key: 'map' });
        const tiles = map.addTilesetImage('Desert');
        const layer = map.createLayer(0, tiles, 0, 0);
        layer.setScrollFactor(0.5);
        layer.setAlpha(0.75);

        const level = [
            [ 2, 2, 2, 2 ],
            [ 2, 2, 2, 2 ],
            [ 2, 2, 2, 2 ],
            [ 2, 2, 2, 2 ]
        ];
        const map2 = this.make.tilemap({ tileWidth: 32, tileHeight: 32, data: level });

        const tiles2 = map2.addTilesetImage('drawtiles-spaced', null, 32, 32, 1, 2);

        const layer2 = map2.createLayer(0, tiles2, 200, 200);

        map2.forEachTile(function(tile) {

            tile.setAlpha(.5,.5,1,1)
            //tile.setAlpha(.5)
            console.log('Tiles Alpha Top Left: '+tile.alphaTopLeft+ ' And tiles Alpha Bottom Left is: '+tile.alphaBottomLeft)
            
        })

        const cursors = this.input.keyboard.createCursorKeys();
        const controlConfig = {
            camera: this.cameras.main,
            left: cursors.left,
            right: cursors.right,
            up: cursors.up,
            down: cursors.down,
            speed: 0.5
        };
        this.controls = new Phaser.Cameras.Controls.FixedKeyControl(controlConfig);
    }

    update (time, delta)
    {
        this.controls.update(delta);
    }
}

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#000000',
    parent: 'phaser-example',
    pixelArt: true,
    scene: Example
};

const game = new Phaser.Game(config);
@photonstorm
Copy link
Collaborator

Tile is incorrectly using the Alpha component, which implies you can set these values, but you cannot. I have fixed it so it's now using AlphaSingle, so the methods will now reflect this. Tiles only have a single alpha value and cannot be modified per corner.

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

No branches or pull requests

2 participants