Help adding shooting.
by Michael Hermann · in TGB Platformer Kit · 10/07/2008 (8:14 am) · 4 replies
I tried to get to TGN but it seems to be down. I am trying to add shooting to the Platform tutorial. I have a couple questions.
I added the following code to the ControllerBehavior.cs
// Attack key
if (%keyDown $= "Attack")
//%this.Attack = true;
//added this code to implement a projectile
%this.Owner.ActorBehavior.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = PlayerMissile;
//missileSpeed = %this.missileSpeed;
missileSpeed = 500;
player = %this; //I don't think this is right and don't understand what "player" is.
};
%this.playerMissile.fire();
I then created playermissle.cs. I took this code from the shooter demo.
I understand that that platform demo was already capturing the "x" button key press. SO I thought the first step was to flush out the keydown $= Attack section of code. I am not sure what the keyword "player" is and weather I have declared this, or is it a default keyword.
If anyone can point me in the right direction I would appreciate it.
Thanks
I added the following code to the ControllerBehavior.cs
// Attack key
if (%keyDown $= "Attack")
//%this.Attack = true;
//added this code to implement a projectile
%this.Owner.ActorBehavior.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = PlayerMissile;
//missileSpeed = %this.missileSpeed;
missileSpeed = 500;
player = %this; //I don't think this is right and don't understand what "player" is.
};
%this.playerMissile.fire();
I then created playermissle.cs. I took this code from the shooter demo.
I understand that that platform demo was already capturing the "x" button key press. SO I thought the first step was to flush out the keydown $= Attack section of code. I am not sure what the keyword "player" is and weather I have declared this, or is it a default keyword.
If anyone can point me in the right direction I would appreciate it.
Thanks
#2
The process of shoot is as follows:
1. Button "X" is pressed as defined in ControllerBehavior.cs this binds the X key and calls the Attack function in ActorBehavior.cs
2. The attack function checks the state of the Actor and sets the state of the appropriate animation in ActorBehavior.cs
3. The ActorAnimationBehavior.cs is then called on change of state and the appropriate transition animation is called followed by the appropriate animation. It is also called within each jump? I am a little fuzzy on this logic.
No where am I currently handling the actual creation of a projectile object. I can create a script to handle that, but where would that be called? in the ControllerBehavior.cs?
I realize that these may be basic questions. I have been away from coding for a while and just getting back into the details.
10/07/2008 (9:26 am)
Ok after going through the shoot stuff on TDN I have a few questions or really want to confirm my understanding.The process of shoot is as follows:
1. Button "X" is pressed as defined in ControllerBehavior.cs this binds the X key and calls the Attack function in ActorBehavior.cs
2. The attack function checks the state of the Actor and sets the state of the appropriate animation in ActorBehavior.cs
3. The ActorAnimationBehavior.cs is then called on change of state and the appropriate transition animation is called followed by the appropriate animation. It is also called within each jump? I am a little fuzzy on this logic.
No where am I currently handling the actual creation of a projectile object. I can create a script to handle that, but where would that be called? in the ControllerBehavior.cs?
I realize that these may be basic questions. I have been away from coding for a while and just getting back into the details.
#3
function ActorComponent::attack(%this)
to
function ActorBehavior::attack(%this)
And my error went away and I was able to see the new animation that I added. I am not sure of the difference between the two yet but regardless it fixed my problem. So now on to actually shooting something.
10/07/2008 (11:54 am)
Still need to confirm the above. But found what I think is a typo in the Shooting animation tutorial. I was getting an error in the debugger when trying to press the attack button. and then I changedfunction ActorComponent::attack(%this)
to
function ActorBehavior::attack(%this)
And my error went away and I was able to see the new animation that I added. I am not sure of the difference between the two yet but regardless it fixed my problem. So now on to actually shooting something.
#4
The ActorComponent was some leftover script I was doing for a friend.
10/08/2008 (1:26 pm)
Sorry Michael, that was my bad! Really good pickup too ;)The ActorComponent was some leftover script I was doing for a friend.
Torque Owner Michael Hermann