攻击按钮冷却时间

This commit is contained in:
k8w 2021-12-03 18:11:32 +08:00
parent abaedff1b3
commit 82285176d2
4 changed files with 53 additions and 33 deletions

View File

@ -33,11 +33,11 @@
"_active": true, "_active": true,
"_components": [], "_components": [],
"_prefab": { "_prefab": {
"__id__": 57 "__id__": 58
}, },
"autoReleaseAssets": false, "autoReleaseAssets": false,
"_globals": { "_globals": {
"__id__": 60 "__id__": 61
}, },
"_id": "0d3889f6-dc9c-424e-b8cd-6fa78d63af15" "_id": "0d3889f6-dc9c-424e-b8cd-6fa78d63af15"
}, },
@ -483,9 +483,6 @@
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 53
},
{ {
"__id__": 54 "__id__": 54
}, },
@ -494,6 +491,9 @@
}, },
{ {
"__id__": 56 "__id__": 56
},
{
"__id__": 57
} }
], ],
"_prefab": null, "_prefab": null,
@ -811,7 +811,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Button", "_name": "btnAttack",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 25 "__id__": 25
@ -831,6 +831,9 @@
}, },
{ {
"__id__": 51 "__id__": 51
},
{
"__id__": 53
} }
], ],
"_prefab": null, "_prefab": null,
@ -949,7 +952,7 @@
"b": 0, "b": 0,
"a": 255 "a": 255
}, },
"_string": "", "_string": "攻击",
"_horizontalAlign": 1, "_horizontalAlign": 1,
"_verticalAlign": 1, "_verticalAlign": 1,
"_actualFontSize": 40, "_actualFontSize": 40,
@ -978,8 +981,8 @@
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 100, "width": 120,
"height": 100 "height": 120
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -1104,6 +1107,18 @@
"handler": "onBtnAttack", "handler": "onBtnAttack",
"customEventData": "" "customEventData": ""
}, },
{
"__type__": "cc.UIOpacity",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 45
},
"_enabled": true,
"__prefab": null,
"_opacity": 255,
"_id": "49xySc2HlNZ7kO4VRCiutC"
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
@ -1196,6 +1211,9 @@
"camera": { "camera": {
"__id__": 4 "__id__": 4
}, },
"btnAttack": {
"__id__": 45
},
"_id": "86PJf2PFRK5LGUONuKqmzS" "_id": "86PJf2PFRK5LGUONuKqmzS"
}, },
{ {
@ -1203,14 +1221,14 @@
"fileId": "", "fileId": "",
"targetOverrides": [ "targetOverrides": [
{ {
"__id__": 58 "__id__": 59
} }
] ]
}, },
{ {
"__type__": "cc.TargetOverrideInfo", "__type__": "cc.TargetOverrideInfo",
"source": { "source": {
"__id__": 56 "__id__": 57
}, },
"sourceInfo": null, "sourceInfo": null,
"propertyPath": [ "propertyPath": [
@ -1220,7 +1238,7 @@
"__id__": 28 "__id__": 28
}, },
"targetInfo": { "targetInfo": {
"__id__": 59 "__id__": 60
} }
}, },
{ {
@ -1232,16 +1250,16 @@
{ {
"__type__": "cc.SceneGlobals", "__type__": "cc.SceneGlobals",
"ambient": { "ambient": {
"__id__": 61
},
"shadows": {
"__id__": 62 "__id__": 62
}, },
"_skybox": { "shadows": {
"__id__": 63 "__id__": 63
}, },
"fog": { "_skybox": {
"__id__": 64 "__id__": 64
},
"fog": {
"__id__": 65
} }
}, },
{ {

View File

@ -1,5 +1,5 @@
import { Component, instantiate, Node, Prefab, Vec2, _decorator } from 'cc'; import { Button, Component, instantiate, Node, Prefab, UIOpacity, Vec2, _decorator } from 'cc';
import { Arrow } from '../../prefabs/Arrow/Arrow'; import { Arrow } from '../../prefabs/Arrow/Arrow';
import { Joystick } from '../../prefabs/Joystick/Joystick'; import { Joystick } from '../../prefabs/Joystick/Joystick';
import { Player } from '../../prefabs/Player/Player'; import { Player } from '../../prefabs/Player/Player';
@ -9,18 +9,6 @@ import { gameConfig } from '../../scripts/shared/game/gameConfig';
import { ArrowState } from '../../scripts/shared/game/state/ArrowState'; import { ArrowState } from '../../scripts/shared/game/state/ArrowState';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
/**
* Predefined variables
* Name = GameScene
* DateTime = Thu Dec 02 2021 18:43:36 GMT+0800 ()
* Author = k8w
* FileBasename = GameScene.ts
* FileBasenameNoExtension = GameScene
* URL = db://assets/scenes/GameScene/GameScene.ts
* ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
*
*/
@ccclass('GameScene') @ccclass('GameScene')
export class GameScene extends Component { export class GameScene extends Component {
@ -40,6 +28,9 @@ export class GameScene extends Component {
@property(FollowCamera) @property(FollowCamera)
camera: FollowCamera = null as any; camera: FollowCamera = null as any;
@property(Node)
btnAttack: Node = null as any;
gameManager!: GameManager; gameManager!: GameManager;
private _playerInstances: { [playerId: number]: Player | undefined } = {}; private _playerInstances: { [playerId: number]: Player | undefined } = {};
@ -49,6 +40,7 @@ export class GameScene extends Component {
onLoad() { onLoad() {
(window as any).game = this; (window as any).game = this;
// 初始化摇杆
this.joyStick.options = { this.joyStick.options = {
onOperate: v => { onOperate: v => {
if (!this._selfSpeed) { if (!this._selfSpeed) {
@ -64,9 +56,10 @@ export class GameScene extends Component {
this.gameManager = new GameManager(); this.gameManager = new GameManager();
// 监听数据状态事件 // 监听数据状态事件
// 新箭矢发射(仅表现)
this.gameManager.gameSystem.onNewArrow.push(v => { this._onNewArrow(v) }); this.gameManager.gameSystem.onNewArrow.push(v => { this._onNewArrow(v) });
// 断线一秒后重连 // 断线 2 秒后自动重连
this.gameManager.client.flows.postDisconnectFlow.push(v => { this.gameManager.client.flows.postDisconnectFlow.push(v => {
setTimeout(() => { setTimeout(() => {
this.gameManager.join(); this.gameManager.join();
@ -172,5 +165,13 @@ export class GameScene extends Component {
targetPos: { x: targetPos.x, y: targetPos.y }, targetPos: { x: targetPos.x, y: targetPos.y },
targetTime: this.gameManager.state.now + gameConfig.arrowFlyTime targetTime: this.gameManager.state.now + gameConfig.arrowFlyTime
} as any) } as any)
// 冷却时间 1 秒
this.btnAttack.getComponent(Button)!.interactable = false;
this.btnAttack.getComponent(UIOpacity)!.opacity = 120;
this.scheduleOnce(() => {
this.btnAttack.getComponent(Button)!.interactable = true;
this.btnAttack.getComponent(UIOpacity)!.opacity = 255;
}, 1)
} }
} }

View File

@ -5,7 +5,7 @@ const { ccclass, property } = _decorator;
const v3_1 = new Vec3; const v3_1 = new Vec3;
/** /**
* *
*/ */
@ccclass @ccclass
export class FollowCamera extends Component { export class FollowCamera extends Component {

View File

@ -94,7 +94,8 @@ export class GameManager {
pendingInputMsgs: MsgClientInput[] = []; pendingInputMsgs: MsgClientInput[] = [];
sendClientInput(input: ClientInput) { sendClientInput(input: ClientInput) {
if (!this.selfPlayerId) { // 已掉线或暂未加入,忽略本地输入
if (!this.selfPlayerId || !this.client.isConnected) {
return; return;
} }