Psych Engine Logo
Psych Engine - Lua Script API

反射函数

就是你可以获取/设置变量的函数


getProperty

getProperty(variable:String, ?allowMaps:Bool = false):Dynamic

这个可以获取已经存在的变量的数值, 你可以使用 "setVar" 或直接local一些变量。

举个例子:


getPropertyFromGroup

getPropertyFromGroup(variable:String, index:Int, property:Dynamic, ?allowMaps:Bool = false):Dynamic

返回FlxTypedGroup/FlxSpriteGroup内变量的属性值。

举个例子:


getPropertyFromClass

getPropertyFromClass(classVar:String, variable:String, ?allowMaps:Bool = false):Dynamic

这个能获取不同class的变量,也就是说这个游戏里面所有的公共变量都能被获取。

举个例子:


setProperty

setProperty(variable:String, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

这个函数跟getProperty相反,这个函数是用来设置变量值的,你可以用 "setVar" 或者lua等
来设置变量值。

举个例子:


setPropertyFromGroup

setPropertyFromGroup(variable:String, index:Int, property:Dynamic, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

跟getPropertyFromGroup相反,用来设置组变量。

举个例子:


setPropertyFromClass

setPropertyFromClass(classVar:String, variable:String, value:Dynamic, ?allowMaps:Bool = false, ?allowInstances:Bool = false):Dynamic

可以设置在别的class的变量值。
他会返回"value"的值。

举个例子:


callMethod

callMethod(funcToRun:String, ?args:Array<Dynamic> = null):Dynamic

调用函数并返回其值。

举个例子:


callMethodFromClass

callMethodFromClass(classVar:String, funcToRun:String, ?args:Array<Dynamic> = null):Dynamic

调用Class内的函数并返回其值。

举个例子:


instanceArg

instanceArg(instanceName:String, ?classVar:String = null):String

"callMethod", "callMethodFromClass", "createInstance", "setProperty", "setPropertyFromGroup", "setPropertyFromClass""setVar"一起使用。.
以特定方式转化字符串,以告知前面提到的函数该字符串是一个实例。

举个例子:


createInstance

createInstance(variableToSave:String, classVar:String, ?args:Array<Dynamic> = null):Bool

创建类的实例并将其保存到 lua 变量名称标签,以便您对其使用setPropertysetProperty 和其他函数。
如果创建成功,则返回“true”或“false”。

举个例子:

注意:大多数情况下您仍然必须使用"addInstance"添加创建的实例。


addInstance

addInstance(objectName:String, ?inFront:Bool = false):Void

将实例添加到场景中。

举个例子:

注意:从 1.0 开始,此功能是多余的,因为它的功能与"addLuaSprite"几乎相同。


getObjectOrder

getObjectOrder(tag:String, ?group:String = null):Int

返回场景中或组中精灵的对象层。
如果找不到对象或组,则抛出错误并返回 -1。

举个例子:


setObjectOrder

setObjectOrder(tag:String, position:Int, ?group:String = null):Void

设置场景中或组内的对象层。

举个例子:


addToGroup

addToGroup(group:String, tag:String, ?index:Int = -1):Void

将对象添加到组。

举个例子:


removeFromGroup

removeFromGroup(group:String, ?index:Int = -1, ?tag:String = null, ?destroy:Bool = true):Void

将对象添加到组。

举个例子:


setObjectCamera

setObjectCamera(tag:String, ?camera:String = 'game'):Bool

改变对象的绘制相机。
返回操作是否成功。

举个例子:


setScrollFactor

setScrollFactor(tag:String, scrollX:Float, scrollY:Float):Void

Changes the parallax of an Object.

Examples:


screenCenter

screenCenter(tag:String, ?axis:String = 'xy'):Void

Centers an Object to the Screen on the specified axis.

Examples:


scaleObject

scaleObject(tag:String, x:Float, y:Float, ?updateHitbox:Bool = true):Void

Scales an Object by a ratio.

Examples:


setGraphicSize

setGraphicSize(tag:String, x:Float, ?y:Float = 0, ?updateHitbox:Bool = true):Void

Scales an Object by a ratio.

Examples:


updateHitbox

updateHitbox(tag:String):Void

Updates the Width/Height hitboxes and the Offset of an Object, used after scaling operations.


setBlendMode

setBlendMode(tag:String, ?blend:String = ''):Bool

Changes the Blend Mode of an object, similarly to Photoshop and other image editors.
Returns if the operation was successful.

Examples:

Note: Some blend modes like "OVERLAY" just seem to not work at all, this is not my fault!


getMidpointX

getMidpointX(tag:String):Float

Returns the X of the center point of an Object.


getMidpointY

getMidpointY(tag:String):Float

Returns the Y of the center point of an Object.


getGraphicMidpointX

getGraphicMidpointX(tag:String):Float

Returns the Object's Graphic center X.


getGraphicMidpointY

getGraphicMidpointY(tag:String):Float

Returns the Object's Graphic center Y.


getScreenPositionX

getScreenPositionX(tag:String, ?camera:String = 'game'):Float

Returns the Object's On-Camera X Position.

Examples:


getScreenPositionY

getScreenPositionY(tag:String, ?camera:String = 'game'):Float

Returns the Object's On-Camera Y Position.

Examples:


getPixelColor

getPixelColor(tag:String, x:Int, y:Int):Int

Gets the color of a pixel in a Sprite's Graphic.
Returns the color's integer value, if invalid, it returns black.

Note: Sprites will require to have their GPU Caching turned off for it to work.


objectsOverlap

objectsOverlap(obj1:String, obj2:String):Bool

Returns if two Object hitboxes are overlapping each other, useful for collision checking.

Examples: