update
This commit is contained in:
@@ -1,57 +1,55 @@
|
||||
import { _decorator, Component, Node, input, Input, EventTouch, Vec2, Vec3, UITransform } from 'cc';
|
||||
import { _decorator, Component, Node, input, Input, EventTouch, Vec2, Vec3, UITransform } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('JoyStickManager')
|
||||
@ccclass("JoyStickManager")
|
||||
export class JoyStickManager extends Component {
|
||||
input: Vec2 = Vec2.ZERO
|
||||
input: Vec2 = Vec2.ZERO;
|
||||
|
||||
private body: Node
|
||||
private stick: Node
|
||||
private touchStartPos: Vec2
|
||||
private defaultPos: Vec2
|
||||
private radius: number = 0
|
||||
private body: Node;
|
||||
private stick: Node;
|
||||
private touchStartPos: Vec2;
|
||||
private defaultPos: Vec2;
|
||||
private radius: number = 0;
|
||||
|
||||
init() {
|
||||
this.body = this.node.getChildByName("Body")
|
||||
this.stick = this.body.getChildByName("Stick")
|
||||
const { x, y } = this.body.position
|
||||
this.defaultPos = new Vec2(x, y)
|
||||
this.radius = this.body.getComponent(UITransform).contentSize.x / 2
|
||||
init() {
|
||||
this.body = this.node.getChildByName("Body");
|
||||
this.stick = this.body.getChildByName("Stick");
|
||||
const { x, y } = this.body.position;
|
||||
this.defaultPos = new Vec2(x, y);
|
||||
this.radius = this.body.getComponent(UITransform).contentSize.x / 2;
|
||||
|
||||
input.on(Input.EventType.TOUCH_START, this.onTouchMove, this);
|
||||
input.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
input.on(Input.EventType.TOUCH_START, this.onTouchMove, this);
|
||||
input.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
input.off(Input.EventType.TOUCH_START, this.onTouchMove, this);
|
||||
input.off(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
input.off(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
}
|
||||
|
||||
onTouchMove(e: EventTouch) {
|
||||
const touchPos = e.touch.getUILocation();
|
||||
if (!this.touchStartPos) {
|
||||
this.touchStartPos = touchPos.clone();
|
||||
this.body.setPosition(this.touchStartPos.x, this.touchStartPos.y);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
input.off(Input.EventType.TOUCH_START, this.onTouchMove, this);
|
||||
input.off(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
input.off(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
const stickPos = new Vec2(touchPos.x - this.touchStartPos.x, touchPos.y - this.touchStartPos.y);
|
||||
const len = stickPos.length();
|
||||
if (len > this.radius) {
|
||||
stickPos.multiplyScalar(this.radius / len);
|
||||
}
|
||||
|
||||
onTouchMove(e: EventTouch) {
|
||||
const touchPos = e.touch.getUILocation()
|
||||
if (!this.touchStartPos) {
|
||||
this.touchStartPos = touchPos.clone()
|
||||
this.body.setPosition(this.touchStartPos.x, this.touchStartPos.y);
|
||||
}
|
||||
this.stick.setPosition(stickPos.x, stickPos.y);
|
||||
this.input = stickPos.clone().normalize();
|
||||
}
|
||||
|
||||
const stickPos = new Vec2(touchPos.x - this.touchStartPos.x, touchPos.y - this.touchStartPos.y)
|
||||
const len = stickPos.length()
|
||||
if (len > this.radius) {
|
||||
stickPos.multiplyScalar(this.radius / len)
|
||||
}
|
||||
|
||||
this.stick.setPosition(stickPos.x, stickPos.y)
|
||||
this.input = stickPos.clone().normalize()
|
||||
}
|
||||
|
||||
onTouchEnd() {
|
||||
this.body.setPosition(this.defaultPos.x, this.defaultPos.y)
|
||||
this.stick.setPosition(0, 0)
|
||||
this.touchStartPos = undefined
|
||||
this.input = Vec2.ZERO
|
||||
}
|
||||
onTouchEnd() {
|
||||
this.body.setPosition(this.defaultPos.x, this.defaultPos.y);
|
||||
this.stick.setPosition(0, 0);
|
||||
this.touchStartPos = undefined;
|
||||
this.input = Vec2.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,22 +1,19 @@
|
||||
import { _decorator, Component, Node, Label } from 'cc';
|
||||
import { EventEnum } from '../Enum';
|
||||
import DataManager from '../Global/DataManager';
|
||||
import EventManager from '../Global/EventManager';
|
||||
import { _decorator, Component, Node, Label } from "cc";
|
||||
import DataManager from "../Global/DataManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PlayerManager')
|
||||
@ccclass("PlayerManager")
|
||||
export class PlayerManager extends Component {
|
||||
init({ id, nickname, rid }: { id: number, nickname: string, rid: number }) {
|
||||
const label = this.getComponent(Label)
|
||||
let str = nickname
|
||||
init({ id, nickname, rid }: { id: number; nickname: string; rid: number }) {
|
||||
const label = this.getComponent(Label);
|
||||
let str = nickname;
|
||||
if (DataManager.Instance.myPlayerId === id) {
|
||||
str += `(我)`
|
||||
str += `(我)`;
|
||||
}
|
||||
if (rid !== -1) {
|
||||
str += `(房间${rid})`
|
||||
str += `(房间${rid})`;
|
||||
}
|
||||
label.string = str
|
||||
this.node.active = true
|
||||
label.string = str;
|
||||
this.node.active = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { _decorator, Component, Node, Label } from 'cc';
|
||||
import { EventEnum } from '../Enum';
|
||||
import EventManager from '../Global/EventManager';
|
||||
import { _decorator, Component, Node, Label } from "cc";
|
||||
import { EventEnum } from "../Enum";
|
||||
import EventManager from "../Global/EventManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('RoomManager')
|
||||
@ccclass("RoomManager")
|
||||
export class RoomManager extends Component {
|
||||
id: number
|
||||
init({ id, players }: { id: number, players: Array<{ id: number, nickname: string }> }) {
|
||||
this.id = id
|
||||
const label = this.getComponent(Label)
|
||||
label.string = `房间id:${id},当前人数:${players.length}`
|
||||
this.node.active = true
|
||||
id: number;
|
||||
init({ id, players }: { id: number; players: Array<{ id: number; nickname: string }> }) {
|
||||
this.id = id;
|
||||
const label = this.getComponent(Label);
|
||||
label.string = `房间id:${id},当前人数:${players.length}`;
|
||||
this.node.active = true;
|
||||
}
|
||||
|
||||
handleClick() {
|
||||
EventManager.Instance.emit(EventEnum.RoomJoin, this.id)
|
||||
EventManager.Instance.emit(EventEnum.RoomJoin, this.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,11 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { EventEnum } from '../Enum';
|
||||
import EventManager from '../Global/EventManager';
|
||||
import { _decorator, Component, Node } from "cc";
|
||||
import { EventEnum } from "../Enum";
|
||||
import EventManager from "../Global/EventManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ShootManager')
|
||||
@ccclass("ShootManager")
|
||||
export class ShootManager extends Component {
|
||||
shoot() {
|
||||
EventManager.Instance.emit(EventEnum.WeaponShoot)
|
||||
}
|
||||
|
||||
shoot() {
|
||||
EventManager.Instance.emit(EventEnum.WeaponShoot);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user