render optimization
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Node, Prefab, SpriteFrame } from 'cc'
|
||||
import { Node, Prefab, SpriteFrame, clamp } from 'cc'
|
||||
import Singleton from '../Base/Singleton'
|
||||
import { EntityTypeEnum, IBullet, IClientInput, InputTypeEnum, IRoom, IState, toFixed } from '../Common'
|
||||
import { ActorManager } from '../Entity/Actor/ActorManager'
|
||||
@@ -84,6 +84,10 @@ export default class DataManager extends Singleton {
|
||||
|
||||
player.position.x += toFixed(x * PLAYER_SPEED * dt)
|
||||
player.position.y += toFixed(y * PLAYER_SPEED * dt)
|
||||
|
||||
player.position.x = clamp(player.position.x, -this.mapSize.x / 2, this.mapSize.x / 2)
|
||||
player.position.y = clamp(player.position.y, -this.mapSize.y / 2, this.mapSize.y / 2)
|
||||
|
||||
player.direction = { x, y }
|
||||
break
|
||||
}
|
||||
|
@@ -91,8 +91,10 @@ export default class NetworkManager extends Singleton {
|
||||
})
|
||||
}
|
||||
|
||||
sendMsg<T extends keyof IModel['msg']>(name: T, data: IModel['msg'][T]) {
|
||||
async sendMsg<T extends keyof IModel['msg']>(name: T, data: IModel['msg'][T]) {
|
||||
const view = binaryEncode(name, data)
|
||||
let networkLag = parseInt(new URLSearchParams(location.search).get('lag') || '0') || 0;
|
||||
await new Promise((r) => setTimeout(r, networkLag))
|
||||
this.ws.send(view.buffer)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user