How to get the action object that is currently running? #1852
-
Hello, The sprite can be running a walking action, a jumping action, an attacking action, etc... In a nutshell all I want is some thing like (and I am making up the name of the method) playerSprite->getCurrentAction(), which would be returning the Action object it self. Or even return the tag of the running action. The only way I can think of it, is to create an int variable in the player class, and have it update every frame as the action changes. For instance, if I press "W", then I set that variable to 0, if I press "Space" for the jump, I set it to 1, etc... that way I am "manually" updating the tag. But it doesn't look clean. thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Multiple actions can run on a target at the exact same time, and each of those actions can be sequenced, being made up of many other actions, so what you are after wouldn't really help you. There are many ways to do what you're trying to achieve, with a few examples below. You can create a sub-class of Sprite, for example You can also create a separate
This also allows you to set the current state inside the action sequence, such as by using the |
Beta Was this translation helpful? Give feedback.
-
Cool. In fact I already had a PlayerStates class doing something similar to what you mention. I didn't know about the Node::setUserObject() though. Thanks, I'll give that a try. |
Beta Was this translation helpful? Give feedback.
Multiple actions can run on a target at the exact same time, and each of those actions can be sequenced, being made up of many other actions, so what you are after wouldn't really help you.
There are many ways to do what you're trying to achieve, with a few examples below.
You can create a sub-class of Sprite, for example
class PlayerSprite public ax::Sprite
, and add the state variables to that, to track what state the player is currently in.You can also create a separate
PlayerState
class, such asclass PlayerState : public ax::Ref
(ensure it inherits fromax::Ref
), and add it as a a user object to the player sprite, viaNode::setUserObject(Ref* userObject)
. You would then just do this: