4 Star 8 Fork 3

北京蓝亚盒子科技有限公司 / LayaAir2.x引擎示例源码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CameraInteraction.js 30.03 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
var laya = (function (exports) {
'use strict';
class KeyBoard extends Laya.Script {
constructor() {
super();
}
onEnable() {
this.w = this.owner.getChildByName("w");
this.a = this.owner.getChildByName("a");
this.s = this.owner.getChildByName("s");
this.d = this.owner.getChildByName("d");
this.q = this.owner.getChildByName("q");
this.e = this.owner.getChildByName("e");
}
onKeyDown(e) {
switch (e.keyCode) {
case 87:
case 38:
this.w.visible = false;
break;
case 65:
case 37:
this.a.visible = false;
break;
case 69:
this.e.visible = false;
break;
case 81:
this.q.visible = false;
break;
case 83:
case 40:
this.s.visible = false;
break;
case 68:
case 39:
this.d.visible = false;
break;
}
}
onKeyUp() {
this.w.visible = true;
this.a.visible = true;
this.s.visible = true;
this.d.visible = true;
this.q.visible = true;
this.e.visible = true;
}
onDisable() {
}
}
class JoyStick extends Laya.Script {
constructor() {
super();
this.centerX = 0;
this.centerY = 0;
this.isMoving = false;
this.touchId = 0;
this.angle = -1;
this.radians = -1;
this.maxDistance = 0;
this.maxDistanceSpr = 0;
this.deltaX = 0;
this.deltaY = 0;
this.tempV2_1 = new Laya.Point(0, 0);
this.tempV2_2 = new Laya.Point(0, 0);
}
onAwake() {
this.RockerPad = this.owner;
this.Rocker = this.RockerPad.getChildByName("axis");
this.centerX = this.Rocker.x;
this.centerY = this.Rocker.y;
!this.maxDistance && (this.maxDistance = (this.RockerPad.width - this.Rocker.width) / 2);
this.maxDistanceSpr = this.maxDistance * this.maxDistance;
}
onEnable() {
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.MouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.MouseUp);
Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.MouseMove);
}
MouseDown(e) {
e.stopPropagation();
if (Laya.stage.mouseX > this.RockerPad.x &&
Laya.stage.mouseX < this.RockerPad.x + this.RockerPad.width &&
Laya.stage.mouseY > this.RockerPad.y &&
Laya.stage.mouseY < this.RockerPad.y + this.RockerPad.height) {
this.isMoving = true;
this.touchId = e.touchId;
}
}
MouseUp(e) {
e.stopPropagation();
if (e.touchId != this.touchId) {
return;
}
this.isMoving = false;
this.Rocker.pos(this.centerX, this.centerY);
this.radians = this.angle = -1;
}
MouseMove(e) {
e.stopPropagation();
if (e.touchId != this.touchId) {
return;
}
if (this.isMoving) {
this.tempV2_1.x = Laya.stage.mouseX;
this.tempV2_1.y = Laya.stage.mouseY;
this.tempV2_2 = this.RockerPad.globalToLocal(this.tempV2_1, false);
this.deltaX = this.tempV2_2.x - this.centerX;
this.deltaY = this.tempV2_2.y - this.centerY;
this.angle = Math.atan2(this.deltaX, this.deltaY) * 180 / Math.PI;
if (this.angle < 0) {
this.angle += 360;
}
this.angle = Math.round(this.angle);
this.radians = Math.PI / 180 * this.angle;
var distanceSqr = this.getDistanceSqr(this.centerX, this.centerY, this.tempV2_2.x, this.tempV2_2.y);
if (distanceSqr > this.maxDistanceSpr) {
var x = Math.floor(Math.sin(this.radians) * this.maxDistance + this.centerX);
var y = Math.floor(Math.cos(this.radians) * this.maxDistance + this.centerY);
this.Rocker.pos(x, y);
}
else {
this.Rocker.pos(this.tempV2_2.x, this.tempV2_2.y);
}
}
}
onDisable() {
Laya.stage.off(Laya.Event.MOUSE_DOWN, this, this.MouseDown);
Laya.stage.off(Laya.Event.MOUSE_UP, this, this.MouseUp);
Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.MouseMove);
}
getDistanceSqr(centerX, centerY, mouseX, mouseY) {
var dx = centerX - mouseX;
var dy = centerY - mouseY;
var distance = dx * dx + dy * dy;
return distance;
}
}
class CameraMoveEuler extends Laya.Script {
constructor() {
super();
this._tempVector3 = new Laya.Vector3();
this.yawPitchRoll = new Laya.Vector3();
this.rotaionSpeed = 0.004;
this.rockerRotationSpeed = 0.0005;
this.moveSpeed = 0.0025;
this.lastMouseX = 0;
this.lastMouseY = 0;
this.isMouseDown = false;
}
onEnable() {
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp);
this.camera = this.owner;
}
onDisable() {
console.log("camera euler script is disable :" + this.enabled);
Laya.stage.off(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.off(Laya.Event.MOUSE_UP, this, this.mouseUp);
}
onUpdate() {
var elapsedTime = Laya.timer.delta;
if (Laya.Browser.onPC) {
if (!isNaN(this.lastMouseX) && !isNaN(this.lastMouseY)) {
Laya.KeyBoardManager.hasKeyDown(87) && this.moveForward(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(83) && this.moveForward(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(65) && this.moveRight(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(68) && this.moveRight(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(81) && this.moveVertical(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(69) && this.moveVertical(-0.01 * elapsedTime);
if (this.isMouseDown) {
var offsetX = Laya.stage.mouseX - this.lastMouseX;
var offsetY = Laya.stage.mouseY - this.lastMouseY;
this.camera.transform.localRotationEulerX -= offsetY * this.rotaionSpeed * elapsedTime;
this.camera.transform.localRotationEulerY -= offsetX * this.rotaionSpeed * elapsedTime;
console.log("Use Euler Script!");
}
}
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
}
else {
if (this.moveRocker.angle != -1) {
var speedX = Math.sin(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
var speedZ = Math.cos(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
this._tempVector3.setValue(speedX, 0, speedZ);
this.camera.transform.translate(this._tempVector3, true);
}
if (this.rotationRocker.angle != -1) {
var offsetX = this.rotationRocker.deltaX;
var offsetY = this.rotationRocker.deltaY;
this.camera.transform.localRotationEulerX -= offsetY * this.rockerRotationSpeed * elapsedTime;
this.camera.transform.localRotationEulerY -= offsetX * this.rockerRotationSpeed * elapsedTime;
console.log("Use Euler Script!");
}
}
}
mouseDown(e) {
this.camera.transform.localRotation.getYawPitchRoll(this.yawPitchRoll);
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
this.isMouseDown = true;
}
mouseUp(e) {
this.isMouseDown = false;
}
moveForward(distance) {
this._tempVector3.x = 0;
this._tempVector3.y = 0;
this._tempVector3.z = distance;
this.camera.transform.translate(this._tempVector3, true);
}
moveRight(distance) {
this._tempVector3.y = 0;
this._tempVector3.z = 0;
this._tempVector3.x = distance;
this.camera.transform.translate(this._tempVector3, true);
}
moveVertical(distance) {
this._tempVector3.x = this._tempVector3.z = 0;
this._tempVector3.y = distance;
this.camera.transform.translate(this._tempVector3, false);
}
}
class CameraMoveQuaternion extends Laya.Script {
constructor() {
super();
this._tempVector3 = new Laya.Vector3();
this.yawPitchRoll = new Laya.Vector3();
this.tempRotationZ = new Laya.Quaternion();
this.rotaionSpeed = 0.00012;
this.rockerRotationSpeed = 0.00001;
this.moveSpeed = 0.0025;
this.lastMouseX = 0;
this.lastMouseY = 0;
this.isMouseDown = false;
}
onEnable() {
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp);
this.camera = this.owner;
}
onDisable() {
console.log("camera quaternion script is disable :" + this.enabled);
Laya.stage.off(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.off(Laya.Event.MOUSE_UP, this, this.mouseUp);
}
onUpdate() {
var elapsedTime = Laya.timer.delta;
if (Laya.Browser.onPC) {
if (!isNaN(this.lastMouseX) && !isNaN(this.lastMouseY)) {
Laya.KeyBoardManager.hasKeyDown(87) && this.moveForward(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(83) && this.moveForward(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(65) && this.moveRight(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(68) && this.moveRight(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(81) && this.moveVertical(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(69) && this.moveVertical(-0.01 * elapsedTime);
if (this.isMouseDown) {
var offsetX = Laya.stage.mouseX - this.lastMouseX;
var offsetY = Laya.stage.mouseY - this.lastMouseY;
var yprElem = this.yawPitchRoll;
yprElem.x -= offsetX * this.rotaionSpeed * elapsedTime;
yprElem.y -= offsetY * this.rotaionSpeed * elapsedTime;
this.updateRotation();
console.log("Use Quaternion Script!");
}
}
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
}
else {
if (this.moveRocker.angle != -1) {
var speedX = Math.sin(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
var speedZ = Math.cos(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
this._tempVector3.setValue(speedX, 0, speedZ);
this.camera.transform.translate(this._tempVector3, true);
}
if (this.rotationRocker.angle != -1) {
var offsetX = this.rotationRocker.deltaX;
var offsetY = this.rotationRocker.deltaY;
var yprElem = this.yawPitchRoll;
yprElem.x -= offsetX * this.rockerRotationSpeed * elapsedTime;
yprElem.y -= offsetY * this.rockerRotationSpeed * elapsedTime;
this.updateRotation();
console.log("Use Quaternion Script!");
}
}
}
mouseDown(e) {
this.camera.transform.localRotation.getYawPitchRoll(this.yawPitchRoll);
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
this.isMouseDown = true;
}
mouseUp(e) {
this.isMouseDown = false;
}
moveForward(distance) {
this._tempVector3.x = 0;
this._tempVector3.y = 0;
this._tempVector3.z = distance;
this.camera.transform.translate(this._tempVector3, true);
}
moveRight(distance) {
this._tempVector3.y = 0;
this._tempVector3.z = 0;
this._tempVector3.x = distance;
this.camera.transform.translate(this._tempVector3, true);
}
moveVertical(distance) {
this._tempVector3.x = this._tempVector3.z = 0;
this._tempVector3.y = distance;
this.camera.transform.translate(this._tempVector3, false);
}
updateRotation() {
if (Math.abs(this.yawPitchRoll.y) < 1.50) {
Laya.Quaternion.createFromYawPitchRoll(this.yawPitchRoll.x, this.yawPitchRoll.y, this.yawPitchRoll.z, this.tempRotationZ);
this.tempRotationZ.cloneTo(this.camera.transform.localRotation);
this.camera.transform.localRotation = this.camera.transform.localRotation;
}
}
}
class CameraMoveMatrix extends Laya.Script {
constructor() {
super();
this._tempVector3 = new Laya.Vector3();
this.yawPitchRoll = new Laya.Vector3();
this.rotateMatrix = new Laya.Matrix4x4();
this.rotaionSpeed = 0.00012;
this.rockerRotationSpeed = 0.00001;
this.moveSpeed = 0.0025;
this.lastMouseX = 0;
this.lastMouseY = 0;
this.isMouseDown = false;
}
onEnable() {
Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp);
this.camera = this.owner;
}
onDisable() {
console.log("camera matrix script is disable :" + this.enabled);
Laya.stage.off(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
Laya.stage.off(Laya.Event.MOUSE_UP, this, this.mouseUp);
}
onUpdate() {
var elapsedTime = Laya.timer.delta;
if (Laya.Browser.onPC) {
if (!isNaN(this.lastMouseX) && !isNaN(this.lastMouseY)) {
Laya.KeyBoardManager.hasKeyDown(87) && this.moveForward(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(83) && this.moveForward(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(65) && this.moveRight(-0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(68) && this.moveRight(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(81) && this.moveVertical(0.01 * elapsedTime);
Laya.KeyBoardManager.hasKeyDown(69) && this.moveVertical(-0.01 * elapsedTime);
if (this.isMouseDown) {
var offsetX = Laya.stage.mouseX - this.lastMouseX;
var offsetY = Laya.stage.mouseY - this.lastMouseY;
var yprElem = this.yawPitchRoll;
yprElem.x -= offsetX * this.rotaionSpeed * elapsedTime;
yprElem.y -= offsetY * this.rotaionSpeed * elapsedTime;
Laya.Matrix4x4.createRotationYawPitchRoll(yprElem.x, yprElem.y, yprElem.z, this.rotateMatrix);
var moveMatrix = new Laya.Matrix4x4();
Laya.Matrix4x4.createTranslate(new Laya.Vector3(this.camera.transform.position.x, this.camera.transform.position.y, this.camera.transform.position.z), moveMatrix);
Laya.Matrix4x4.multiply(moveMatrix, this.rotateMatrix, this.rotateMatrix);
this.camera.transform.localMatrix = this.rotateMatrix;
console.log("Use Matrix Script!");
}
}
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
}
else {
if (this.moveRocker.angle != -1) {
var speedX = Math.sin(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
var speedZ = Math.cos(this.moveRocker.radians) * this.moveSpeed * elapsedTime;
this._tempVector3.setValue(speedX, 0, speedZ);
this.camera.transform.translate(this._tempVector3, true);
}
if (this.rotationRocker.angle != -1) {
var offsetX = this.rotationRocker.deltaX;
var offsetY = this.rotationRocker.deltaY;
var yprElem = this.yawPitchRoll;
yprElem.x -= offsetX * this.rockerRotationSpeed * elapsedTime;
yprElem.y -= offsetY * this.rockerRotationSpeed * elapsedTime;
Laya.Matrix4x4.createRotationYawPitchRoll(yprElem.x, yprElem.y, yprElem.z, this.rotateMatrix);
var moveMatrix = new Laya.Matrix4x4();
Laya.Matrix4x4.createTranslate(new Laya.Vector3(this.camera.transform.position.x, this.camera.transform.position.y, this.camera.transform.position.z), moveMatrix);
Laya.Matrix4x4.multiply(moveMatrix, this.rotateMatrix, this.rotateMatrix);
this.camera.transform.localMatrix = this.rotateMatrix;
console.log("Use Matrix Script!");
}
}
}
mouseDown(e) {
this.camera.transform.localRotation.getYawPitchRoll(this.yawPitchRoll);
this.lastMouseX = Laya.stage.mouseX;
this.lastMouseY = Laya.stage.mouseY;
this.isMouseDown = true;
}
mouseUp(e) {
this.isMouseDown = false;
}
moveForward(distance) {
this._tempVector3.x = 0;
this._tempVector3.y = 0;
this._tempVector3.z = distance;
this.camera.transform.translate(this._tempVector3);
}
moveRight(distance) {
this._tempVector3.y = 0;
this._tempVector3.z = 0;
this._tempVector3.x = distance;
this.camera.transform.translate(this._tempVector3);
}
moveVertical(distance) {
this._tempVector3.x = this._tempVector3.z = 0;
this._tempVector3.y = distance;
this.camera.transform.translate(this._tempVector3, false);
}
}
class loading {
constructor() {
Laya3D.init(0, 0);
if (Laya.Browser.onPC) {
Laya.stage.width = 1600;
Laya.stage.height = 750;
Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
}
else {
Laya.stage.width = 1334;
Laya.stage.height = 750;
Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Laya.Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_AUTO;
Laya.stage.screenMode = Laya.Stage.SCREEN_HORIZONTAL;
}
this.res = [
"res/threeDimen/texture/earth.png",
"res/threeDimen/scene/CourtyardScene/Courtyard.ls",
];
this.current = new Laya.Label();
this.progress = new Laya.ProgressBar("res/threeDimen/progress.png");
this.preLoad();
}
preLoad() {
var progressBox = new Laya.Box();
Laya.stage.addChild(progressBox);
progressBox.centerX = 0;
progressBox.centerY = 0;
progressBox.addChild(this.current);
progressBox.addChild(this.progress);
this.current.size(100, 35);
this.current.pos(166, 40);
this.current.fontSize = 50;
this.current.font = "SimHei";
this.current.color = "#ffffff";
this.current.bgColor = "#000000";
this.progress.size(460, 20);
this.progress.pos(0, 0);
this.progress.sizeGrid = "5,5,5,5,1";
Laya.loader.create(this.res, Laya.Handler.create(this, this.loadComplete), Laya.Handler.create(this, this.onLoading, null, false));
Laya.loader.on(Laya.Event.ERROR, this, this.loadError);
}
loadComplete() {
this.progress.value = 0.99;
this.current.text = "加载完毕";
console.log("资源加载完毕");
new CameraInteraction();
}
onLoading(progress) {
this.current.text = "加载中";
if (progress > 0.93) {
this.progress.value = 0.96;
}
else {
this.progress.value = progress;
}
}
loadError() {
console.error("加载资源失败");
}
}
class CameraInteraction extends Laya.View {
constructor() {
super();
Laya.Stat.show();
this.keyboard = new Laya.Box();
this.joystick = new Laya.Box();
this.isQuaternion = true;
this.isEuler = false;
this.isMatrix = false;
this.loadUI();
}
loadUI() {
var scene3D = Laya.Loader.getRes("res/threeDimen/scene/CourtyardScene/Courtyard.ls");
Laya.stage.addChild(scene3D);
this.camera = scene3D.addChild(new Laya.Camera(0, 0.1, 100));
this.camera.transform.translate(new Laya.Vector3(57, 2.5, 58), false);
this.camera.transform.rotate(new Laya.Vector3(-10, 150, 0), true, false);
this.camera.addComponent(CameraMoveQuaternion);
this.camera.addComponent(CameraMoveEuler);
this.camera.addComponent(CameraMoveMatrix);
this.camera.getComponent(CameraMoveQuaternion).enabled = this.isQuaternion;
this.camera.getComponent(CameraMoveEuler).enabled = this.isEuler;
this.camera.getComponent(CameraMoveMatrix).enabled = this.isMatrix;
var directionLight = scene3D.addChild(new Laya.DirectionLight());
directionLight.color = new Laya.Vector3(0.6, 0.6, 0.6);
directionLight.transform.worldMatrix.setForward(new Laya.Vector3(1, -1, 0));
this.keyboard.addComponent(KeyBoard);
this.keyboard.width = 400;
this.keyboard.height = 300;
this.keyboard.left = 20;
this.keyboard.bottom = 20;
var q = new Laya.Sprite();
var w = new Laya.Sprite();
var e = new Laya.Sprite();
var a = new Laya.Sprite();
var s = new Laya.Sprite();
var d = new Laya.Sprite();
this.keyboard.addChild(q);
this.keyboard.addChild(w);
this.keyboard.addChild(e);
this.keyboard.addChild(a);
this.keyboard.addChild(s);
this.keyboard.addChild(d);
q.loadImage("res/threeDimen/q.png");
q.pos(0, 30);
q.name = "q";
w.loadImage("res/threeDimen/w.png");
w.pos(110, 30);
w.name = "w";
e.loadImage("res/threeDimen/e.png");
e.pos(220, 30);
e.name = "e";
a.loadImage("res/threeDimen/a.png");
a.pos(0, 140);
a.name = "a";
s.loadImage("res/threeDimen/s.png");
s.pos(110, 140);
s.name = "s";
d.loadImage("res/threeDimen/d.png");
d.pos(220, 140);
d.name = "d";
Laya.stage.addChild(this.keyboard);
this.joystick.left = 0;
this.joystick.right = 0;
this.joystick.top = 0;
this.joystick.bottom = 0;
this.leftJoyStick = new Laya.Box();
this.joystick.addChild(this.leftJoyStick);
this.leftJoyStick.name = "leftJoyStick";
this.leftJoyStick.addComponent(JoyStick);
this.leftJoyStick.width = 215;
this.leftJoyStick.height = 215;
this.leftJoyStick.left = 50;
this.leftJoyStick.bottom = 50;
var bg = new Laya.Sprite();
this.leftJoyStick.addChild(bg);
bg.loadImage("res/threeDimen/joystick_bg.png");
bg.width = 215;
bg.height = 215;
bg.name = "bg";
var axis = new Laya.Sprite();
this.leftJoyStick.addChild(axis);
axis.loadImage("res/threeDimen/joystick_axis.png");
axis.width = 78;
axis.height = 78;
axis.name = "axis";
axis.pos(70, 70);
this.rightJoyStick = new Laya.Box();
this.joystick.addChild(this.rightJoyStick);
this.rightJoyStick.name = "rightJoyStick";
this.rightJoyStick.addComponent(JoyStick);
this.rightJoyStick.width = 215;
this.rightJoyStick.height = 215;
this.rightJoyStick.right = 50;
this.rightJoyStick.bottom = 50;
var bg = new Laya.Sprite();
this.rightJoyStick.addChild(bg);
bg.loadImage("res/threeDimen/joystick_bg.png");
bg.width = 215;
bg.height = 215;
bg.name = "bg";
var axis = new Laya.Sprite();
this.rightJoyStick.addChild(axis);
axis.loadImage("res/threeDimen/joystick_axis.png");
axis.width = 78;
axis.height = 78;
axis.name = "axis";
axis.pos(70, 70);
Laya.stage.addChild(this.joystick);
this.camera.getComponent(CameraMoveQuaternion).moveRocker = this.leftJoyStick.getComponent(JoyStick);
this.camera.getComponent(CameraMoveQuaternion).rotationRocker = this.rightJoyStick.getComponent(JoyStick);
this.camera.getComponent(CameraMoveEuler).moveRocker = this.leftJoyStick.getComponent(JoyStick);
this.camera.getComponent(CameraMoveEuler).rotationRocker = this.rightJoyStick.getComponent(JoyStick);
this.camera.getComponent(CameraMoveMatrix).moveRocker = this.leftJoyStick.getComponent(JoyStick);
this.camera.getComponent(CameraMoveMatrix).rotationRocker = this.rightJoyStick.getComponent(JoyStick);
this.switchBtn = Laya.stage.addChild(new Laya.Button("res/threeDimen/ui/button.png", "切换到欧拉角变换模式"));
this.switchBtn.size(300, 40);
this.switchBtn.labelBold = true;
this.switchBtn.labelSize = 30;
this.switchBtn.sizeGrid = "4,4,4,4";
this.switchBtn.scale(Laya.Browser.pixelRatio, Laya.Browser.pixelRatio);
this.switchBtn.pos(Laya.stage.width / 2 - this.switchBtn.width * Laya.Browser.pixelRatio / 2, 10 * Laya.Browser.pixelRatio);
this.switchBtn.on(Laya.Event.CLICK, this, this.switchScript);
if (Laya.Browser.onPC) {
this.keyboard.visible = true;
this.joystick.visible = false;
var text = new Laya.Label();
text.pos(Laya.stage.width / 2 - this.switchBtn.width * Laya.Browser.pixelRatio / 2, 60 * Laya.Browser.pixelRatio);
text.overflow = Laya.Text.HIDDEN;
text.color = "#ea4335";
text.font = "Impact";
text.fontSize = 20;
text.borderColor = "#ea4335";
text.text = "摇杆模式请扫二维码预览!";
Laya.stage.addChild(text);
}
else {
this.keyboard.visible = false;
this.joystick.visible = true;
}
}
switchScript() {
if (this.isQuaternion) {
this.isEuler = true;
this.isQuaternion = false;
this.isMatrix = false;
this.camera.getComponent(CameraMoveQuaternion).enabled = this.isQuaternion;
this.camera.getComponent(CameraMoveEuler).enabled = this.isEuler;
this.camera.getComponent(CameraMoveMatrix).enabled = this.isMatrix;
this.switchBtn.label = "切换到矩阵变换模式";
}
else if (this.isEuler) {
this.isEuler = false;
this.isQuaternion = false;
this.isMatrix = true;
this.camera.getComponent(CameraMoveQuaternion).enabled = this.isQuaternion;
this.camera.getComponent(CameraMoveEuler).enabled = this.isEuler;
this.camera.getComponent(CameraMoveMatrix).enabled = this.isMatrix;
this.switchBtn.label = "切换到四元数变换模式";
}
else if (this.isMatrix) {
this.isEuler = false;
this.isQuaternion = true;
this.isMatrix = false;
this.camera.getComponent(CameraMoveQuaternion).enabled = this.isQuaternion;
this.camera.getComponent(CameraMoveEuler).enabled = this.isEuler;
this.camera.getComponent(CameraMoveMatrix).enabled = this.isMatrix;
this.switchBtn.label = "切换到欧拉角变换模式";
}
}
}
new loading();
exports.CameraInteraction = CameraInteraction;
exports.CameraMoveEuler = CameraMoveEuler;
exports.CameraMoveQuaternion = CameraMoveQuaternion;
exports.JoyStick = JoyStick;
exports.KeyBoard = KeyBoard;
exports.default = CameraMoveMatrix;
exports.loading = loading;
return exports;
}({}));
//# sourceMappingURL=bundle.js.map
1
https://gitee.com/layabox/layaAir2-example.git
git@gitee.com:layabox/layaAir2-example.git
layabox
layaAir2-example
LayaAir2.x引擎示例源码
master

搜索帮助