反射函数
就是你可以获取/设置变量的函数
getProperty
getProperty(variable:String, ?allowMaps:Bool = false):Dynamic
这个可以获取已经存在的变量的数值, 你可以使用 "setVar" 或直接local一些变量。
- variable - 你要获取变量的名称。
- allowMaps (可选) - 允许使用map访问,通常为了优化他是禁用的。
举个例子:
- getProperty('dad.scale.x') - 他会返回这个贴图x轴上的大小
- getProperty('singAnimations[0]') - 通常他会返回 "singLEFT".
- getProperty('boyfriend.animOffsets.idle', true) - 他可以返回 "{0, 0}"。
getPropertyFromGroup
getPropertyFromGroup(variable:String, index:Int, property:Dynamic, ?allowMaps:Bool = false):Dynamic
返回FlxTypedGroup/FlxSpriteGroup内变量的属性值。
- variable - 组变量。
- index - 因为他是一个组,所以你得输入索引数。
- property - 你得写这个玩意儿的属性。
- allowMaps (可选) - 允许使用map访问,通常为了优化他是禁用的。
举个例子:
- getPropertyFromGroup('playerStrums', 1, 'animation.curAnim.name') - 他会返回当前玩家按下箭头后角色的动作名称。
- getPropertyFromGroup('unspawnNotes', 0, 'extraData.testVar', true) - 就相当于 unspawnNotes[0].extraData.get('testVar').
getPropertyFromClass
getPropertyFromClass(classVar:String, variable:String, ?allowMaps:Bool = false):Dynamic
这个能获取不同class的变量,也就是说这个游戏里面所有的公共变量都能被获取。
- classVar - 你得写这个class在源码中的路径。
- variable - 你要获取的变量名。
- allowMaps (可选) - 允许使用map访问,通常为了优化他是禁用的。
举个例子:
- getPropertyFromClass('backend.ClientPrefs', 'data.downScroll') - 他会返回Downscroll设置的变量是"true"或者"false".
- getPropertyFromClass('states.PlayState', 'SONG.player1') - 他会返回当前谱子内player1的名称。
setProperty
setProperty(variable:String,
value:Dynamic,
?allowMaps:Bool = false,
?allowInstances:Bool = false):Dynamic
这个函数跟getProperty相反,这个函数是用来设置变量值的,你可以用 "setVar" 或者lua等
来设置变量值。
- variable - 你要设置的变量名。
- value - 你要把他设置成啥。
- allowMaps (可选) - 允许使用map设置,通常为了优化他是禁用的。
- allowInstances (可选) - 允许使用"instanceArg"来设置,默认情况下,为优化而禁用。
举个例子:
- setProperty('boyfriend.stunned', true) - 会让玩家眩晕,大概就是你怎么按都没反应。
- setProperty('singAnimations[3]', 'singLEFT') - 让玩家按下右键后播放"singLEFT"动作。
- setProperty('boyfriend.animOffsets.idle', {-200, 100}, true) - 更改角色的偏移。
setPropertyFromGroup
setPropertyFromGroup(variable:String,
index:Int,
property:Dynamic,
value:Dynamic,
?allowMaps:Bool = false,
?allowInstances:Bool = false):Dynamic
跟getPropertyFromGroup相反,用来设置组变量。
- variable - 组变量。
- index - 索引数。
- property - 这个组里成员的属性。
- value - 你想把他设置成啥。
- allowMaps (可选) - 允许使用map设置,通常为了优化他是禁用的。
- allowInstances (可选) - 允许使用"instanceArg" 设置,通常为了优化他是禁用的。
举个例子:
- setPropertyFromGroup('playerStrums', 2, 'visible', false) - 隐藏玩家的上键
- setPropertyFromGroup('unspawnNotes', 0, 'extraData.testVar', true, true) - 相当于unspawnNotes[0].extraData.set('testVar', true).
setPropertyFromClass
setPropertyFromClass(classVar:String,
variable:String,
value:Dynamic,
?allowMaps:Bool = false,
?allowInstances:Bool = false):Dynamic
可以设置在别的class的变量值。
他会返回"value"的值。
- classVar - 这个class在源码里的路径。
- variable - 变量名。
- value - 你想把他设置成啥。
- allowMaps (可选) - 允许使用map设置,通常为了优化他是禁用的。
- allowInstances (可选) - 允许使用"instanceArg" 来设置,通常为了优化他是被禁用的。
举个例子:
- setPropertyFromClass('states.PlayState', 'SONG.player1', 'pico-playable') - 将play1的角色换成"pico-playable".
callMethod
callMethod(funcToRun:String, ?args:Array<Dynamic> = null):Dynamic
调用函数并返回其值。
- funcToRun - 你想运行的函数名称。
- args (可选) - 可选传入的参数。
举个例子:
- callMethod('KillNotes') - 清除所有箭头。
- callMethod('boyfriend.isAnimationNull') - 如果玩家的动画为空,则返回“true”或“false”。
- callMethod('iconP1.changeIcon', {'bf-old'}) - 把玩家的小图标改成"bf-old".
callMethodFromClass
callMethodFromClass(classVar:String, funcToRun:String, ?args:Array<Dynamic> = null):Dynamic
调用Class内的函数并返回其值。
- classVar - 基于源文件夹结构的class变量。
- funcToRun - 你想要运行的函数的名称。
- args (可选) - 可选传入的参数。
举个例子:
- callMethodFromClass('backend.CoolUtil', 'browserLoad', {'https://ko-fi.com/shadowmario'}) - 在浏览器中打开shadowmario的 Ko-Fi 页面,给shadowmario钱。
instanceArg
instanceArg(instanceName:String, ?classVar:String = null):String
"callMethod", "callMethodFromClass", "createInstance", "setProperty", "setPropertyFromGroup", "setPropertyFromClass" 和 "setVar"一起使用。.
以特定方式转化字符串,以告知前面提到的函数该字符串是一个实例。
- instanceName - 实例名称
- classVar (可选) - 基于源文件夹结构的class变量。
举个例子:
- callMethod('spawnNoteSplashOnNote', {instanceArg('notes.members[0]')}) - 将在屏幕上的第一个箭头中产生一个箭头飞溅。
- setVar('leftStrum', instanceArg('playerStrums.members[0]')) - 创建一个到玩家左音符的快捷方式。
createInstance
createInstance(variableToSave:String, classVar:String, ?args:Array<Dynamic> = null):Bool
创建类的实例并将其保存到 lua 变量名称标签,以便您对其使用setPropertysetProperty 和其他函数。
如果创建成功,则返回“true”或“false”。
- variableToSave - 用于保存创建的实例的变量名称。
- classVar - 基于源文件夹结构的class变量。
- args (可选) - 可选传入参数。
举个例子:
- createInstance('testIcon', 'objects.HealthIcon', {'gf'}) - 创建一个 GF图标。
注意:大多数情况下您仍然必须使用"addInstance"添加创建的实例。
addInstance
addInstance(objectName:String, ?inFront:Bool = false):Void
将实例添加到场景中。
- objectName - 实例的变量名称。
- inFront (可选) - 如果为 true,实例将被添加到其相机中所有对象的顶部;如果为 false,实例将被添加到所有角色的后面。
举个例子:
- addInstance('testIcon', true) - 在所有内容顶部添加一个标签为“testIcon”的实例。
注意:从 1.0 开始,此功能是多余的,因为它的功能与"addLuaSprite"几乎相同。
getObjectOrder
getObjectOrder(tag:String, ?group:String = null):Int
返回场景中或组中精灵的对象层。
如果找不到对象或组,则抛出错误并返回 -1。
- tag - 实例或 Lua 对象名称标签的变量名称。
- group (Optional) - FlxTypedGroup/FlxSpriteGroup/Array 的变量名称。
举个例子:
- getObjectOrder('boyfriendGroup') - 返回玩家角色组的对象层。
- getObjectOrder('scoreTxt', 'uiGroup') - 返回其组中分数文本的对象层。
setObjectOrder
setObjectOrder(tag:String, position:Int, ?group:String = null):Void
设置场景中或组内的对象层。
- tag - 实例或 Lua 对象名称标签的变量名称。
- position - 场景/组中的新位置。
- group (可选) - FlxTypedGroup/FlxSpriteGroup/Array 的变量名称。
举个例子:
- setObjectOrder('boyfriendGroup', getObjectOrder('gfGroup')) - 将玩家角色组设置为gf后面的一层。
- setObjectOrder('iconP1', 0, 'uiGroup') - 使玩家器图标成为所有其他图标后面的一层。
addToGroup
addToGroup(group:String, tag:String, ?index:Int = -1):Void
将对象添加到组。
- group - FlxTypedGroup/FlxSpriteGroup/Array 的变量名称。
- tag - 实例或 Lua 对象名称标签的变量名称。
- index (可选) - 组中的位置,-1 为顶部,默认为 -1
举个例子:
- addToGroup('uiGroup', 'mySprite') - 将 Lua 对象“mySprite”添加到 UI Group 的顶部。
- addToGroup('uiGroup', 'mySprite', 0) - 将 Lua 对象“mySprite”添加到 UI Group 的底部。
removeFromGroup
removeFromGroup(group:String,
?index:Int = -1,
?tag:String = null,
?destroy:Bool = true):Void
将对象添加到组。
- group - FlxTypedGroup/FlxSpriteGroup/Array 的变量名称。
- index (可选) - 组中的位置,如果“tag”不为空则忽略,默认为 -1。
- tag (可选) - 实例或 Lua 对象名称标签的变量名称。
- destroy (可选) - 如果启用,则一旦删除就从内存中清除对象,除非你知道自己在做什么,否则不要禁用。
举个例子:
- removeFromGroup('groupName', _, 'mySprite') - 从 UI 组中删除名为“mySprite”的对象。
- removeFromGroup('groupName', 0) - 删除 UI 组底部的对象。
setObjectCamera
setObjectCamera(tag:String,
?camera:String = 'game'):Bool
改变对象的绘制相机。
返回操作是否成功。
- tag - 实例或 Lua 对象名称标签的变量名称。
- camera (Optional) - 可以是 "game", "hud"或"other", 默认为"game".
举个例子:
- setObjectCamera('mySprite', 'hud') - 将名为“mySprite”的对象移动到 HUD 相机上。
setScrollFactor(tag:String,
scrollX:Float,
scrollY:Float):Void
Changes the parallax of an Object.
- tag - Variable name of the instance or Lua Object nametag.
- scrollX - 1 = Normal parallax.
- scrollY - 1 = Normal parallax.
Examples:
- setScrollFactor('mySprite', 0, 0) - Object will look like it's immobile/never gets displaced.
screenCenter
screenCenter(tag:String,
?axis:String = 'xy'):Void
Centers an Object to the Screen on the specified axis.
- tag - Variable name of the instance or Lua Object nametag.
- axis (Optional) - can be "X", "Y" or "XY", defaults to "XY".
Examples:
- screenCenter('mySprite', 'x') - Objects gets only centered horizontally.
- screenCenter('mySprite', 'y') - Objects gets only centered vertically.
- screenCenter('mySprite', 'xy') - Objects gets centered on both axis.
scaleObject
scaleObject(tag:String,
x:Float,
y:Float,
?updateHitbox:Bool = true):Void
Scales an Object by a ratio.
- tag - Variable name of the instance or Lua Object nametag.
- x - Scale ratio X.
- y - Scale ratio Y.
- updateHitbox (Optional) - Updates Hitbox after scaling.
Examples:
- scaleObject('mySprite', 1.5, 2) - Object gets stretched 1.5x larger horizontally and 2x larger vertically.
setGraphicSize
setGraphicSize(tag:String,
x:Float,
?y:Float = 0,
?updateHitbox:Bool = true):Void
Scales an Object by a ratio.
- tag - Variable name of the instance or Lua Object nametag.
- x - Width in pixels.
- y (Optional) - Height in pixels, set to 0 to keep its size constraint to the Width. Defaults to 0.
- updateHitbox (Optional) - Updates Hitbox after scaling.
Examples:
- setGraphicSize('mySprite', 300, 300) - Object will be 300 pixels wide and 300 pixels tall.
- setGraphicSize('mySprite', 500) - Object will be 500 pixels wide, height will be scaled keeping its size constraint.
updateHitbox
updateHitbox(tag:String):Void
Updates the Width/Height hitboxes and the Offset of an Object, used after scaling operations.
- tag - Variable name of the instance or Lua Object nametag.
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.
- tag - Variable name of the instance or Lua Object nametag.
- blend - Blend mode name, leave empty for using the default blend mode.
Examples:
- setBlendMode('mySprite', 'add') - Changes Blend Mode to "ADD".
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.
- tag - Variable name of the instance or Lua Object nametag.
getMidpointY
getMidpointY(tag:String):Float
Returns the Y of the center point of an Object.
- tag - Variable name of the instance or Lua Object nametag.
getGraphicMidpointX
getGraphicMidpointX(tag:String):Float
Returns the Object's Graphic center X.
- tag - Variable name of the instance or Lua Object nametag.
getGraphicMidpointY
getGraphicMidpointY(tag:String):Float
Returns the Object's Graphic center Y.
- tag - Variable name of the instance or Lua Object nametag.
getScreenPositionX
getScreenPositionX(tag:String, ?camera:String = 'game'):Float
Returns the Object's On-Camera X Position.
- tag - Variable name of the instance or Lua Object nametag.
- camera (Optional) - Can be "game", "hud" or "other", defaults to "game".
Examples:
- getScreenPositionX('mySprite') - Object position on Game Camera.
- getScreenPositionX('mySprite', 'hud') - Object position on HUD Camera.
getScreenPositionY
getScreenPositionY(tag:String, ?camera:String = 'game'):Float
Returns the Object's On-Camera Y Position.
- tag - Variable name of the instance or Lua Object nametag.
- camera (Optional) - Can be "game", "hud" or "other", defaults to "game".
Examples:
- getScreenPositionY('mySprite') - Object position on Game Camera.
- getScreenPositionY('mySprite', 'hud') - Object position on HUD Camera.
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.
- tag - Variable name of the instance or Lua Object nametag.
- x - Pixel X of the Graphic.
- y - Pixel Y of the Graphic.
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.
- obj1 - Variable name of the instance or Lua Object nametag of the first object.
- obj2 - Variable name of the instance or Lua Object nametag of the second object.
Examples:
- objectsOverlap('mySprite1', 'mySprite2') - Checks if two Lua Sprites are colliding against each other's hitboxes.