import { property, EditType } from "@egret/core"
import { component } from "@egret/ecs"
import { Application, Behaviour } from "@egret/engine"
import { InputCode, InputManager } from "@egret/input";
@component()
export class InputTest extends Behaviour {
@property(EditType.Float)
public moveSpeed: float = 10;
@property(EditType.Float)
public routateSpeed: float = 50;
onUpdate(dt) {
console.log("進(jìn)入update");
const inputManager = Application.instance.globalEntity.getComponent(InputManager);
if (inputManager.getInput(InputCode.KeyW).isHold) {
this.entity.transform.position = this.entity.transform.position.add(
this.entity.transform.getForward().multiplyScalar(dt * this.moveSpeed)
);
}
if (inputManager.getInput(InputCode.KeyS).isHold) {
this.entity.transform.position = this.entity.transform.position.subtract(
this.entity.transform.getForward().multiplyScalar(dt * this.moveSpeed)
);
}
if (inputManager.getInput(InputCode.KeyA).isHold) {
this.entity.transform.rotate(0, -dt * this.routateSpeed, 0);
}
if (inputManager.getInput(InputCode.KeyD).isHold) {
this.entity.transform.rotate(0, dt * this.routateSpeed, 0);
}
}
}
獲取鍵盤輸入
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- getchar 獲取鍵盤輸入,只能獲取一個(gè)字符或數(shù)字, 從鍵盤輸入一個(gè)字符,然后輸出一個(gè)字符。 源代碼: #inc...
- void test1 (void); main() { test1(); return 0; } void tes...
- 程序開(kāi)發(fā)過(guò)程中,需要從鍵盤獲取輸入值是常有的事,但Java它偏偏就沒(méi)有像c語(yǔ)言給我們提供的scanf(),C++給...
- System.in.read() System.out.read()只能針對(duì)一個(gè)字符的獲取,獲取進(jìn)來(lái)的變量的類型只...