API Manual

From LuaSTG Wiki
Jump to navigation Jump to search

Introduction[edit | edit source]

This page shows documents of core API of LuaSTG, including Plus and X version.

To get original API manual of LuaSTGPlus, please visit here.

To get full API document of LuaSTG-x, please visit here. It's better for LuaSTG-x users to use this document since many functions are extended.
本页面为LuaSTG的核心API文档,包括Plus和X版本。

LuaSTGPlus的原始API手册见此处

LuaSTG-x的完整API文档见此处。由于新增了大量函数,推荐LuaSTG-x用户使用该文档。
This page shows documents of core API of LuaSTG, including Plus and X version.

To get original API manual of LuaSTGPlus, please visit here.

To get full API document of LuaSTG-x, please visit here. It's better for LuaSTG-x users to use this document since many functions are extended.


Global Variables[edit | edit source]

lstg[edit | edit source]

[P] [X]

Holds API functions and many script stuff. Functions will be exported to global space at launch.
持有API函数及一些脚本内容。函数会在启动时导出到全局空间。
Holds API functions and many script stuff. Functions will be exported to global space at launch.
Type
table
args[edit | edit source]

[P]

Holds command line arguments as an array of string.
以字符串数组的形式持有命令行参数。
Holds command line arguments as an array of string.
Type
table
_ARGS[edit | edit source]

[X]

Holds command line arguments as an array of string.
以字符串数组的形式持有命令行参数。
Holds command line arguments as an array of string.
Type
table

Frame Control[edit | edit source]

SetWindowed(isWindowed)

[P] [X] [static] [deprecated in X]

Set the engine windowed or full-screen. true for windowed and false for full-screen. Default is true.
  • (P) Can only be invoked during launch instead of runtime.
设置引擎以窗口或全屏模式运行。true 为窗口, false 为全屏。默认为 true.
  • (P) 仅限初始化时使用,无法在运行时使用。
Set the engine windowed or full-screen. true for windowed and false for full-screen. Default is true.
  • (P) Can only be invoked during launch instead of runtime.

Parameters参数パラメータ

isWindowedboolean
SetFPS(targetFPS)

[P] [X] [static]

Set target FPS. Default is 60.
  • (P) Can only be invoked during launch instead of runtime.
设置引擎运行的目标帧率。默认为 60
  • (P) 仅限初始化时使用,无法在运行时使用。
Set target FPS. Default is 60.
  • (P) Can only be invoked during launch instead of runtime.

Parameters参数パラメータ

targetFPSnumber
GetFPS()

[P] [X] [static]

Get current FPS (not target FPS).
获取引擎的当前帧率(非目标帧率)。
Get current FPS (not target FPS).

Return value返回值戻り値

number
SetVsync(isEnable)

[P] [X] [static]

Set V-Sync. Default is true.
  • (P) Can only be invoked during launch instead of runtime.
设置是否开启垂直同步。默认为 true
  • (P) 仅限初始化时使用,无法在运行时使用。
Set V-Sync. Default is true.
  • (P) Can only be invoked during launch instead of runtime.

Parameters参数パラメータ

isEnableboolean
SetResolution(width, height)

[P] [X] [static]

Set window resolution (size) if game is windowed. Default is 640, 480.
  • (P) Can only be invoked during launch instead of runtime.
设置引擎的窗口分辨率(大小)。默认为 640, 480
  • (P) 仅限初始化时使用,无法在运行时使用。
Set window resolution (size) if game is windowed. Default is 640, 480.
  • (P) Can only be invoked during launch instead of runtime.

Parameters参数パラメータ

widthnumber
heightnumber
ChangeVideoMode(width, height, windowed, vsync)

[P] [X] [static]

Change display parameters. Returns true if success, otherwise returns false and restore last parameters.
  • (P) Can only be invoked during runtime.
设置显示参数。若成功返回 true,否则返回 false 并恢复到上次的参数。
  • (P) 仅限运行时使用。
Change display parameters. Returns true if success, otherwise returns false and restore last parameters.
  • (P) Can only be invoked during runtime.

Parameters参数パラメータ

widthnumber
heightnumber
windowedboolean
vsyncboolean

Return value返回值戻り値

boolean
SetSplash(boolean)

[P] [X] [static]

Set if the mouse cursor is displayed in game window.
  • (P) Default is false.
  • (X) Default is true.
设置是否显示在窗口内光标。
  • (P) 默认为 false.
  • (X) 默认为 true.
Set if the mouse cursor is displayed in game window.
  • (P) Default is false.
  • (X) Default is true.

Parameters参数パラメータ

boolean
SetTitle(title)

[P] [X] [static]

Set the caption of window.
  • (P) Default is "LuaSTGPlus".
  • (X) Default is "LuaSTG-x".
设置窗口标题。
  • (P) 默认为 "LuaSTGPlus".
  • (X) 默认为 "LuaSTG-x".
Set the caption of window.
  • (P) Default is "LuaSTGPlus".
  • (X) Default is "LuaSTG-x".

Parameters参数パラメータ

titlestring
SystemLog(str)

[P] [X] [static]

Write string to log file.
将字符串写入日志文件。
Write string to log file.

Parameters参数パラメータ

strstring
Print(...)

[P] [X] [static]

  • (P) Write values to log file.
  • (X) Print values to console on desktop platforms. Write values to log file on mobile platforms.

  • (P) 将多个值写入日志文件。
  • (X) 在桌面平台上将多个值打印至console。在移动平台上将多个值写入日志文件。

  • (P) Write values to log file.
  • (X) Print values to console on desktop platforms. Write values to log file on mobile platforms.

Parameters参数パラメータ

...
LoadPack(path, password)

[P] [X] [static]

Load zip pack at path with an optional password.

Will throw an error if failed.

Detail
Zip pack loaded later will have higher priority. So you can override files in previous packs.
Zip file will be occupied after loaded.
Files required by engine will be searched in packs at first, then local path.
加载位于 path 的资源包,可选填密码。

失败时将抛出错误。

细节
后加载的资源包有较高的查找优先级。这意味着可以覆盖之前包中的文件。
zip文件在加载后将被程序占用。
加载文件时将按照优先级依次搜索,若资源包中未找到则从本地路径加载。
Load zip pack at path with an optional password.

Will throw an error if failed.

Detail
Zip pack loaded later will have higher priority. So you can override files in previous packs.
Zip file will be occupied after loaded.
Files required by engine will be searched in packs at first, then local path.

Parameters参数パラメータ

pathstring
passwordstring [optional]
UnloadPack(path)

[P] [X] [static]

Unload zip pack loaded at path. Will NOT throw an error if failed.
卸载位于 path 的资源包。 失败时将不会抛出错误。
Unload zip pack loaded at path. Will NOT throw an error if failed.

Parameters参数パラメータ

pathstring
ExtractRes(path, target)

[P] [X] [static]

Extract files in pack to local path. Will throw an error if failed.
将资源包中的文件解压到本地。 失败时将抛出错误。
Extract files in pack to local path. Will throw an error if failed.

Parameters参数パラメータ

pathstring
targetstring
DoFile(path)

[P] [X] [static]

Execute script at path. Similar to dofile() of Lua. Will throw an error if script not exists, failed to compile or failed to execute.
执行位于 path 的脚本。与Lua中的 dofile() 类似。 若文件不存在、编译失败或执行失败则抛出错误。
Execute script at path. Similar to dofile() of Lua. Will throw an error if script not exists, failed to compile or failed to execute.

Parameters参数パラメータ

pathstring
ShowSplashWindow(path)

[P] [X] [static] [deprecated in X]

  • (P) Set the loading picture.
Will use default picture if failed or path not passed.
  • (X) Do nothing.

  • (P) 设置启动图片。
若图片加载失败或为空则使用默认图片。
  • (X) 无作用。

  • (P) Set the loading picture.
Will use default picture if failed or path not passed.
  • (X) Do nothing.

Parameters参数パラメータ

pathstring [optional] Path of picture file.

Game Object Pool[edit | edit source]

GetnObj()

[P] [X] [static]

Get game object count.
获取游戏对象的数量。
Get game object count.

Return value返回值戻り値

number
ObjFrame()

[P] [X] [static]

Update all game objects.

Do not invoke in coroutine.

Detail
Properties will be updated in the following order:
vx += ax
vy += ay
x += vx
y += vy
rot += omiga
Update paritle system if there is
更新所有游戏对象。

禁止在协程上调用该方法。

细节
属性将按以下顺序更新:
vx += ax
vy += ay
x += vx
y += vy
rot += omiga
更新粒子系统(若有)
Update all game objects.

Do not invoke in coroutine.

Detail
Properties will be updated in the following order:
vx += ax
vy += ay
x += vx
y += vy
rot += omiga
Update paritle system if there is
ObjRender()

[P] [X] [static]

Render all game objects. Will invoke rander() callback one by one.

Object with smaller layer property will be rendered first.

Do not invoke in coroutine.
渲染所有游戏对象。将依次调用 rander() 回调。

具有较小 layer 属性的游戏对象将会先渲染。

禁止在协程上调用该方法。
Render all game objects. Will invoke rander() callback one by one.

Object with smaller layer property will be rendered first.

Do not invoke in coroutine.
SetBound(left, right, bottom, top)

[P] [X] [static]

Set boundary for game objects.
设置游戏对象的边界。
Set boundary for game objects.

Parameters参数パラメータ

leftnumber
rightnumber
bottomnumber
topnumber
BoundCheck()

[P] [X] [static]

Do boundary check and mark objects outside boundary as del status.

An object will not be marked if bound property is false.

Do not invoke in coroutine.
执行边界检查并将边界外的游戏对象标记为 del 状态。

当游戏对象的 bound 属性为 false 时将不会被标记。

禁止在协程上调用该方法。
Do boundary check and mark objects outside boundary as del status.

An object will not be marked if bound property is false.

Do not invoke in coroutine.
CollisionCheck(A, B)

[P] [X] [static]

Do collision chekc on A and B.

If an object (in group) A collides another object (in group) B, its colli() callback will be invoked and the other object will be passed as parameter.

  • (P) A and B are group IDs.
  • (X) A and B can be either group ID or object.
Do not invoke in coroutine.
AB 进行碰撞检测。

A(组中的)对象和 B(组中的)对象发生碰撞,前者的 colli() 回调将会被调用,后者会作为参数传入。

  • (P) AB 为碰撞组ID。
  • (X) AB 为碰撞组ID或游戏对象。
禁止在协程上调用该方法。
Do collision chekc on A and B.

If an object (in group) A collides another object (in group) B, its colli() callback will be invoked and the other object will be passed as parameter.

  • (P) A and B are group IDs.
  • (X) A and B can be either group ID or object.
Do not invoke in coroutine.

Parameters参数パラメータ

Anumber/object
Bnumber/object
UpdateXY()

[P] [X] [static]

Update following properties of all objects: dx, dy, lastx, lasty, rot (when navi is true). Do not invoke in coroutine.
更新所有游戏对象的以下属性:dx, dy, lastx, lasty, rot(当 navi 为 true)。 禁止在协程上调用该方法。
Update following properties of all objects: dx, dy, lastx, lasty, rot (when navi is true). Do not invoke in coroutine.
AfterFrame()

[P] [X] [static]

Update following properties of all objects: timer, ani_timer. Trim objects marked as del or kill.

Do not invoke in coroutine.

Detail
Set status property of an object to "normal" to preserve it.
更新所有游戏对象的以下属性:timer, ani_timer。销毁被标记为 delkill 的游戏对象。

禁止在协程上调用该方法。

细节
将游戏对象的 status 属性设置为 "normal" 可以将其保留。
Update following properties of all objects: timer, ani_timer. Trim objects marked as del or kill.

Do not invoke in coroutine.

Detail
Set status property of an object to "normal" to preserve it.
New(class)

[P] [X] [static]

Creates a game object and returns it.
Detail
Game object is created based on class and will invoke init() callback.
Created object will have following properties:
x, ycoordinates
dx, dydifference of coordinates from last update (read-only)
rotorientation (in degrees)
omigaangular velocity of orientation
timerupdate counter
vx, vyvelocity
ax, ayacceleration
layerrender layer
groupcollision group
hideif object will not be rendered
boundif object will be marked at boundary check
naviif orientation will be updated according to velocity
colliif object will be involved in collision check
statusstatus of object, can be "del", "kill" or "normal"
hscale, vscalescale of horizontal and verticle for render
classclass of the object
a, bparameters of collision box size
rectif collision box is rectangle
imgname of renderable resource on the object
anianimation timer (read-only)
Index 1 and 2 of the object will be class and internal ID, do not modify them.
class should have following properties:
is_class = true
[1] = init(object, ...) callback
[2] = del(object, ...) callback
[3] = frame(object) callback
[4] = render(object) callback
[5] = colli(object, object) callback
[6] = kill(object, ...) callback
Callbacks will be invoked when corresponding event happens.
The upper limit of object count is 32768. An error will be thrown if it exceeds.
创建一个游戏对象并返回。
细节
游戏对象基于 class 创建并将调用 init() 回调。
被创建的对象具有如下属性:
x, y坐标
dx, dy坐标相对于上次更新时的增量(只读)
rot朝向(角度)
omiga朝向的角速度
timer更新计数器
vx, vy速度
ax, ay加速度
layer渲染层级
group碰撞组
hide是否隐藏(跳过渲染回调)
bound是否越界销毁
navi是否根据速度自动更新朝向
colli是否参与碰撞检测
status对象状态,取值为 "del", "kill" 或 "normal"
hscale, vscale横向、纵向的渲染缩放
class对象的类
a, b碰撞盒尺寸的参数
rect是否为矩形碰撞盒
img绑定的可渲染资源的名字
ani动画计数器(只读)
游戏对象的索引 12 用于保存 class 和内部ID,请勿修改。
class 需要具有以下属性:
is_class = true
[1] = init(object, ...) callback
[2] = del(object, ...) callback
[3] = frame(object) callback
[4] = render(object) callback
[5] = colli(object, object) callback
[6] = kill(object, ...) callback
回调函数将在对象触发相应事件时被调用。
游戏对象数量的上限为32768。超出后将抛出错误。
Creates a game object and returns it.
Detail
Game object is created based on class and will invoke init() callback.
Created object will have following properties:
x, ycoordinates
dx, dydifference of coordinates from last update (read-only)
rotorientation (in degrees)
omigaangular velocity of orientation
timerupdate counter
vx, vyvelocity
ax, ayacceleration
layerrender layer
groupcollision group
hideif object will not be rendered
boundif object will be marked at boundary check
naviif orientation will be updated according to velocity
colliif object will be involved in collision check
statusstatus of object, can be "del", "kill" or "normal"
hscale, vscalescale of horizontal and verticle for render
classclass of the object
a, bparameters of collision box size
rectif collision box is rectangle
imgname of renderable resource on the object
anianimation timer (read-only)
Index 1 and 2 of the object will be class and internal ID, do not modify them.
class should have following properties:
is_class = true
[1] = init(object, ...) callback
[2] = del(object, ...) callback
[3] = frame(object) callback
[4] = render(object) callback
[5] = colli(object, object) callback
[6] = kill(object, ...) callback
Callbacks will be invoked when corresponding event happens.
The upper limit of object count is 32768. An error will be thrown if it exceeds.

Parameters参数パラメータ

classtable
Del(object, ...)

[P] [X] [static]

Mark object as del status and invoke del() callback. Parameters passed after object will be passed to del() callback.
将游戏对象标记为 del 状态并调用 del() 回调。 在 object 之后的参数将传入 del() 回调。
Mark object as del status and invoke del() callback. Parameters passed after object will be passed to del() callback.

Parameters参数パラメータ

object
...[optional]
Kill(object, ...)

[P] [X] [static]

Mark object as kill status and invoke kill() callback. Parameters passed after object will be passed to kill() callback.
将游戏对象标记为 kill 状态并调用 kill() 回调。 在 object 之后的参数将传入 kill() 回调。
Mark object as kill status and invoke kill() callback. Parameters passed after object will be passed to kill() callback.

Parameters参数パラメータ

object
...[optional]
IsValid(object)

[P] [X] [static]

Check if object is valid (not trimmed).
检查游戏对象是否有效(未被销毁)。
Check if object is valid (not trimmed).

Parameters参数パラメータ

object
GetV(object)

[P] [X] [static]

Returns magnitude (speed) and direction (in degrees) of object velocity.
返回游戏对象的速度大小和速度方向(角度)。
Returns magnitude (speed) and direction (in degrees) of object velocity.

Parameters参数パラメータ

object

Return value返回值戻り値

number,number
SetV(object, magnitude, direction, updateRot)

[P] [X] [static]

Set magnitude (speed) and direction (in degrees) of object velocity. Will update rot property if updateRot is true.
设置游戏对象的速度大小和速度方向(角度)。当 updateRottrue 时将更新 rot 属性。
Set magnitude (speed) and direction (in degrees) of object velocity. Will update rot property if updateRot is true.

Parameters参数パラメータ

objectobject
magnitudenumber
directionnumber
updateRotboolean
SetImgState(object, blend, a, r, g, b)

[P] [X] [static]

Set parameters of the renderable resource bind to object.
设置绑定在 object 上的可渲染资源的参数。
Set parameters of the renderable resource bind to object.

Parameters参数パラメータ

object
blendstring
anumber
rnumber
gnumber
bnumber
Angle(a, b)

[P] [X] [static]

Returns angle between the line connecting two objects and X axis in degrees.
返回两个游戏对象连线与X轴正方向的夹角(角度)。
Returns angle between the line connecting two objects and X axis in degrees.

Parameters参数パラメータ

aobject
bobject

Return value返回值戻り値

number
Angle(x1, y1, x2, y2)

[P] [X] [static]

Returns angle between the line connecting two points and X axis in degrees.
返回两点连线与X轴正方向的夹角(角度)。
Returns angle between the line connecting two points and X axis in degrees.

Parameters参数パラメータ

x1number
y1number
x2number
y2number

Return value返回值戻り値

number
Dist(a, b)

[P] [X] [static]

Returns distance between two objects.
返回两个游戏对象的距离。
Returns distance between two objects.

Parameters参数パラメータ

aobject
bobject

Return value返回值戻り値

number
Dist(x1, y1, x2, y2)

[P] [X] [static]

Returns distance between (x1,y1) and (x2,y2).
返回点 (x1,y1) 和 (x2,y2) 的距离。
Returns distance between (x1,y1) and (x2,y2).

Parameters参数パラメータ

x1number
y1number
x2number
y2number

Return value返回值戻り値

number
BoxCheck(object, left, right, top, bottom)

[P] [X] [static]

Check if position of object is in the given range.
检查 object 的位置是否在给定范围内。
Check if position of object is in the given range.

Parameters参数パラメータ

object
leftnumber
rightnumber
topnumber
bottomnumber

Return value返回值戻り値

boolean
ResetPool()

[P] [X] [static]

Trim all game objects immediately.
立即回收所有游戏对象。
Trim all game objects immediately.
DefaultRenderFunc(object)

[P] [X] [static]

Default render function for a game object.
游戏对象的默认渲染函数。
Default render function for a game object.

Parameters参数パラメータ

object
NextObject(groupid, id)

[P] [X] [static]

Iterates objects in a group if groupid is valid, otherwise iterates all objects. This is manual version of ObjList().
groupid 有效时,在该组中遍历游戏对象,否则遍历所有游戏对象。 ObjList() 的手动版本。
Iterates objects in a group if groupid is valid, otherwise iterates all objects. This is manual version of ObjList().

Parameters参数パラメータ

groupidnumber
idnumber

Return value返回值戻り値

number,object
ObjList(groupid)

[P] [X] [static]

Returns an iterator that go through objects in a group.
Example
for _, obj in ObjList(GROUP_ITEM) do ... end
返回一个能够遍历组中游戏对象的迭代器。
示例
for _, obj in ObjList(GROUP_ITEM) do ... end
Returns an iterator that go through objects in a group.
Example
for _, obj in ObjList(GROUP_ITEM) do ... end

Parameters参数パラメータ

groupidnumber

Return value返回值戻り値

function
ParticleFire(object)

[P] [X] [static]

Start particle emitter on object.
启动绑定在对象上的粒子发射器。
Start particle emitter on object.

Parameters参数パラメータ

object
ParticleStop(object)

[P] [X] [static]

Stop particle emitter on object.
停止绑定在对象上的粒子发射器。
Stop particle emitter on object.

Parameters参数パラメータ

object
ParticleGetn(object)

[P] [X] [static]

Returns current particle count on object.
返回绑定在对象上的粒子发射器的当前粒子数。
Returns current particle count on object.

Parameters参数パラメータ

object

Return value返回值戻り値

number
ParticleGetEmission(object)

[P] [X] [static]

Returns particle emit frequency on object (count per second).
Detail
Particle emitter will always step by 1/60 seconds.
返回绑定在对象上粒子发射器的发射密度(个/秒)。
细节
粒子发射器始终以1/60秒的步进更新。
Returns particle emit frequency on object (count per second).
Detail
Particle emitter will always step by 1/60 seconds.

Parameters参数パラメータ

object
ParticleSetEmission(object, count)

[P] [X] [static]

Set particle emit frequency on object (count per second).
设置绑定在对象上粒子发射器的发射密度(个/秒)。
Set particle emit frequency on object (count per second).

Parameters参数パラメータ

object
count

Game Resource[edit | edit source]

RemoveResource(poolType)

[P] [X] [static]

Clear a resources pool. poolType can be "global" or "stage". If a resource is in use, it will not be released until all usages are end.
清空一个资源池。poolType 为 "global" 或 "stage"。 若资源正在被使用,在使用结束前不会被释放。
Clear a resources pool. poolType can be "global" or "stage". If a resource is in use, it will not be released until all usages are end.

Parameters参数パラメータ

poolTypestring
RemoveResource(poolType, resType, name)

[P] [X] [static]

Remove a resource from a pool. poolType can be "global" or "stage". If a resource is in use, it will not be released until all usages are end.
从资源池中移除指定的资源。poolType 为 "global" 或 "stage"。 若资源正在被使用,在使用结束前不会被释放。
Remove a resource from a pool. poolType can be "global" or "stage". If a resource is in use, it will not be released until all usages are end.

Parameters参数パラメータ

poolTypestring
resTypenumber Resource type code
namestring
CheckRes(type, name)

[P] [X] [static]

Returns name of the pool where a resource is located. Usually used to check if a resource exists.
Detail
Will search in global pool at first, then stage pool.
Returns nil if resource not exists.
返回资源所在的资源池名称。通常用于检测资源是否存在。
细节
先在 global 池中查找,然后是 stage 池。
若资源不存在则返回 nil
Returns name of the pool where a resource is located. Usually used to check if a resource exists.
Detail
Will search in global pool at first, then stage pool.
Returns nil if resource not exists.

Parameters参数パラメータ

typenumber
namestring

Return value返回值戻り値

string
EnumRes(type)

[P] [X] [static]

Returns array of all resource names in global and stage pool respectively.
分别返回 globalstage 池中所有资源名字的数组。
Returns array of all resource names in global and stage pool respectively.

Parameters参数パラメータ

typenumber Resource type code

Return value返回值戻り値

table, table
GetTextureSize(name)

[P] [X] [static]

Returns width and height of a texture resource.
返回纹理资源的宽度和高度。
Returns width and height of a texture resource.

Parameters参数パラメータ

namestring

Return value返回值戻り値

number, number
LoadTexture(name, path, mipmap)

[P] [X] [static]

Load a texture resource from file.
从文件加载纹理资源。
Load a texture resource from file.

Parameters参数パラメータ

namestring
pathstring
mipmapboolean [optional] Default is false
LoadImage(name, tex_name, x, y, w, h, a, b, rect)

[P] [X] [static]

Load a image resource from a texture resource.
  • x, y specifies left-top of the image in texture coordinates (in pixels).
  • w, h specifies width and height of the image (in pixels).
  • a, b, rect specifies parameters of the collision box.
Detail
When a image resource is assigned to img property of an object, collision box parameters will be assigned to the object.
从纹理资源加载图像资源。
  • x, y 指定图像在纹理坐标的左上角位置(像素)。
  • w, h 指定图像的宽度和高度(像素)。
  • a, b, rect 指定碰撞盒参数。
细节
当图像资源被赋予游戏对象的 img 属性时,碰撞盒参数参数会同时赋予该对象。
Load a image resource from a texture resource.
  • x, y specifies left-top of the image in texture coordinates (in pixels).
  • w, h specifies width and height of the image (in pixels).
  • a, b, rect specifies parameters of the collision box.
Detail
When a image resource is assigned to img property of an object, collision box parameters will be assigned to the object.

Parameters参数パラメータ

namestring
tex_namestring
xnumber
ynumber
wnumber
hnumber
anumber [optional]
bnumber [optional]
rectboolean [optional]
SetImageState(name, blendMode, vertColor1, vertColor2, vertColor3, vertColor4)

[P] [X] [static]

Set parameters of a image resource. Optional vertex color parameters can be 1 or 4.
设置图像资源参数,可选1或4个顶点颜色参数。
Set parameters of a image resource. Optional vertex color parameters can be 1 or 4.

Parameters参数パラメータ

namestring
blendModestring
vertColor1lstg::Color [optional]
vertColor2lstg::Color [optional]
vertColor3lstg::Color [optional]
vertColor4lstg::Color [optional]
SetImageCenter(name, x, y)

[P] [X] [static]

Set center of an image resource to (x, y) relative to its left-top.
设置图像资源的中心为 (x, y) ,相对于图像的左上角。
Set center of an image resource to (x, y) relative to its left-top.

Parameters参数パラメータ

namestring
xnumber
ynumber
LoadAnimation(name, tex_name, x, y, w, h, n, m, interval, a, b, rect)

[P] [X] [static]

Load an animation resource from a texture resource.
  • x, y specifies top-left coordinates of the first frame.
  • w, h specifies width and height of one frame.
  • n, m specifies number of columns and rows.
  • interval specifies played interval in frames.
  • a, b, rect specifies parameters of the collision box.
Animations are always played repeatedly.
从纹理资源加载动画资源。
  • x, y 指定第一帧的左上角坐标。
  • w, h 指定每帧的宽度和高度。
  • n, m 指定列和行的数量。
  • interval 指定播放间隔,单位为帧。
  • a, b, rect 指定碰撞盒参数。
动画总是循环播放的。
Load an animation resource from a texture resource.
  • x, y specifies top-left coordinates of the first frame.
  • w, h specifies width and height of one frame.
  • n, m specifies number of columns and rows.
  • interval specifies played interval in frames.
  • a, b, rect specifies parameters of the collision box.
Animations are always played repeatedly.

Parameters参数パラメータ

namestring
tex_namestring
x, ynumber, number
w, hnumber, number
n, mnumber, number
intervalnumber
a, b, rectnumber, number, boolean [optional]
SetAnimationState(name, blend_mode, vertColor1, vertColor2, vertColor3, vertColor4)

[P] [X] [static]

Similar to SetImageState.
SetImageState 类似。
Similar to SetImageState.

Parameters参数パラメータ

namestring
blend_modestring
vertColor1lstg::Color [optional]
vertColor2lstg::Color [optional]
vertColor3lstg::Color [optional]
vertColor4lstg::Color [optional]
SetAnimationCenter(name, x, y)

[P] [X] [static]

Similar to SetImageCenter.
SetImageCenter 类似。
Similar to SetImageCenter.

Parameters参数パラメータ

namestring
xnumber
ynumber
LoadPS(name, def_file, img_name, a, b, rect)

[P] [X] [static]

Load a particle resource.
  • def_file specifies path of definition file.
  • img_name specifies name of image resource.
  • a, b, rect specifies parameters of the collision box.
Supports HGE format.
加载粒子资源。
  • def_file 指定定义文件的路径。
  • img_name 指定图像资源的名称。
  • a, b, rect 指定碰撞盒参数。
支持 HGE 格式。
Load a particle resource.
  • def_file specifies path of definition file.
  • img_name specifies name of image resource.
  • a, b, rect specifies parameters of the collision box.
Supports HGE format.

Parameters参数パラメータ

namestring
def_filestring
img_namestring
anumber [optional]
bnumber [optional]
rectboolean [optional]
LoadFont(name, def_file, bind_tex [optional], mipmap)

[P] [X] [static]

Load a texture font resource.
  • def_file specifies path of definition file.
  • (P) bind_tex specifies texture path, only used by fancy2d format.
Detail
(P) Supports HGE format and fancy2d format.
(X) Supports HGE format.
For HGE format, texture file will be searched at the same directory of def_file.
加载纹理字体资源。
  • def_file 指定定义文件的路径。
  • (P) bind_tex 指定纹理路径,仅用于 fancy2d 格式。
Detail
(P) 支持 HGE 格式和 fancy2d 格式。
(X) 支持 HGE 格式。
对于 HGE 格式,纹理文件将在 def_file 的同级路径查找。
Load a texture font resource.
  • def_file specifies path of definition file.
  • (P) bind_tex specifies texture path, only used by fancy2d format.
Detail
(P) Supports HGE format and fancy2d format.
(X) Supports HGE format.
For HGE format, texture file will be searched at the same directory of def_file.

Parameters参数パラメータ

namestring
def_filestring
bind_tex [optional]string
mipmapboolean [optional] Default is true.
SetFontState(name, blendMode, color)

[P] [X] [static]

(P) Set status of a texture font resource. (X) Set status of a font resource.
(P) 设置纹理字体资源的状态。 (X) 设置字体资源的状态。
(P) Set status of a texture font resource. (X) Set status of a font resource.

Parameters参数パラメータ

namestring
blendModestring
colorlstg::Color [optional]
LoadTTF(name, path, width, height)

[P] [X] [static]

Load a TTF font resource.
  • path specifies path of font file.
  • (P) width, height specifies width and height of font.
  • (X) width specifies size of font.
加载TTF字体资源。
  • path 指定字体文件的路径。
  • (P) width, height 指定字体的宽度和高度。
  • (X) width 指定字体的大小。
Load a TTF font resource.
  • path specifies path of font file.
  • (P) width, height specifies width and height of font.
  • (X) width specifies size of font.

Parameters参数パラメータ

namestring
pathstring
widthnumber
heightnumber
LoadSound(name, path)

[P] [X] [static]

Load a sound resource.
  • (P) Supports WAV and OGG format. WAV format is recommended.
  • (X) Supports WAV, OGG, MP3 and FLAC format. WAV format is recommended.
Detail
Sound resource will be loaded into memory entirely. Please avoid using big audio files.
WAV file of non-standard or compressed format is not supported.
加载音效资源。
  • (P) 支持 WAV 和 OGG 格式。推荐 WAV 格式。
  • (X) 支持 WAV, OGG, MP3 和 FLAC 格式。推荐 WAV 格式。
细节
音效资源将被整体加载进内存。请勿使用较大的音频文件。
不支持非标准的或压缩格式的 WAV 文件。
Load a sound resource.
  • (P) Supports WAV and OGG format. WAV format is recommended.
  • (X) Supports WAV, OGG, MP3 and FLAC format. WAV format is recommended.
Detail
Sound resource will be loaded into memory entirely. Please avoid using big audio files.
WAV file of non-standard or compressed format is not supported.

Parameters参数パラメータ

namestring
pathstring
LoadMusic(name, path, loop_end, loop_duration)

[P] [X] [static]

Load a music resource.
  • loop_end, loop_duration specifies end time and length of repeat section in seconds. The repeat range will be loop_end-loop_duration to loop_end.
  • (P) Supports WAV and OGG format. OGG format is recommended.
  • (X) Supports WAV, OGG, MP3 and FLAC format. OGG format is recommended.
Detail
Music resource will not be loaded into memory entirely.
The repeat function is implemented by decoder so it's completely seamless.
加载音乐资源。
  • loop_end, loop_duration 指定循环节的结束和时长,单位为秒。循环范围为 loop_end-loop_durationloop_end
  • (P) 支持 WAV 和 OGG 格式。推荐 OGG 格式。
  • (X) 支持 WAV, OGG, MP3 和 FLAC 格式。推荐 OGG 格式。
细节
音乐资源不会被整体加载进内存。
循环功能由解码器实现,因此是无缝的。
Load a music resource.
  • loop_end, loop_duration specifies end time and length of repeat section in seconds. The repeat range will be loop_end-loop_duration to loop_end.
  • (P) Supports WAV and OGG format. OGG format is recommended.
  • (X) Supports WAV, OGG, MP3 and FLAC format. OGG format is recommended.
Detail
Music resource will not be loaded into memory entirely.
The repeat function is implemented by decoder so it's completely seamless.

Parameters参数パラメータ

namestring
pathstring
loop_endnumber
loop_durationnumber
LoadFX(name, path)

[P] [static]

Load a shader resource. path specifies path of FX format file.
加载着色器资源。 path 指定 FX 文件的路径。
Load a shader resource. path specifies path of FX format file.

Parameters参数パラメータ

namestring
pathstring
LoadFX(name, fShader, vShader, isString)

[X] [static]

Load a shader resource.
  • fShader specifies path or content of fragment shader. Will be default fragment shader if got nil.
  • vShader specifies path of content of vertex shader. Will be default vertex shader if got nil.
  • isString specifies if fShader and vShader is string content rather than path.
加载着色器资源。
  • fShader 指定像素着色器的路径或内容。传入 nil 时将使用默认像素着色器。
  • vShader 指定顶点着色器的路径或内容。传入 nil 时将使用默认顶点着色器。
  • isString 指定 fShadervShader 是字符串内容还是路径。
Load a shader resource.
  • fShader specifies path or content of fragment shader. Will be default fragment shader if got nil.
  • vShader specifies path of content of vertex shader. Will be default vertex shader if got nil.
  • isString specifies if fShader and vShader is string content rather than path.

Parameters参数パラメータ

namestring
fShaderstring [optional]
vShaderstring [optional]
isStringboolean [optional]
CreateRenderTarget(name)

[P] [X] [static]

Create a render target.
  • (P) Will be treated as a texture resource.
创建渲染目标
  • (P) 将作为纹理资源使用。
Create a render target.
  • (P) Will be treated as a texture resource.

Parameters参数パラメータ

namestring
IsRenderTarget(name)

[P] [X] [static] [deprecated in X]

(P) Check if a texture resource is a render target. (X) Check if a render target resource exists.
(P) 检查纹理资源是否为渲染目标。 (X) 检查渲染目标资源是否存在。
(P) Check if a texture resource is a render target. (X) Check if a render target resource exists.

Parameters参数パラメータ

namestring

Render[edit | edit source]

;
  • The engine uses Cartesian coordinate system as screen coordinate system, which means right and up are positive direction. The original point is the left-bottom of screen.
  • There is a global scale factor for rendering. It will affect some render functions.
  • Z-buffer will not be enabled by default.
  • All render functions must be invoked in RenderFunc (render() callback of game class).
  • A render target cannot be rendered when under using.
  • 引擎使用笛卡尔坐标系作为窗口坐标系,右和上为正方向,原点为屏幕左下角。
  • 引擎提供一个全局渲染缩放系数,会影响一些渲染函数。
  • 引擎默认关闭深度缓冲。
  • 所有渲染函数必须在 RenderFuncrender() 回调)中调用。
  • 渲染目标在使用中不能被渲染。
  • The engine uses Cartesian coordinate system as screen coordinate system, which means right and up are positive direction. The original point is the left-bottom of screen.
  • There is a global scale factor for rendering. It will affect some render functions.
  • Z-buffer will not be enabled by default.
  • All render functions must be invoked in RenderFunc (render() callback of game class).
  • A render target cannot be rendered when under using.
BeginScene()

[P] [X] [static]

Notice engine the beginning of rendering. Must invoked in RenderFunc. All render functions should be invoked between BeginScene and EndScene.
通知引擎渲染开始。必须在 RenderFunc 中调用。 所有渲染函数必须在 BeginSceneEndScene 之间调用。
Notice engine the beginning of rendering. Must invoked in RenderFunc. All render functions should be invoked between BeginScene and EndScene.
EndScene()

[P] [X] [static]

Notice engine the ending of rendering. Must invoked in RenderFunc.
通知引擎渲染结束。必须在 RenderFunc 中调用。
Notice engine the ending of rendering. Must invoked in RenderFunc.
RenderClear(lstg::Color)

[P] [X] [static]

Clear screen with specified color. Will also clear z-buffer if enabled.
使用指定颜色清空屏幕。同时会清除深度缓冲区(若启用)。
Clear screen with specified color. Will also clear z-buffer if enabled.

Parameters参数パラメータ

lstg::Color
SetViewport(left, right, bottom, top)

[P] [X] [static]

Set viewport. Will affect clipping and rendering.
设置视口。将影响裁剪和渲染。
Set viewport. Will affect clipping and rendering.

Parameters参数パラメータ

leftnumber
rightnumber
bottomnumber
topnumber
SetOrtho(left, right, bottom, top)

[P] [X] [static]

Set orthogonal projection.
Detail
(P) Z range will be [0, 1].
(X) Z range will be [-1024, 1024].
设置正交投影。
细节
(P) Z 范围为 [0, 1]。
(X) Z 范围为 [-1024, 1024]。
Set orthogonal projection.
Detail
(P) Z range will be [0, 1].
(X) Z range will be [-1024, 1024].

Parameters参数パラメータ

leftnumber
rightnumber
bottomnumber
topnumber
SetPerspective(eyeX, eyeY, eyeZ, atX, atY, atZ, upX, upY, upZ, fovy, aspect, zn, zf)

[P] [X] [static]

Set perspective projection.
  • (eyeX, eyeY, eyeZ) specifies eye position.
  • (atX, atY, atZ) specifies target position.
  • (upX,upY,upZ) specifies up vector.
  • fovy specifies field of view in radians.
  • aspect specifies aspect ratio.
  • zn, zf specifies z-near and z-far plane.
设置透视投影。
  • (eyeX, eyeY, eyeZ) 指定观察者位置。
  • (atX, atY, atZ) 指定观察目标位置。
  • (upX,upY,upZ) 指定观察者的上方向。
  • fovy 指定视角范围(弧度)
  • aspect 指定宽高比。
  • zn, zf 指定Z轴近平面和远平面。
Set perspective projection.
  • (eyeX, eyeY, eyeZ) specifies eye position.
  • (atX, atY, atZ) specifies target position.
  • (upX,upY,upZ) specifies up vector.
  • fovy specifies field of view in radians.
  • aspect specifies aspect ratio.
  • zn, zf specifies z-near and z-far plane.

Parameters参数パラメータ

eyeX, eyeY, eyeZnumber, number, number
atX, atY, atZnumber, number, number
upX, upY, upZnumber, number, number
fovynumber
aspectnumber
znnumber
zfnumber
Render(image_name, x, y, rot, hscale, vscale, z)

[P] [X] [static]

Render an image resource.
  • (x, y) specifies position of image center.
  • rot specifies rotation in radians. Default is 0.
  • (hscale, vscale) specifies horizontal and verticle scale. Default of hscale is 1. vscale will be same as hscale if only hscale is assigned.
  • z specifies z coordinate. Default is 0.5.
Will be affected by the global scale factor.
渲染图像资源。
  • (x, y) 指定图像中心的位置。
  • rot 指定旋转,单位为弧度。默认为 0
  • (hscale, vscale) 指定水平和垂直方向的缩放。若只指定了 hscalevscale 将与 hscale 相同。
  • z 指定Z坐标。默认为 0.5
受全局缩放系数影响。
Render an image resource.
  • (x, y) specifies position of image center.
  • rot specifies rotation in radians. Default is 0.
  • (hscale, vscale) specifies horizontal and verticle scale. Default of hscale is 1. vscale will be same as hscale if only hscale is assigned.
  • z specifies z coordinate. Default is 0.5.
Will be affected by the global scale factor.

Parameters参数パラメータ

image_namestring
xnumber
ynumber
rotnumber [optional]
hscalenumber [optional]
vscalenumber [optional]
znumber [optional]
RenderRect(image_name, left, right, bottom, top)

[P] [X] [static]

Render an image resource in the specified rectangle. Z coordinate will be 0.5.
将图像资源渲染到指定的矩形。此时Z坐标为 0.5
Render an image resource in the specified rectangle. Z coordinate will be 0.5.

Parameters参数パラメータ

image_namestring
leftnumber
rightnumber
bottomnumber
topnumber
Render4V(image_name, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)

[P] [X] [static]

Render an image resource in specified vertex positions.
将图像资源渲染到指定的顶点位置。
Render an image resource in specified vertex positions.

Parameters参数パラメータ

image_namestring
x1, y1, z1number, number,number
x2, y2, z2number, number,number
x3, y3, z3number, number,number
x4, y4, z4number, number,number
SetFog()

[P] [X] [static]

Clear fog effect.
清除雾效果。
Clear fog effect.
SetFog(near, far, color)

[P] [X] [static]

Set fog effect.
  • If near is -1, EXP1 algorism will be used and far will be density parameter.
  • If near is -2, EXP2 algorism will be used and far will be density parameter.
  • Otherwise, linear algorism will be used and near, far will be range parameter.
设置清除雾效果。
  • near-1,将使用 EXP1 算法且 far 为强度参数。
  • near-2,将使用 EXP2 算法且 far 为强度参数。
  • 否则,将使用线性算法且 near, far 为范围参数。
Set fog effect.
  • If near is -1, EXP1 algorism will be used and far will be density parameter.
  • If near is -2, EXP2 algorism will be used and far will be density parameter.
  • Otherwise, linear algorism will be used and near, far will be range parameter.

Parameters参数パラメータ

nearnumber
farnumber
colorlstg::Color [optional] Default is 0x00FFFFFF.
RenderText(name, text, x, y, scale, align)

[P] [X] [static]

Render a texture font resource.
  • text specifies text to render.
  • (x, y) specifies position.
  • scale specifies scale. Default is 1.
  • align specifies alignment. Default is 5.

Will be affected by the global scale factor.

Detail
Values for align:
LT: 0 / MT: 1 / RT: 2
LM: 4 / MM: 5 / RM: 6
LB: 8 / MB: 9 / RB: 10
  • This function is overwritten in core script and has different parameters.
渲染纹理字体资源。
  • text 指定要渲染的文字。
  • (x, y) 指定位置。
  • scale 指定缩放。默认为 1
  • align 指定对齐模式。默认为 5

受全局缩放系数影响。

细节
align 可取值:
左上: 0 / 中上: 1 / 右上: 2
左中: 4 / 中中: 5 / 右中: 6
左下: 8 / 中下: 9 / 右下: 10
  • 该函数已在核心脚本中被覆盖并具有不同的参数。
Render a texture font resource.
  • text specifies text to render.
  • (x, y) specifies position.
  • scale specifies scale. Default is 1.
  • align specifies alignment. Default is 5.

Will be affected by the global scale factor.

Detail
Values for align:
LT: 0 / MT: 1 / RT: 2
LM: 4 / MM: 5 / RM: 6
LB: 8 / MB: 9 / RB: 10
  • This function is overwritten in core script and has different parameters.

Parameters参数パラメータ

namestring
textstring
xnumber
ynumber
scalenumber [optional]
alignnumber [optional]
RenderTexture(tex_name, blend, vertex1, vertex2, vertex3, vertex4)

[P] [X] [static]

Render a texture resource.
Detail
vertex1-4 specify vertices and should have following fields:
[1] = X coordinate
[2] = Y coordinate
[3] = Z coordinate
[4] = U coordinate (in pixels)
[5] = V coordinate (in pixels)
[6] = color
渲染纹理资源。
细节
vertex1-4 指定各个顶点,需包含以下成员:
[1] = X 坐标
[2] = Y 坐标
[3] = Z 坐标
[4] = U 坐标(像素)
[5] = V 坐标(像素)
[6] = 颜色
Render a texture resource.
Detail
vertex1-4 specify vertices and should have following fields:
[1] = X coordinate
[2] = Y coordinate
[3] = Z coordinate
[4] = U coordinate (in pixels)
[5] = V coordinate (in pixels)
[6] = color

Parameters参数パラメータ

tex_namestring
blendstring
vertex1table
vertex2table
vertex3table
vertex4table
RenderTTF(name, text, left, right, bottom, top, format, color, scale)

[P] [X] [static]

Render a TTF font resource.
  • name specifies name of font resource.
  • text specifies text to render.
  • left, right, bottom, top specifies a box that text will be rendered into.
  • format specifies how text is aligned in the box.
  • color specifies blend color.
  • scale specifies scale. This value will be multiplied by 0.5 in the engine. Default is 1.

(X) Will use values from resource if format and subsequent parameters are omitted.

Will be affected by the global scale factor.

  • This function is overwritten in core script and has different parameters.
渲染TTF字体资源。
  • name 指定字体资源的名称。
  • text 指定要渲染的文本。
  • left, right, bottom, top 指定文本要被渲染到的矩形。
  • format 指定文本如何在矩形内对齐。
  • color 指定混合颜色。
  • scale 指定缩放。该值将在引擎内部乘以0.5。默认为 1

(X) 若省略 format 以及之后的参数,将使用资源的参数。

受全局缩放系数影响。

  • 该函数已在核心脚本中被覆盖并具有不同的参数。
Render a TTF font resource.
  • name specifies name of font resource.
  • text specifies text to render.
  • left, right, bottom, top specifies a box that text will be rendered into.
  • format specifies how text is aligned in the box.
  • color specifies blend color.
  • scale specifies scale. This value will be multiplied by 0.5 in the engine. Default is 1.

(X) Will use values from resource if format and subsequent parameters are omitted.

Will be affected by the global scale factor.

  • This function is overwritten in core script and has different parameters.

Parameters参数パラメータ

namestring
textstring
leftnumber
rightnumber
bottomnumber
topnumber
formatnumber
colorlstg::Color
scalenumber [optional]

Post Effect[edit | edit source]

PushRenderTarget(name)

[P] [X] [static]

Push a render target into render target stack and use it as render output.
Detail
Render targets are managed by a stack so it's possible to use them nestedly.

Usages should satisfy:

PushRenderTarget(name)
...
PopRenderTarget()
将一个渲染目标入栈并作为渲染输出。
细节
渲染目标由一个堆栈进行管理,可以嵌套使用。

使用时需满足:

PushRenderTarget(name)
...
PopRenderTarget()
Push a render target into render target stack and use it as render output.
Detail
Render targets are managed by a stack so it's possible to use them nestedly.

Usages should satisfy:

PushRenderTarget(name)
...
PopRenderTarget()

Parameters参数パラメータ

namestring
PopRenderTarget()

[P] [X] [static]

Pop a render target from render target stack.
将一个渲染目标出栈。
Pop a render target from render target stack.
PostEffect(name, fx_name, blend, args)

[P] [X] [static]

Apply post effect and render result. Values in args will be passed to shader.

blend specifies blend mode used for result rendering.

Detail
(P) Only the first 'technique' will be used in the shader.
(P) Preset values can be get by following annotations:
(X) Preset values can be get by following uniforms:
(P) POSTEFFECTTEXTURE: texture to apply effect (texture2d)
(X) u_texture: texture to apply effect (sampler2D)
VIEWPORT: size of viewport (float4)
SCREENSIZE: size of screen (float4)
应用后处理并将渲染结果。args 中的值将传递给着色器。

blend 指定渲染结果使用的渲染模式。

细节
(P) 只有着色器中的第一个 technique 会被使用。
(P) 预设值可以通过以下 annotations 取得:
(X) 预设值可以通过以下 uniform 取得:
(P) POSTEFFECTTEXTURE: 要应用效果的纹理 (texture2d)
(X) u_texture: 要应用效果的纹理 (sampler2D)
VIEWPORT: 视口大小 (float4)
SCREENSIZE: 屏幕大小 (float4)
Apply post effect and render result. Values in args will be passed to shader.

blend specifies blend mode used for result rendering.

Detail
(P) Only the first 'technique' will be used in the shader.
(P) Preset values can be get by following annotations:
(X) Preset values can be get by following uniforms:
(P) POSTEFFECTTEXTURE: texture to apply effect (texture2d)
(X) u_texture: texture to apply effect (sampler2D)
VIEWPORT: size of viewport (float4)
SCREENSIZE: size of screen (float4)

Parameters参数パラメータ

namestring
fx_namestring
blendstring
argstable [optional]
PostEffectCapture()

[P] [X] [static] [deprecated in X]

A shortcut to begin post effect.

Equivalent to:

PushRenderTarget(InternalRenderTarget)
开始后处理的快捷函数。

等价于:

PushRenderTarget(InternalRenderTarget)
A shortcut to begin post effect.

Equivalent to:

PushRenderTarget(InternalRenderTarget)
PostEffectApply(fx_name, blend, args)

[P] [X] [static] [deprecated in X]

A shortcut to finish post effect. An internal render target is used.

Equivalent to:

PopRenderTarget(InternalRenderTarget)
PostEffect(InternalRenderTarget, fx_name, blend, args)

Usages should satisfy:

PostEffectCapture()
...
PostEffectApply(...)
结束后处理的快捷函数。会使用一个内置的渲染目标。

等价于:

PopRenderTarget(InternalRenderTarget)
PostEffect(InternalRenderTarget, fx_name, blend, args)

使用时需满足:

PostEffectCapture()
...
PostEffectApply(...)
A shortcut to finish post effect. An internal render target is used.

Equivalent to:

PopRenderTarget(InternalRenderTarget)
PostEffect(InternalRenderTarget, fx_name, blend, args)

Usages should satisfy:

PostEffectCapture()
...
PostEffectApply(...)

Parameters参数パラメータ

fx_namestring
blendstring
argstable [optional]

Sound[edit | edit source]

PlaySound(name, vol, pan)

[P] [X] [static]

Play a sound resource.
  • vol specifies volume, the range is [0, 1].
  • pan specifies channel balance, the range is [-1, 1]. Default is 0.
Detail
A sound resource will be interrupted if it's played again.
播放音效资源。
  • vol 指定音量,范围为 [0, 1]。
  • pan 指定通道平衡,范围为 [-1, 1]。 默认为 0
细节
音效资源重复播放时会被中断。
Play a sound resource.
  • vol specifies volume, the range is [0, 1].
  • pan specifies channel balance, the range is [-1, 1]. Default is 0.
Detail
A sound resource will be interrupted if it's played again.

Parameters参数パラメータ

namestring
volnumber
pannumber [optional]
StopSound(name)

[P] [X] [static]

Stop a sound resource.
停止播放音效资源。
Stop a sound resource.

Parameters参数パラメータ

namestring
PauseSound(name)

[P] [X] [static]

Pause a sound resource.
暂停播放音效资源。
Pause a sound resource.

Parameters参数パラメータ

namestring
ResumeSound(name)

[P] [X] [static]

Resume a sound resource.
恢复播放音效资源。
Resume a sound resource.

Parameters参数パラメータ

namestring
GetSoundState(name)

[P] [X] [static]

Returns status of a sound resource. Will return "paused", "playing" or "stopped".
返回音效资源的状态,将返回 "paused", "playing" 或 "stopped"。
Returns status of a sound resource. Will return "paused", "playing" or "stopped".

Parameters参数パラメータ

namestring

Return value返回值戻り値

string
PlayMusic(name, vol, position)

[P] [X] [static]

Play a music resource.
  • vol specifies volume, the range is [0, 1]. Default is 1.
  • position specifies start position in seconds. Default is 0.
播放音乐资源。
  • vol 指定音量,范围为 [0, 1]。默认为 1.
  • position 指定播放的起始位置,单位为秒。默认为 0.
Play a music resource.
  • vol specifies volume, the range is [0, 1]. Default is 1.
  • position specifies start position in seconds. Default is 0.

Parameters参数パラメータ

namestring
volnumber [optional]
positionnumber [optional]
StopMusic(name)

[P] [X] [static]

Stop a music resource. Will set playback position to the beginning.
停止播放音乐资源。会使播放位置回到开头。
Stop a music resource. Will set playback position to the beginning.

Parameters参数パラメータ

namestring
PauseMusic(name)

[P] [X] [static]

Pause a music resource.
暂停播放音乐资源。
Pause a music resource.

Parameters参数パラメータ

namestring
ResumeMusic(name)

[P] [X] [static]

Resume a music resource.
恢复播放音乐资源。
Resume a music resource.

Parameters参数パラメータ

namestring
GetMusicState(name)

[P] [X] [static]

Returns status of a music resource. Will return "paused", "playing" or "stopped".
返回音乐资源的状态,将返回 "paused", "playing" 或 "stopped"。
Returns status of a music resource. Will return "paused", "playing" or "stopped".

Parameters参数パラメータ

namestring

Return value返回值戻り値

string
SetSEVolume(vol)

[P] [X] [static]

Set global volume factor for sound resources. The value will be multiplied to vol parameter of PlaySound. Will not affect playing sounds.
  • (P) vol should in range [0, 1].
设置音效资源的全局音量系数。值会乘到 PlaySoundvol 参数上。不会影响正在播放的音效。
  • (P) vol 范围为 [0, 1]。
Set global volume factor for sound resources. The value will be multiplied to vol parameter of PlaySound. Will not affect playing sounds.
  • (P) vol should in range [0, 1].

Parameters参数パラメータ

volnumber
SetSEVolume(name, vol)

[X] [static]

Set volume of specified sound resource. Will affect playing sounds.
  • vol should in range [0, 1].
设置指定音效资源的音量。会影响正在播放的音效。
  • vol 范围为 [0, 1]。
Set volume of specified sound resource. Will affect playing sounds.
  • vol should in range [0, 1].

Parameters参数パラメータ

namestring
volnumber
SetBGMVolume(vol)

[P] [X] [static]

Set global volume factor for music resources. The value will be multiplied to vol parameter of PlayMusic. Will not affect playing musics.
  • (P) vol should in range [0, 1].
设置音乐资源的全局音量系数。值会乘到 PlayMusicvol 参数上。不会影响正在播放的音乐。
  • (P) vol 范围为 [0, 1]。
Set global volume factor for music resources. The value will be multiplied to vol parameter of PlayMusic. Will not affect playing musics.
  • (P) vol should in range [0, 1].

Parameters参数パラメータ

volnumber
SetBGMVolume(name, vol)

[P] [X] [static]

Set volume of specified music resource. Will affect playing musics.
  • vol should in range [0, 1].
设置指定音乐资源的音量。会影响正在播放的音效。
  • vol 范围为 [0, 1]。
Set volume of specified music resource. Will affect playing musics.
  • vol should in range [0, 1].

Parameters参数パラメータ

namestring
volnumber

Input[edit | edit source]

(P) Gamepad input is mapped to code 0x92 - 0xB1. (X) Gamepad input is mapped dynamically to existing codes.
(P) 手柄输入被映射到 0x92 - 0xB1 的键码。 (X) 手柄输入被动态映射到已有的键码。
(P) Gamepad input is mapped to code 0x92 - 0xB1. (X) Gamepad input is mapped dynamically to existing codes.
GetKeyState(code)

[P] [X] [static]

Check if key corresponding to code is pressed.
Detail
  • (P) code is VK_CODE defined by microsoft.
  • (X) code is EventKeyboard::KeyCode defined by cocos2d-x.
检查 code 对应的按键是否被按下。
细节
  • (P) code 为微软定义的 VK_CODE
  • (X) code 为cocos2d-x定义的 EventKeyboard::KeyCode
Check if key corresponding to code is pressed.
Detail
  • (P) code is VK_CODE defined by microsoft.
  • (X) code is EventKeyboard::KeyCode defined by cocos2d-x.

Parameters参数パラメータ

codenumber

Return value返回值戻り値

boolean
GetLastKey()

[P] [X] [static]

Returns code of last pressed key.
返回上一次按下的按键的键码。
Returns code of last pressed key.

Return value返回值戻り値

number
GetLastChar()

[P] [X] [static] [deprecated in X]

* (P) Returns last input char.
  • (X) Do nothing.
  • (P) 返回上一次输入的字符。
    • (X) 无作用。
  • (P) Returns last input char.
    • (X) Do nothing.

    Return value返回值戻り値

    string
    GetMousePosition()

    [P] [X] [static]

    (P) Get mouse position in pixels starts from the bottom left of the window. (X) Get mouse position in screen coordinates starts from the bottom left of the window.
    (P) 获取鼠标的位置,以窗口左下角为原点,单位为像素。 (X) 获取鼠标在屏幕坐标系的位置,以窗口左下角为原点。
    (P) Get mouse position in pixels starts from the bottom left of the window. (X) Get mouse position in screen coordinates starts from the bottom left of the window.

    Return value返回值戻り値

    number,number
    GetMouseState(button)

    [P] [X] [static]

    Check if mouse button is pressed.
    • button specifies button to check. 0/1/2 correspond to left/middle/right.
    检查鼠标按键是否被按下。
    • button 指定要检查的按键。0/1/2分别对应左/中/右。
    Check if mouse button is pressed.
    • button specifies button to check. 0/1/2 correspond to left/middle/right.

    Parameters参数パラメータ

    buttonnumber

    Return value返回值戻り値

    boolean

    Misc[edit | edit source]

    Snapshot(file_path)

    [P] [X] [static]

    Take a snapshot of screen and save to file_path in PNG format.
    截取屏幕并以PNG格式保存到 file_path
    Take a snapshot of screen and save to file_path in PNG format.

    Parameters参数パラメータ

    file_pathstring
    Execute(path, arguments, directory, wait)

    [P] [static]

    Execute an external program at path. Returns true on success, false on failure.
    执行位于 path 的外部程序。 成功时返回 true,失败时返回 false
    Execute an external program at path. Returns true on success, false on failure.

    Parameters参数パラメータ

    pathstring
    argumentsstring [optional]
    directorystring [optional]
    waitboolean [optional] Default is true.

    Return value返回值戻り値

    boolean

    Math[edit | edit source]

    The following trigonometric functions accept or return degree values.
    以下三角函数均接受或返回角度值。
    The following trigonometric functions accept or return degree values.
    sin(ang)

    [P] [X] [static]

    Parameters参数パラメータ

    ang
    cos(ang)

    [P] [X] [static]

    Parameters参数パラメータ

    ang
    asin(v)

    [P] [X] [static]

    Parameters参数パラメータ

    v
    acos(v)

    [P] [X] [static]

    Parameters参数パラメータ

    v
    tan(ang)

    [P] [X] [static]

    Parameters参数パラメータ

    ang
    atan(v)

    [P] [X] [static]

    Parameters参数パラメータ

    v
    atan2(y, x)

    [P] [X] [static]

    Parameters参数パラメータ

    y
    x

    Class Constructor[edit | edit source]

    Rand()

    [P] [X] [static]

    Create a RNG object.
    创建 RNG 对象。
    Create a RNG object.

    Return value返回值戻り値

    RNG
    Color(argb)

    [P] [X] [static]

    Create a Color object.
    创建 Color 对象。
    Create a Color object.

    Parameters参数パラメータ

    argbnumber

    Return value返回值戻り値

    lstg::Color
    Color(a, r, g, b)

    [P] [X] [static]

    Create a Color object.
    创建 Color 对象。
    Create a Color object.

    Parameters参数パラメータ

    anumber
    rnumber
    gnumber
    bnumber

    Return value返回值戻り値

    lstg::Color
    BentLaserData()

    [P] [X] [static]

    Create a BentLaserData object.
    创建 BentLaserData 对象。
    Create a BentLaserData object.

    Return value返回值戻り値

    BentLaserData

    Debug[edit | edit source]

    ObjTable()

    [P] [X] [static]

    Returns the table where game objects are stored.
    返回所有游戏对象所在的table。
    Returns the table where game objects are stored.

    Return value返回值戻り値

    table

    Global Callback[edit | edit source]

    Following functions should be defined in global space and will be invoked by the engine. They are already defined in the core script.
    以下函数必须定义在脚本的全局范围,并将被引擎调用。这些函数已经在核心脚本中定义。
    Following functions should be defined in global space and will be invoked by the engine. They are already defined in the core script.
    GameInit()

    [P] [X] [static]

    Will be invoked after the initialization of engine finished.
    在引擎初始化结束后调用。
    Will be invoked after the initialization of engine finished.
    FocusLoseFunc()

    [P] [X] [static]

    Will be invoked when the window lose focus.
    在窗口失去焦点时调用。
    Will be invoked when the window lose focus.
    FocusGainFunc()

    [P] [X] [static]

    Will be invoked when the window get focus.
    在窗口获得焦点时调用。
    Will be invoked when the window get focus.
    FrameFunc()

    [P] [X] [static]

    Will be invoked every frame to process all frame logic. Game will exit if it returns true.
    会被每帧调用以处理帧逻辑。 当返回 true 时游戏将退出。
    Will be invoked every frame to process all frame logic. Game will exit if it returns true.

    Return value返回值戻り値

    boolean
    RenderFunc()

    [P] [X] [static]

    Will be invoked every frame to process all render instructions.
    会被每帧调用以处理渲染指令。
    Will be invoked every frame to process all render instructions.

    Color Class[edit | edit source]

    lstg::Color (Color for short) class is used to represent a 32-bit color. The a/r/g/b component represents alpha/red/green/blue value.
    • Color object can be constructed by Color().
    • Components a, r, g, b are in range [0, 255].
    • Components will be clamped to [0, 255] when performing arithmetic operation if not specified.
    • (X) Components can be accessed and assigned by field a, r, g, b.
    • (X) 32-bit value can be accessed and assigned by field argb.
    • (X) Other methods and custom constructor are extended in Lua scripts. Please refer to the document or source code of LuaSTG-x.
    • A Color object is a Lua userdata.
    lstg::Color (简记为Color) 类用于表示32位颜色。a/r/g/b 分量分别表示透明度/红/绿/蓝的值。
    • Color 对象可以通过 Color() 创建。
    • 分量 a, r, g, b 范围为 [0, 255]。
    • 如无特殊说明,在数值计算时分量会被限制在 [0, 255]。
    • (X) 分量可以通过 a, r, g, b 属性读写。
    • (X) 32位值可以通过 argb 属性读写。
    • (X) 在Lua脚本中扩展了其他方法和自定义构造函数。请参考LuaSTG-x的文档或源码。
    • Color 对象是 Lua 中的 userdata
    lstg::Color (Color for short) class is used to represent a 32-bit color. The a/r/g/b component represents alpha/red/green/blue value.
    • Color object can be constructed by Color().
    • Components a, r, g, b are in range [0, 255].
    • Components will be clamped to [0, 255] when performing arithmetic operation if not specified.
    • (X) Components can be accessed and assigned by field a, r, g, b.
    • (X) 32-bit value can be accessed and assigned by field argb.
    • (X) Other methods and custom constructor are extended in Lua scripts. Please refer to the document or source code of LuaSTG-x.
    • A Color object is a Lua userdata.
    ARGB()

    [P] [X]

    Returns a, r, g, b components respectively.
    分别返回 a, r, g, b 分量。
    Returns a, r, g, b components respectively.

    Return value返回值戻り値

    number, number, number, number
    unpack()

    [X]

    Returns r, g, b, a components respectively.
    分别返回 r, g, b, a 分量。
    Returns r, g, b, a components respectively.

    Return value返回值戻り値

    number, number, number, number
    unpackFloat()

    [X]

    Returns r, g, b, a components scaled to [0, 1] respectively.
    分别返回缩放到 [0, 1] 的 r, g, b, a 分量。
    Returns r, g, b, a components scaled to [0, 1] respectively.

    Return value返回值戻り値

    number, number, number, number
    set(R, G, B, A)

    [X]

    Set values of components. Alpha component is optional. Returns self.
    设置分量的值。透明度分量是可选的。返回 self
    Set values of components. Alpha component is optional. Returns self.

    Parameters参数パラメータ

    Rnumber
    Gnumber
    Bnumber
    Anumber [optional]

    Return value返回值戻り値

    Color
    setFloat(R, G, B, A)

    [X]

    Set values of components in range [0, 1]. Alpha component is optional. Returns self.
    以 [0, 1] 范围设置分量的值。透明度分量是可选的。返回 self
    Set values of components in range [0, 1]. Alpha component is optional. Returns self.

    Parameters参数パラメータ

    Rnumber
    Gnumber
    Bnumber
    Anumber [optional]

    Return value返回值戻り値

    Color
    clone()

    [P] [X] [static]

    Returns a clone of the color object.
    返回颜色对象的副本。
    Returns a clone of the color object.

    Return value返回值戻り値

    Color
    (meta)__eq(lhs, rhs)

    [P] [X] [static]

    Returns whether two color values are equal.
    返回两个颜色值是否相等。
    Returns whether two color values are equal.

    Parameters参数パラメータ

    lhsColor
    rhsColor

    Return value返回值戻り値

    boolean
    (meta)__add(lhs, rhs)

    [P] [X] [static]

    Add two color objects component-wise.
    将两个颜色对象逐分量相加。
    Add two color objects component-wise.

    Parameters参数パラメータ

    lhsColor
    rhsColor

    Return value返回值戻り値

    Color
    (meta)__sub(lhs, rhs)

    [P] [X] [static]

    Subtract two color objects component-wise.
    将两个颜色对象逐分量相减。
    Subtract two color objects component-wise.

    Parameters参数パラメータ

    lhsColor
    rhsColor

    Return value返回值戻り値

    Color
    (meta)__mul(lhs, rhs)

    [P] [X] [static]

    When passed with two color objects:
    Multiply two color values component-wise as if components are in range [0, 1].

    When passed with a color object and a number:

    Multiply components with a number.
    当传入两个颜色对象时:
    将两个颜色对象逐分量相乘,分量会被当做 [0, 1] 范围。

    当传入一个颜色对象和一个数值时:

    将分量与数值相乘。
    When passed with two color objects:
    Multiply two color values component-wise as if components are in range [0, 1].

    When passed with a color object and a number:

    Multiply components with a number.

    Parameters参数パラメータ

    lhsColor/number
    rhsColor/number

    Return value返回值戻り値

    Color
    (meta)__tostring(self)

    [P] [X] [static]

    Returns decription of the color objects.
    返回颜色对象的描述。
    Returns decription of the color objects.

    Parameters参数パラメータ

    selfColor

    Return value返回值戻り値

    string

    RNG Class[edit | edit source]

    RNG (random number generator) class is used for generating pseudo random number.
    • RNG object can be constructed by Rend().
    • RNG class uses WELL512 algorithm.
    Default global RNG object is implemented by lstg::Random class in LuaSTG-x and has other extra methods. Please refer to the document or source code of LuaSTG-x.
    RNG(随机数发生器)类用于生成伪随机数。
    • RNG 对象可以通过 Rend() 创建。
    • RNG 类使用 WELL512 算法。
    在LuaSTG-x中,默认的全局 RNG 对象是由 lstg::Random 类实现的且具有更多方法。请参考LuaSTG-x的文档或源码。
    RNG (random number generator) class is used for generating pseudo random number.
    • RNG object can be constructed by Rend().
    • RNG class uses WELL512 algorithm.
    Default global RNG object is implemented by lstg::Random class in LuaSTG-x and has other extra methods. Please refer to the document or source code of LuaSTG-x.
    Seed(seed)

    [P] [X]

    Set seed. seed shoule in range [0, 2^32-1].
    设置随机数种子。seed 范围为 [0, 2^32-1]。
    Set seed. seed shoule in range [0, 2^32-1].

    Parameters参数パラメータ

    seednumber
    GetSeed()

    [P] [X]

    Returns the seed.
    返回随机数种子。
    Returns the seed.

    Return value返回值戻り値

    number
    Int(min, max)

    [P] [X]

    Returns a random integer in range [min, max]. min should not be bigger than max.
    返回 [min, max] 范围的随机整数。min 不应大于 max
    Returns a random integer in range [min, max]. min should not be bigger than max.

    Parameters参数パラメータ

    minnumber
    maxnumber

    Return value返回值戻り値

    number
    Float(min, max)

    [P] [X]

    Returns a random float in range [min, max]. min should not be bigger than max.
    返回 [min, max] 范围的随机浮点数。min 不应大于 max
    Returns a random float in range [min, max]. min should not be bigger than max.

    Parameters参数パラメータ

    minnumber
    maxnumber

    Return value返回值戻り値

    number
    Sign()

    [P] [X]

    Returns 1 or -1 randomly.
    随机返回 1-1
    Returns 1 or -1 randomly.

    Return value返回值戻り値

    number

    BentLaserData Class[edit | edit source]

    BentLaserData class is used to control bent laser (aka curvy laser) function provided by the engine.
    • BentLaserData object can be constructed by BentLaserData().
    BentLaserData is implemented by lstg::GameObjectBentLaser class in LuaSTG-x and has different methods. Please refer to the document or source code of LuaSTG-x.
    BentLaserData 类用于控制引擎提供的曲线激光功能。
    • BentLaserData 对象可以通过 BentLaserData() 创建。
    在LuaSTG-x中,BentLaserDatalstg::GameObjectBentLaser 类实现且具有不同的方法。请参考LuaSTG-x的文档或源码。
    BentLaserData class is used to control bent laser (aka curvy laser) function provided by the engine.
    • BentLaserData object can be constructed by BentLaserData().
    BentLaserData is implemented by lstg::GameObjectBentLaser class in LuaSTG-x and has different methods. Please refer to the document or source code of LuaSTG-x.
    ;Related features
    Bent Laser
    相关功能
    曲线激光
    Related features
    Bent Laser
    Update(obj, length, width)

    [P]

    Add a new node to bent laser. Its position will be (obj.x, obj.y).
    • length specifies the limit of node count.
    • width specifies the width property of node.
    向曲线激光添加一个新节点。节点位置为 (obj.x, obj.y)
    • length 指定节点数量上限。
    • width 指定节点的宽度属性。
    Add a new node to bent laser. Its position will be (obj.x, obj.y).
    • length specifies the limit of node count.
    • width specifies the width property of node.

    Parameters参数パラメータ

    objobject
    lengthnumber
    widthnumber
    Release()

    [P]

    Legacy of old version. Do nothing.
    旧版遗留。无作用。
    Legacy of old version. Do nothing.
    Render(texName, blend, color, texLeft, texTop, texWidth, texHeight, scale)

    [P]

    Render bent laser.
    • texName specifies name of texture resource.
    • blend specifies name of blend mode.
    • color specifies color of all vertices.
    • texLeft, texTop, texWidth, texHeight specifies texture coordinates in range [0, 1].
    • scale specifies the scale apply to each node's width.
    Will be affected by the global scale factor.
    渲染曲线激光。
    • texName 指定纹理资源名称。
    • blend 指定混合模式名称。
    • color 指定所有顶点的颜色。
    • texLeft, texTop, texWidth, texHeight 指定纹理坐标,范围为 [0, 1]。
    • scale 指定每个节点宽度的缩放。
    受全局缩放系数影响。
    Render bent laser.
    • texName specifies name of texture resource.
    • blend specifies name of blend mode.
    • color specifies color of all vertices.
    • texLeft, texTop, texWidth, texHeight specifies texture coordinates in range [0, 1].
    • scale specifies the scale apply to each node's width.
    Will be affected by the global scale factor.

    Parameters参数パラメータ

    texNamestring
    blendstring
    colorlstg::Color
    texLeftnumber
    texTopnumber
    texWidthnumber
    texHeightnumber
    scalenumber
    CollisionCheck(x, y, rot, a, b, rect)

    [P]

    Do collision check with a fake game object as if it has given properties.

    Returns true is there is collision.

    Detail
    Each node will be treated as a circle whose radius is half of the width.
    与给定的游戏对象属性进行碰撞检测。

    若发生碰撞则返回 true

    细节
    每个节点将被当作一个半径为其宽度一半的圆。
    Do collision check with a fake game object as if it has given properties.

    Returns true is there is collision.

    Detail
    Each node will be treated as a circle whose radius is half of the width.

    Parameters参数パラメータ

    xnumber
    ynumber
    rotnumber [optional] Default is 0.
    anumber [optional] Default is 0.
    bnumber [optional] Default is 0.
    rectboolean [optional] Default is false.

    Return value返回值戻り値

    boolean
    BoundCheck()

    [P]

    Check if all nodes' position are in the range set by SetBound().
    检查是否所有节点都在 SetBound() 设置的范围内。
    Check if all nodes' position are in the range set by SetBound().

    Return value返回值戻り値

    boolean