当前位置:网站首页>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-0
3.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"); //广播--开始游戏
}));
边栏推荐
- Data warehouse (1) What is data warehouse and what are the characteristics of data warehouse
- [Teach you to use the serial port idle interrupt of the STM32HAL library]
- js数据类型、节流/防抖、点击事件委派优化、过渡动画
- 该如何训练好深度学习模型?
- Feign 与 OpenFeign
- Debug locally and start the local server in vs code
- [21 days learning challenge - kernel notes] (2), based in the device tree
- Web3时代的战争
- 【AGC】构建服务1-云函数示例
- Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
猜你喜欢
Big capital has begun to flee the crypto space?
How to understand the crawler's Scrapy framework in the simplest and most popular way?
for 循环中的 ++i 与 i++
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
ts集成和使用
LINQ to SQL (Group By/Having/Count/Sum/Min/Max/Avg操作符)
【2022牛客多校5 A题 Don‘t Starve】DP
大资本已开始逃离加密领域?
c语言小项目(三子棋游戏实现)
PowerCLi 批量配置NTP
随机推荐
DSPE-PEG-Aldehyde,DSPE-PEG-CHO,磷脂-聚乙二醇-醛基一种疏水18碳磷脂
Matlab画图2
C语言知识大全(一)——C语言概述,数据类型
基于单向链表结构的软件虚拟定时器的设计与构建
顺序队列
matlab 画图
【编程思想】
某男子因用本地虚拟机做压测,惨遭字节面试官当场嘲笑
[2022 Nioke Duo School 5 A Question Don't Starve] DP
【PCBA方案设计】握力计方案
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
工龄10年的测试员从大厂“裸辞”后...
88.(cesium之家)cesium聚合图
dotnet 通过 WMI 获取系统安装软件
run command for node
遇到MapStruct后,再也不手写PO,DTO,VO对象之间的转换了
web漏洞扫描器-awvs
c语言小项目(三子棋游戏实现)
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
两种白名单限流方案(redis lua限流,guava方案)