Probems inheriting DirectionalTrigger
by Vishal Bhanderi · in Torque X Platformer Kit · 09/07/2007 (9:45 am) · 7 replies
Guys, for some reason I can't get my Block to work. I've inherited from Directional Trigger but when I come into contact with it, it dosn't seem to call the _onEnter method.
Im I missing some code somewhere ?
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.Util;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;
using GarageGames.Torque.SceneGraph;
using GarageGames.Torque.MathUtil;
using GarageGames.Torque.PlatformerFramework;
namespace GarageGames.Torque.PlatformerDemo
{
[TorqueXmlSchemaType]
public class BlockComponent : DirectionalTriggerComponent
{
//======================================================
#region Public properties, operators, constants, and enums
//public T2DSceneObject SceneObject
public T2DAnimationData TriggeredAnimation
{
get { return _triggeredAnimation; }
set { _triggeredAnimation = value; }
}
#endregion
//======================================================
#region Public methods
public override void CopyTo(TorqueComponent obj)
{
base.CopyTo(obj);
}
#endregion
//======================================================
#region Private, protected, internal methods
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info)
{
base._onEnter(ourObject, theirObject, info);
DragonActorComponent actor = theirObject.Components.FindComponent<DragonActorComponent>();
if (actor == null)
return;
ActorHit(actor);
}
private void ActorHit(ActorComponent actor)
{
T2DAnimatedSprite animSprite = Owner as T2DAnimatedSprite;
if (animSprite != null && !_triggered)
{
animSprite.PlayAnimation(_triggeredAnimation);
}
_triggered = true;
}
protected override bool _OnRegister(TorqueObject owner)
{
if (!base._OnRegister(owner))
return false;
SceneObject.SetObjectType(PlatformerData.BlockObjectType, true);
return true;
}
protected override void _OnUnregister()
{
base._OnUnregister();
}
#endregion
//======================================================
#region Private, protected, internal fields
private T2DAnimationData _triggeredAnimation;
private bool _triggered;
#endregion
}
}Im I missing some code somewhere ?
About the author
#2
I've added this line in the actorComponent
"+ PlatformerData.BlockObjectType;"
and this in the PlatfromerData.
But it still doesn't execute the the _onEnter method. Also where is "Block" used ? Something in TXB ?
EDIT: It works now. Thanks for the help.
09/08/2007 (2:05 am)
Thanks for the info but im still seem to be missing something.I've added this line in the actorComponent
"+ PlatformerData.BlockObjectType;"
and this in the PlatfromerData.
/// <summary>
/// The object type to be used for all blocks.
/// </summary>
static public TorqueObjectType BlockObjectType
{
get
{
if (!_blockObjectType.Valid)
{
TorqueObjectDatabase.Instance.ObjectTypesLocked = false;
_blockObjectType = TorqueObjectDatabase.Instance.GetObjectType("Block");
TorqueObjectDatabase.Instance.ObjectTypesLocked = true;
}
return _blockObjectType;
}
}But it still doesn't execute the the _onEnter method. Also where is "Block" used ? Something in TXB ?
EDIT: It works now. Thanks for the help.
#3
Out of curiosity, was there anything not mentioned that you had to do to get it to work? As far as I know you're the first person to post about using that component for anything other than it's existing uses in the kit. If there are quirks I'd love to hear about them so I know what I'm talking about if it ever comes up again.
09/10/2007 (5:18 am)
Glad to hear it!Out of curiosity, was there anything not mentioned that you had to do to get it to work? As far as I know you're the first person to post about using that component for anything other than it's existing uses in the kit. If there are quirks I'd love to hear about them so I know what I'm talking about if it ever comes up again.
#4
"+ PlatformerData.BlockObjectType;"
needs to be added. Two right under each other.
Now i'm just trying to find out how this animation class works :0
Is there a way to destroy an object once an animation has ended ?
The whole object not just animationComponent
09/10/2007 (1:03 pm)
Nope. That's all the changes required. Note there are two places where the "+ PlatformerData.BlockObjectType;"
needs to be added. Two right under each other.
Now i'm just trying to find out how this animation class works :0
Is there a way to destroy an object once an animation has ended ?
The whole object not just animationComponent
#5
09/11/2007 (7:50 pm)
Yes. You can set the "RemoveOnFinished" property to true. ;P
#7
Hopefully, but i can't seem to get the PlatformSolidComponet/OneWayPlatformComponent to work with my component. I wanted to created a block that behaves the same from above and the sides, but when hit from below i wanted it to blowup and throw out a chilly.
@Thomas,
Thanks for the pointer. RemoveOnFinished is kinda weird though. When I add that to ActorHitMethod and run it, it seems like there is nothing there, until you jump though it. It then runs the animation and then gets destroyed. Don't see how it makes the object vanish. Maybe i'm missing something (Like usual). Try ticking the box 'RemoveonFinish' for the falling platforms and see if you can see them before the animation.
09/12/2007 (2:25 pm)
@Zilla,Hopefully, but i can't seem to get the PlatformSolidComponet/OneWayPlatformComponent to work with my component. I wanted to created a block that behaves the same from above and the sides, but when hit from below i wanted it to blowup and throw out a chilly.
@Thomas,
Thanks for the pointer. RemoveOnFinished is kinda weird though. When I add that to ActorHitMethod and run it, it seems like there is nothing there, until you jump though it. It then runs the animation and then gets destroyed. Don't see how it makes the object vanish. Maybe i'm missing something (Like usual). Try ticking the box 'RemoveonFinish' for the falling platforms and see if you can see them before the animation.
Torque Owner Thomas Buscaglia
In the framework, ActorComponent applies the following object types to its CollidesWith in _OnRegister:
Simply add PlatformerData.BlockObjectType there (or only in the subclass of ActorComponent that you want to be able to interact with the blocks) and you should be made in the shade.