最近工作可真是忙得晕头转向啊,这不,刚处理完客户反馈的一个严重问题,就赶紧来研究 aardio 的更新了。这次 aardio 的更新在类和结构体方面有不少亮点呢。
在类的定义上,有了更明确的规则。例如在 doc/guide/language/syntax-quick-ref.md
文件中,类的构造函数现在必须写在最前面,而且类的成员必须使用分号隔开。就像这样:
class className{
//可选定义类的构造函数,必须写在最前面。
ctor(name,...){
//在类主体内部通过 this 对象访问当前实例成员,this 仅在类主体内有效。
this.property = staticProperty; //无 this 前缀的 staticProperty 是类的静态成员。
this.args = {...};
};
//定义属性,必须写为名值对格式,类的成员必须使用分号隔开
property = "value";
//定义方法(成员函数),必须写为名值对格式,不能省略等号或 function 关键字。
method = function(v){
..console.log("method",v);
this.property = v;
};
}
//打开类的名字空间(类的所有实例共享)定义静态成员
namespace className{
staticProperty = "类的静态变量值";
}
在类主体外添加实例方法时,要注意使用 owner
参数引用当前对象,因为在类主体外部 this
对象默认是 null
值。
结构体方面,RECT
和 RECTF
结构体得到了很大的增强。以 RECT
结构体为例,其构造函数现在可以接受一个表作为参数,方便初始化:
class ::RECT {
ctor(left=0,top=0,right=0,bottom=0){
if(type(left)==="table"){
var rc = left;
if(rc[["left"]]){
this.left = rc.left;
this.top = rc.top;
this.right = rc.right;
this.bottom = rc.bottom;
}
else{
this.left = rc.x;
this.top = rc.y;
this.right = rc.x + rc.width;
this.bottom = rc.y + rc.height;
}
}
else{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
}
并且 RECT
结构体还添加了很多实用的方法,比如 intersectsWith
用于检测两个矩形区块是否碰撞相交,intersect
用于检测与参数指定的矩形区块相交等。
在一些示例代码中也有更新,像 example/Console/loading.aardio
文件里,sleep
的时间从 30 改成了 5,让加载效果更流畅。
这些更新让 aardio 的类和结构体使用起来更加方便和强大,相信能给开发者带来更好的开发体验。
个人学习笔记,大家不要与官方混淆