当前位置:网站首页>Cocos Creator 3.0 基础——常见操作
Cocos Creator 3.0 基础——常见操作
2022-07-17 00:09:00 【许英俊】
文章持续记录开发中遇到常用的功能
节点平移缩放旋转
@ccclass('CubeScale')
export class CubeScale extends Component {
i = 0
j = 0
update(deltaTime: number) {
//平移
this.node.translate(new Vec3(0.01, 0, 0))
//缩放
this.node.setScale(this.i += 0.01, 1, 1)
//旋转
if (this.j >= 360) {
this.j = 0
}
this.node.setRotationFromEuler(v3(this.j += 1, 0, 0))
}
}
持久化存储
写在WebView的本地存储
localStorage.setItem("name", "hensen")
localStorage.getItem("name")
定时器
start() {
this.schedule(this._changeEnemy, 5, macro.REPEAT_FOREVER)
}
_changeEnemy() {}
声音播放
将声音部分全部保存声音管理组件中,并设置好AudioClip属性,对外提供接口进行播放
interface IAudioBean {
[name: string]: AudioClip
}
@ccclass('AudioManager')
export class AudioManager extends Component {
@property([AudioClip])
audios: AudioClip[] = []
beans: IAudioBean = {}
source: AudioSource = null
start() {
this.source = this.getComponent(AudioSource)
for (let index = 0; index < this.audios.length; index++) {
const element = this.audios[index];
this.beans[element.name] = element
}
}
//对外提供接口播放
play(name) {
const audio = this.beans[name]
if (audio !== undefined) {
this.source.playOneShot(audio)
}
}
}
使用播放
@property(AudioManager)
audioManager: AudioManager = null
this.audioManager.play("player")
动态图片加载
SpriteFrame动态加载资源中的图片,有个前提条件,图片必须存放在asset/resources目录下
resources.load("image/magnet_tool/spriteFrame", SpriteFrame, (err, spriteFrame) => {
this.tool.spriteFrame = spriteFrame;
});
边栏推荐
猜你喜欢

CheckPoint and DataNode

04 BTC implementation

touchID 和 FaceID~1

面试官问:Redis 突然变慢了如何排查?

手把手带你从零开始完整开发经典游戏【俄罗斯方块】,全部逻辑只用不到200行代码。

蛟分承影,雁落忘归——袋鼠云一站式全自动化运维管家ChengYing(承影)正式开源

Common asynchronous sending code writing

走好数据中台最后一公里,为什么说数据服务API是数据中台的标配?

Introduction to software vulnerability analysis (5)

MapReduce environment preparation
随机推荐
rotoc-gen-go: unable to determine Go import path for **.proto
Nmap and Nikto scanning
深度伪造对国家安全的挑战及应对
MapReduce环境准备
How to use express and how to match and use routes
毒瘤 DDD
量子计算机带来的全新通信安全风险分析及应对建议
温州大学X袋鼠云:高等人才教育建设,如何做到“心中有数”
如何建设实时开发平台,深入释放企业实时数据价值?
同学们 小组作业记得别抄哈 幸好只传了两道题 不要出事了
NFT differentiation trend has shown, how to capture value?
El date picker time range control
感谢各位点赞关注激增
数据指标体系如何搭建才最有效,从0到1带你快速入门丨02期直播回顾
fetch请求-简单记录
6 寻找比目标字母大的最小字母
面试官问:Redis 突然变慢了如何排查?
El form special character verification
WKWebView 设置自定义UserAgent正确姿势
Today's code farmer girl learned about nodejs and repl interactive interpreter