diff options
author | Mateo de Mayo <mateodemayo@gmail.com> | 2015-08-04 00:47:46 +0300 |
---|---|---|
committer | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-08-04 01:10:33 +0300 |
commit | 23f54076db6d241af2a8f9404ab5f5b8072a4db0 (patch) | |
tree | c13d269da7a6414e0d121f1254afcf16b8541864 /source/gameengine/Ketsji/KX_GameObject.cpp | |
parent | 73522e1157eba1f475454c153f7c027f5dd097ea (diff) |
BGE: Added getActionName() function to KX_GameObject()
It works similar to getActionFrame(), you have to give a layer or not (for layer 0) as the argument and it returns the name of the animation that the object is currently playing.
Example:
```
import bge
own = bge.logic.getCurrentController().owner
own.playAction("SomeAction",0,20)
print(own.getActionName())
```
>> SomeAction
Here is an example file, just open the blend file with the terminal opened
and press P, you can see how the current animation is being printed:
{F217484}
Reviewers: moguri, hg1, panzergame, campbellbarton
Reviewed By: panzergame
Subscribers: campbellbarton, hg1, #game_engine
Projects: #game_engine
Differential Revision: https://developer.blender.org/D1443
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 536670dde1a..651df9aebbe 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -494,6 +494,11 @@ float KX_GameObject::GetActionFrame(short layer) return GetActionManager()->GetActionFrame(layer); } +const char *KX_GameObject::GetActionName(short layer) +{ + return GetActionManager()->GetActionName(layer); +} + void KX_GameObject::SetActionFrame(short layer, float frame) { GetActionManager()->SetActionFrame(layer, frame); @@ -1957,6 +1962,7 @@ PyMethodDef KX_GameObject::Methods[] = { KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction), KX_PYMETHODTABLE(KX_GameObject, stopAction), KX_PYMETHODTABLE(KX_GameObject, getActionFrame), + KX_PYMETHODTABLE(KX_GameObject, getActionName), KX_PYMETHODTABLE(KX_GameObject, setActionFrame), KX_PYMETHODTABLE(KX_GameObject, isPlayingAction), @@ -3921,7 +3927,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, stopAction, "stopAction(layer=0)\n" "Stop playing the action on the given layer\n") { - short layer=0; + short layer = 0; if (!PyArg_ParseTuple(args, "|h:stopAction", &layer)) return NULL; @@ -3937,7 +3943,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame, "getActionFrame(layer=0)\n" "Gets the current frame of the action playing in the supplied layer\n") { - short layer=0; + short layer = 0; if (!PyArg_ParseTuple(args, "|h:getActionFrame", &layer)) return NULL; @@ -3947,11 +3953,25 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame, return PyFloat_FromDouble(GetActionFrame(layer)); } +KX_PYMETHODDEF_DOC(KX_GameObject, getActionName, + "getActionName(layer=0)\n" + "Gets the name of the current action playing in the supplied layer\n") +{ + short layer = 0; + + if (!PyArg_ParseTuple(args, "|h:getActionName", &layer)) + return NULL; + + layer_check(layer, "getActionName"); + + return PyUnicode_FromString(GetActionName(layer)); +} + KX_PYMETHODDEF_DOC(KX_GameObject, setActionFrame, "setActionFrame(frame, layer=0)\n" "Set the current frame of the action playing in the supplied layer\n") { - short layer=0; + short layer = 0; float frame; if (!PyArg_ParseTuple(args, "f|h:setActionFrame", &frame, &layer)) @@ -3968,7 +3988,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, isPlayingAction, "isPlayingAction(layer=0)\n" "Checks to see if there is an action playing in the given layer\n") { - short layer=0; + short layer = 0; if (!PyArg_ParseTuple(args, "|h:isPlayingAction", &layer)) return NULL; |