五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Cocos Creator個性化時間進(jìn)度條實現(xiàn)

2021-11-12 19:52 作者:unity小能手  | 我要投稿

在Cocos Creator游戲開發(fā)中,經(jīng)常需要使用個性化時間進(jìn)度條,下面,我們就一起來封裝下自己的個性化時間進(jìn)度條組件。

一、 個性化時間進(jìn)度條

1: ?編寫腳本, 來使用sprite的扇形來顯示當(dāng)前的進(jìn)度:

屬性: time_sec: 定時器的時間

clockwise: 是否為順時針或逆時針;

reverse: ?是否反轉(zhuǎn)

startClockAction: 開始累積時間,看時間過去的百分比,來改變精靈顯示的百分比;

stopClockAction: 停止計時累積;

二、 計時器控制組件

const {ccclass, property} = cc._decorator;

@ccclass

export default class ClockCtrl extends cc.Component {

? ?@property({tooltip:"計時時長"})

? ?actionTime : number = 10;

? ?@property({tooltip:"是否逆時針"})

? ?clockWise : boolean = false;

? ?@property({tooltip:"計時方向"})

? ?reverse : boolean = false; ?// false,由少變多

? ?@property({tooltip:"是否在加載的時候就開始計時"})

playOnLoad : boolean = false;

private nowTime : number = 0; ? // 用于記錄已經(jīng)過去的時間

private isRuning : boolean = false; // 計時器是否正在行走

private sprite : cc.Sprite;

private endFunc : Function = null;

onLoad () {

this.node.active = false;

// 獲取子節(jié)點上的Sprite組件

this.sprite = this.node.getChildByName("TimerBar").getComponent(cc.Sprite);

if(this.playOnLoad){

this.startClockAction(this.actionTime, this.endFunc);

? ? ? ?}

}

startClockAction(actionTime : number, endFunc : Function){

if(actionTime <= 0){

return;

? ? ? ?}

this.endFunc = endFunc;

this.node.active = true;

this.actionTime = actionTime;

this.nowTime = 0;

this.isRuning = true;

}

stopClockAction(){

this.node.active = false;

this.isRuning = false;

}

update (dt : number) {

if(!this.isRuning){

return;

? ? ? ?}

this.nowTime += dt;

// 將時間轉(zhuǎn)換為百分比,設(shè)置給this.sprite的FillRange屬性

let per : number = this.nowTime/this.actionTime;

if(per > 1){

? ? ? ? ? ?per = 1;

this.isRuning = false;

if(this.endFunc){

this.endFunc();

? ? ? ? ? ?}

? ? ? ?}

// 進(jìn)度條 由多變少的控制

// per : 0 ?0.5 1

// 1-per:1 ?0.5 0

if(this.reverse){

? ? ? ? ? ?per = 1 - per;

? ? ? ?}

// 順時針和逆時針的控制

if(this.clockWise){

? ? ? ? ? ?per = -per;

? ? ? ?}

this.sprite.fillRange = per;

? ?}

}

三、 UI組件

四、 組件的使用測試GameMgr.ts

import ClockCtrl from "./ClockCtrl";

const {ccclass, property} = cc._decorator;

@ccclass

export default class GameMgr extends cc.Component { ? ?

? ?@property({type:ClockCtrl, tooltip:"計時器組件"})

? ?clock : ClockCtrl = null;

? ?@property({tooltip:"計時器計時時長"})

? ?actionTime : number = 5;

private endFunc(){

console.log(this.actionTime,"秒倒計時完成!");

? ?}

start(){

this.clock.startClockAction(this.actionTime, this.endFunc);

}

}


Cocos Creator個性化時間進(jìn)度條實現(xiàn)的評論 (共 條)

分享到微博請遵守國家法律
合江县| 青浦区| 彩票| 云和县| 左贡县| 六安市| 黄浦区| 佛冈县| 龙南县| 九寨沟县| 阿坝县| 通城县| 聊城市| 宜春市| 嵩明县| 阳东县| 南江县| 西青区| 海南省| 沙雅县| 当阳市| 万宁市| 滦平县| 开平市| 武城县| 龙山县| 吉木萨尔县| 宜州市| 墨江| 磐安县| 赤壁市| 樟树市| 巴南区| 桂东县| 神木县| 荣成市| 竹北市| 河源市| 黄冈市| 荥经县| 阿瓦提县|