8 Phaser3-图片透明效果

效果展示

在这里插入图片描述

关键技术点

  • 元素使用setAlpha设置透明度,可以设置整体透明、局部透明和动态透明

部分主要文件代码

BootScene.js

import {Scene} from 'phaser'
import bear from '@/game/assets/bear.png'
import barbarian from '@/game/assets/barbarian.png'

export default class BootScene extends Scene {
    constructor() {
        super({key: 'BootScene'});
    }

    preload() {
        // 加载图片素材
        this.load.image("bear", bear)
        this.load.image("barbarian", barbarian)
    }

    create() {
        this.scene.start('PlayScene')
    }
}

PlayScene.js

import {Scene, Display} from 'phaser'
export default class PlayScene extends Scene {
    constructor() {
        super({key: 'PlayScene'})
    }

    create() {

        this.barbarian = this.add.image(0,0,"barbarian").setOrigin(0)
        this.bear1 = this.add.image(0,0,"bear")
        this.bear2 = this.add.image(0,0,"bear")
        this.bear3 = this.add.image(0,0,"bear")
        this.bear4 = this.add.image(0,0,"bear")
        this.bear5 = this.add.image(0,0,"bear")

        // 顺序top left, top right, bottom left, bottom right,0为透明
        // 效果为底部透明
        this.bear1.setAlpha(1, 1, 0, 0)
        // 整体透明
        this.bear2.setAlpha(0.2)
        // 效果为上部透明
        this.bear3.setAlpha(0, 0, 1, 1)
        // 左部透明
        this.bear4.alphaTopLeft = 0;
        // 多组透明效果切换
        this.tweens.add({
            targets: this.bear5,
            alphaTopLeft: { value: 0, duration: 1000, ease: 'Power1' },
            alphaBottomRight: { value: 0, duration: 1000, ease: 'Power1' },
            alphaBottomLeft: { value: 0, duration: 1000, ease: 'Power1', delay: 500 },
            yoyo: true,
            loop: -1

        });

        Display.Align.In.Center(this.bear1, this.barbarian);
        Display.Align.In.TopRight(this.bear2, this.barbarian);
        Display.Align.In.TopLeft(this.bear3, this.barbarian);
        Display.Align.In.TopCenter(this.bear4, this.barbarian);
        Display.Align.In.BottomCenter(this.bear5, this.barbarian);
    }

    update() {
    }
}

本节完整代码下载地址

https://github.com/biwow/phaser3/tree/main/code/8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容[1],该引用提到了使用TypeScript编写的3D库three.js和ammo.js,可用于Web、移动和PC平台,它可以为您的项目提供物理学特性,并为Phaser 3游戏引入三维功能。您可以访问相应的网站以获取文档和示例。 而根据引用,无法找到G:\html\threejs-test\phaser3-start\01-phaser\node_modules\src文件夹。请确认该路径是否正确,并确保该文件夹存在。如果该文件夹确实不存在,您可以尝试解决该问题的方法包括检查文件路径是否正确、重新安装相应的模块或库,以及确保您的项目配置正确。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [enable3d:用于Three.js的:joystick_selector:独立3D框架物理(使用ammo.js)Phaser 3的3D扩展](https://download.csdn.net/download/weixin_38750761/14948289)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Google搜索关键字](https://blog.csdn.net/weixin_30359021/article/details/99600212)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值