【问题标题】:Is it possible to add custom Sprite to the mouse cursor in cocos creator是否可以在 cocos creator 中为鼠标光标添加自定义 Sprite
【发布时间】:2021-10-15 13:33:35
【问题描述】:

我想在 cocos creator 的光标上添加我自己的图片广告。

如果有任何其他替代解决方案可以实现这一点,请告诉我。

谢谢

【问题讨论】:

    标签: cocoscreator


    【解决方案1】:

    我假设你正在使用 Cocos Creator 3 并且你正在为浏览器进行构建。

    我可以为您的光标添加自定义图像的一种潜在方法是获取呈现整个游戏的canvas 元素并修改它的cursor CSS 属性。

    示例

    import { _decorator, Component, ImageAsset } from 'cc';
    const { ccclass, property } = _decorator;
    
    @ccclass('TestScript')
    export class TestScript extends Component
    {
        @property(ImageAsset)
        private cursorImage : ImageAsset = null;
    
        start ()
        {
            const canvas = document.getElementById("GameCanvas");
            canvas.style.cursor = `url("${this.cursorImage.nativeUrl}"), auto`;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多