当前位置:网站首页>LayaBox---knowledge point
LayaBox---knowledge point
2022-08-04 21:09:00 【Gragra】
目录
2.Defines the variable displayed in the properties panel
3.Get the script to mount the object component
4.Remove mounted scripts,Also have to remove the reference on the mount object.
6.Defined public object variablesnode There are no coordinate properties,需进行类型转换
8.LayaEvent broadcasting and reception
13.The code gets the in-game object
1.visualcode---配置model快捷模版
code---首选项---配置用户代码片段
2.Defines the variable displayed in the properties panel
/** @prop {name:intType, tips:"整数类型示例", type:Int, default:1000}*/
public intType: number = 1000;
/** @prop {name:numType, tips:"数字类型示例", type:Number, default:1000}*/
public numType: number = 1000;
/** @prop {name:strType, tips:"字符串类型示例", type:String, default:"hello laya"}*/
public strType: string = "hello laya";
/** @prop {name:boolType, tips:"布尔类型示例", type:Bool, default:true}*/
public boolType: boolean = true;
/** @prop {name:shoe,tips:"物体",type:Node,default:null}*/
public shoe = null;
// 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-03.Get the script to mount the object component
this.owner.getComponent(Laya.RigiBody);4.Remove mounted scripts,Also have to remove the reference on the mount object.
5.代码发生变动,Such as adding public variables.You need to manually switch the mouse to select objects,Select it again to refresh.
6.Defined public object variablesnode There are no coordinate properties,需进行类型转换
2d:
public get gameObject():Laya.Sprite
{
return this.owner as Laya.Sprite;
}
3d:
public get gameObject():Laya.Sprite3D
{
return this.owner as Laya.Sprite3D;
}
-------------------------------------------------
public get transform():Laya.Transform
{
return this.gameObject.transform;
}7.Laya脚本参数说明
8.LayaEvent broadcasting and reception
广播事件:
Laya.stage.event("事件名");接收事件:
onAwake()
{
//添加监听
Laya.stage.on("事件名",this,this.reset);
}
private reset(){
//.....
}
onDestroy(){
//移除监听
Laya.stage.off("事件名",this,this.reset);
}9.插值
Laya.MathUtill.lerp(curObj.x,targetObj.x,Laya.timer.delta/1000 * speed);10.勾股定理 求距离
a*a + b*b = c*c;
c = Math.sqrt(a*a + b*b);11.随机值
private getRandom(min, max)
{
let value = max - min;
value = Math.random() * value;
return value + min;
}12.获取键盘按键
1.
onUpdate()
{
if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.A))
{
this.rig.setVelocity({ x: -10, y: this.rig.linearVelocity.y });
} else if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.D))
{
this.rig.setVelocity({ x: 10, y: this.rig.linearVelocity.y });
}
}
2.
onKeyDown(e)
{
//console.log(e.nativeEvent.key+".........2");
if (e.nativeEvent.key == " " && this.canJump)
{
this.canJump = false;
this.rig.setVelocity({ x: this.rig.linearVelocity.x, y: -13 });
}
}
3.
onKeyPress(e)
{
console.log(e.nativeEvent.key+".........1");
if(e.nativeEvent.key == "a")
{
}
}13.The code gets the in-game object
//Find primary objects
Laya.stage.getChildByName("Player");
//Find sub-objects under this object
this.owner.getChildByName("child object name");14.音乐音效播放
//播放音乐
Laya.soundManager.playMusic(“地址/music.mp3”,0); //0为无限循环
//Just play sound effects
Laya.SoundManager.playSound("sound/BallHit-01.mp3");
//Add an event after playback is complete
Laya.SoundManager.playSound("sound/startWistle.mp3",1,
new Laya.Handler(this,()=>{
Laya.stage.event("StartGame"); //广播--开始游戏
}));边栏推荐
猜你喜欢

DSPE-PEG-Aldehyde,DSPE-PEG-CHO,磷脂-聚乙二醇-醛基一种疏水18碳磷脂

【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...

无代码平台字段设置:基础设置入门教程

Feign 与 OpenFeign

嵌入式分享合集28

mdk5.14 cannot be burned

Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!

构建Buildroot根文件系统(I.MX6ULL)

ADB 安装 + 打驱动全教程

web漏洞扫描器-awvs
随机推荐
visual studio 2015 warning MSB3246
后缀式的计算
Web3安全风险令人生畏,应该如何应对?
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
After the tester with 10 years of service "naked resignation" from the big factory...
proe和creo的区别有哪些
香港暂停进口俄罗斯部分地区禽肉及禽类产品
bracket matching
【AGC】构建服务1-云函数示例
adb shell input keyevent 模拟按键事件
Matlab画图2
DICOM医学影像协议
moke、动态图片资源打包显示
动手学深度学习_NiN
大资本已开始逃离加密领域?
c语言小项目(三子棋游戏实现)
工龄10年的测试员从大厂“裸辞”后...
MySQL field type
1.读写点云文件
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership