mail@pastecode.io avatar
7 months ago
2.3 kB
package arm;

class ActionPlayer extends iron.Trait {
	function getAnim() {
		// Trait placed on mesh object
		//anim variable is set to the animation of the object that this script is on
		var anim = object.animation;
		// Trait placed on armature object - retrieve animation from child mesh
		// if the there is no animation (null) get the animation from the child 0 object.
		if (anim == null) anim = object.children[0].animation;
		//returs the anim variables value if the getAnim() function is used like: var anim = getAnim(); below
		return anim;

	//new fuction dono why new
	public function new() {

		//this runs when the object is initialized (game starts)
		notifyOnInit(function() {
			//place the getAnim() return value into the anim variable
			var anim = getAnim();
			//when the marker on the animation is reached execute function
			anim.notifyOnMarker("my_marker", function() {
				//print "Marker!" to the console

		//declare the variable and give it a value. I'm doing this outside the update function so the variable is not redeclared and set over and over the gameloop
		var tooglePlayback = false;
		//this is executed while the game is running
		notifyOnUpdate(function() {
			// variable kb is set to keyboard input
			var kb = iron.system.Input.getKeyboard();

			//place the getAnim() return value into the anim variable
			var anim = getAnim();

			//if 1 key is started play idle animation
			if (kb.started("1")) anim.play("idle");
			//if 2 key is started play run animation
			if (kb.started("2")) anim.play("run");
			//if 3 key is started play slash animation and execute the onSlash function
			if (kb.started("3")) anim.play("slash", onSlash);
			//if space key is started set the tooglePlayback to the opposite of what it is right now
			if (kb.started("space")) {
                tooglePlayback = !tooglePlayback;
			    //if the tooglePlayback is true pause the animation
			    if (tooglePlayback) anim.pause();
			    //if togglePlayback is false resume the animation
			    else anim.resume();

	function onSlash() 
		trace("Slash animation played!");