Cocos Creator 教程:ts中如何使用cc.Enum

上码

//定义
export enum Direction {
    up = 1,
    down = 2
};
//声明
@property({ type: cc.Enum(Direction) })
direction: Direction = Direction.down;

参考

  • https://forum.cocos.org/t/typescript-js-cc-enum/72418
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cocos Creator 3.x 版本cc.Line 组件已经被废弃,可以使用 Graphics 组件来绘制随机闪电。具体实现步骤如下: 1. 在场景编辑器创建一个节点,添加 Graphics 组件。 2. 编写脚本,获取 Graphics 组件,在 onEnable 生命周期回调函数调用绘制随机闪电的方法。具体实现方法如下: ``` cc.Class({ extends: cc.Component, properties: { duration: 0.2, // 闪电持续时间 offset: 10, // 闪电偏移量 boltWidth: 5, // 闪电宽度 color: cc.Color.WHITE // 闪电颜色 }, onEnable: function () { this.schedule(this.drawBolt, this.duration); }, onDisable: function () { this.unschedule(this.drawBolt); }, drawBolt: function () { var g = this.getComponent(cc.Graphics); g.clear(); var startPos = cc.v2(0, 0); // 起点坐标 var endPos = cc.v2(cc.winSize.width, cc.winSize.height); // 终点坐标 var midPos = cc.v2(startPos.x + (endPos.x - startPos.x) / 2, startPos.y + (endPos.y - startPos.y) / 2); // 点坐标 // 生成随机偏移量 var offset1 = cc.v2(Math.random() * this.offset - this.offset / 2, Math.random() * this.offset - this.offset / 2); var offset2 = cc.v2(Math.random() * this.offset - this.offset / 2, Math.random() * this.offset - this.offset / 2); // 绘制闪电 g.strokeColor = this.color; g.lineWidth = this.boltWidth; g.moveTo(startPos.x, startPos.y); g.lineTo(midPos.x + offset1.x, midPos.y + offset1.y); g.lineTo(endPos.x + offset2.x, endPos.y + offset2.y); g.stroke(); } }); ``` 这段代码将在节点上使用 Graphics 组件绘制随机闪电,每隔一定时间刷新一次。可以根据需要调整闪电的持续时间、偏移量、宽度和颜色等参数。需要注意的是,随机闪电的绘制效果可能会受到屏幕分辨率的影响,可以根据需要调整起点和终点坐标来适配不同的屏幕大小。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值