Trigger Region
by Rich Wilson · in Torque X 2D · 01/24/2007 (11:33 am) · 30 replies
What's the best way to make a trigger region that I can detect player collision with? I'm trying to make doors between rooms and I want to load a new level as soon as the player enters a rectangular area.
About the author
#22
01/31/2007 (5:24 pm)
Ok, so you should be using _InitComponent. If that method is not being called then you are not attaching the component to a scene object that is being registered to the scene (assuming the _InitComponent is declared and overriding correctly). This is where you should start your investigation.
#23
This is the code I'm using:
protected override bool _InitComponent(TorqueObject owner)
{
OnEnter = EnterCallback;
return true;
}
I removed the if statement just to see if the method was firing at all. My breakpoint is on the assigment statement.
The definition has the prototype listed as:
protected internal override bool _InitComponent(TorqueObject owner);
I feel like I'm beating my head against a wall while forcing others to watch.
02/01/2007 (8:25 am)
Just for testing purposes, I tried attaching the triggerComponent to my sprite object that's palyer controlled. No response from InitComponent there either. I haven't gotten any error about the method being incorrectly overridden or anything.This is the code I'm using:
protected override bool _InitComponent(TorqueObject owner)
{
OnEnter = EnterCallback;
return true;
}
I removed the if statement just to see if the method was firing at all. My breakpoint is on the assigment statement.
The definition has the prototype listed as:
protected internal override bool _InitComponent(TorqueObject owner);
I feel like I'm beating my head against a wall while forcing others to watch.
#24
02/01/2007 (9:05 am)
Rich, if your components are not being registered to your objects that is the problem you need to solve first. I would suggest breaking into the debugger while the game is running and then looking at the Components field in your scene object. This can tell you which component types have been instantiated for that object. If you're not seeing a trigger component there, that narrows it down.
#25
When I crack open my sprite object that I also attached the trigger component to, all I find are the 4 other components I've tied to it. No trigger component is to be found.
02/01/2007 (10:35 am)
For starters, my _items array in my sceneloader level data only lists a tilemap, my player controlled sprite object and 2 physics materials. The scene object I placed is nowhere to be found. When I crack open my sprite object that I also attached the trigger component to, all I find are the 4 other components I've tied to it. No trigger component is to be found.
#26
02/01/2007 (11:03 am)
I'm not sure I'm following what you're talking about between your scene object vs. your sprite, but not having your components attached to your sprite is definitely a problem, so let's keep going with that. You're trying to attach your component to your sprite in TGBX, right? The next thing I would do is check the level .xml file to see if your component is mentioned in there, that can tell us whether TorqueX ever has a chance to do anything with it, or if it's getting lost between TGBX and your level.
#27
Both the t2dSceneObject and the t2dStaticSprite have the LevelTriggerComponent attached in the level XML file.
Another minor development.
I realized that in my component spec ed.cs file I had my LevelTrigger component in the GarageGames.Torque.T2D namespace. I changed it as such:
$LevelTriggerComponent = TorqueX::RegisterComponent( "LevelTriggerComponent", "StarterGame" );
After changing this to "StarterGame", I get a string parsing error on the sceneLoader.
"Input string was not in a correct format."
If I remove the component from my sprite object, the error goes away. I still have one on the generic SceneObject however, and it doesn't throw an error. Of course, the sceneloader debug shows that that object isn't even getting loaded, so that might be why it isn't choking.
02/01/2007 (11:10 am)
I have 2 objects I'm testing the trigger component out on. One is a generic scene object I dragged off of the create panel in the tool. It was just a boudning rectangle with no components. The other is a sprite object I had tied player control to. I was trying to have the sprite enter the scene object rectangle and trigger the custom OnEnter method from there. I just added the component to the sprite to see if the problem was in the sceneObject, just trying to see if the Init would call.Both the t2dSceneObject and the t2dStaticSprite have the LevelTriggerComponent attached in the level XML file.
Another minor development.
I realized that in my component spec ed.cs file I had my LevelTrigger component in the GarageGames.Torque.T2D namespace. I changed it as such:
$LevelTriggerComponent = TorqueX::RegisterComponent( "LevelTriggerComponent", "StarterGame" );
After changing this to "StarterGame", I get a string parsing error on the sceneLoader.
"Input string was not in a correct format."
If I remove the component from my sprite object, the error goes away. I still have one on the generic SceneObject however, and it doesn't throw an error. Of course, the sceneloader debug shows that that object isn't even getting loaded, so that might be why it isn't choking.
#28
When I tried to add a component to a T2DSceneObject it didn't seem to work for me, either. Not sure exactly what's going on there yet.
Also, this doesn't exactly help you right now, but in later versions of TorqueX the integration between TorqueX and TGBX works much better, you won't have to jump through all these hoops.
02/01/2007 (12:30 pm)
Do you also have the addfield calls from Jonathon's post in your componentSpec.ed.cs file? When I have them I get a parsing error, too, but when I comment them out of my componentSpec.ed.cs I make more progress.When I tried to add a component to a T2DSceneObject it didn't seem to work for me, either. Not sure exactly what's going on there yet.
Also, this doesn't exactly help you right now, but in later versions of TorqueX the integration between TorqueX and TGBX works much better, you won't have to jump through all these hoops.
#29
and to and it looks like the object gets instantiated in the level.
02/01/2007 (12:56 pm)
It looks like your problem with t2dSceneObjects may be a bug in the open beta version of TGBX, or maybe in the XML deserializer. If you go in to your level file and manually change
#30
Ok, I removed all of the addfield calls, fixed the T2D manually in my level XML and tried it out. I got a hit on my breakpoint in OnEnter, but it was for the tileLayer I was using for a floor in the level. Even when I moved the SceneObject away from the TileLayer it kept registering an OnEnter event with that object.
Sooo I re-added the CollidesWith addfield line for my TriggerComponent in the ed.cs file and chose PlayerType for the CollidesWith field of the trigger in the editor, also adding that value to the type field in the scripting rollout of the sprite object I'm using as a surrogate player character.
It worked. So now it's a matter of cleanup, figururing out what's broken where I suppose. Is there a bug database somewhere?
02/02/2007 (12:17 pm)
Huzzah!Ok, I removed all of the addfield calls, fixed the T2D manually in my level XML and tried it out. I got a hit on my breakpoint in OnEnter, but it was for the tileLayer I was using for a floor in the level. Even when I moved the SceneObject away from the TileLayer it kept registering an OnEnter event with that object.
Sooo I re-added the CollidesWith addfield line for my TriggerComponent in the ed.cs file and chose PlayerType for the CollidesWith field of the trigger in the editor, also adding that value to the type field in the scripting rollout of the sprite object I'm using as a surrogate player character.
It worked. So now it's a matter of cleanup, figururing out what's broken where I suppose. Is there a bug database somewhere?
Torque Owner Rich Wilson
I tried the type specification thing too, without much luck.
The error I'm getting is "no suitable method found to override"
I also couldn't find any reference to an OnRegister method in the API help files.