Game Development Community

Delegates and T2DTriggerComponent

by Tim Newsome-Ward · in Torque X 2D · 10/12/2010 (7:31 pm) · 21 replies

What would be the best way to draw animated sprites/Images to the screen? Kind of like a active HUD, feedback for the player.

I want to be able to add an animation which will fade in out i.e. "Level 1" and some other things such as a checkpoint marker.

Should I do this with a new GUI? Add the separate elements in there and then use the delegate to activate them? For some reason I just can't grasp this lol! Too many late nights me thinks... :-s

I'm thinking this would be a nice tutorial which I will write up.

So far I have this snippet from Aaron from an earlier thred:

[TorqueXmlSchemaType]
public class delegates
    {
        public static T2DTriggerComponentOnEnterDelegate TheOption1
        {
            get { return _theOption1; }
        }
        
        public static void _theOption1(T2DSceneObject ourObject, T2DSceneObject theirObject)
        {
            //place your code here for the action you want to take place.
            //play new music, turn day to night, etc...
        }
        
    }

Thanks
Page «Previous 1 2
#1
10/12/2010 (8:38 pm)
Hey Tim!

While most people would setup a GUI/SceneView Hud.

I'm not one of those people :-) Instead, I would use a component that could be added to items that need displayed. When it comes time to make them appear (via the trigger), just "hit the switch" (in code), and the items get relocated to the current scene view :-) Fade in/out? Just add another option to the component.

Bad News? If your unfamiliar with creating components, it might take some time getting it programmed.

Good News? I already have similar components for my VGUI system ("Visual GUI" will allow people to create menu's via .txscene's and components). :-)

I will need to tweak it a little bit and test it, but will try my best to get it done today. I will post again when they are finished.

Aaron

#2
10/12/2010 (9:00 pm)
Yeah that's my trouble (as you know), I'm not a coder :-(

Oh yeah I remeber you telling me about the VGUI, I'm looking forward to it!

I really like the idea of adding components to the actaul scene objects which need to be diplayed, this will greatly speed up dev time for me!

Cheers!
#3
10/13/2010 (7:09 am)
Well It's complete! I tried to post it, but there is a 1000 word limit, and the component itself goes over that limit :-(

I will post it to TDN tomorrow, getting late :-)
#4
10/13/2010 (10:20 am)
Brilliant! I'll have a look on TDN.

Cheers again Aaron.
#5
10/13/2010 (5:13 pm)
Apparently a college "edUCation" is required for TDN.

Since I cant post it here or there. I will setup a section on my website to share my components.

I need to recover the password to my server first, so it might be a few hours before I get something up and going, but the domain is TopNotched.com, check back later today.
#6
10/13/2010 (5:48 pm)
great,

Keep us posted! :-)
#7
10/13/2010 (8:37 pm)
@Aaron: try adding it to the Resources section of the site http://www.torquepowered.com/community/resources
#8
10/14/2010 (7:32 am)
The site still needs a lot of work, but here it is, I will add some extra verbiage to the pages tomorrow
Torque X 2D Components
#9
10/14/2010 (5:01 pm)
Wow Great Site Aaron. :)
#10
10/14/2010 (5:19 pm)
Thanks John!

The syntax script keeps throwing html into the c# code (uhh ohh). I am going to search for a new script.

Edit: A new syntax script has been installed, and everything appears to be working now. I tested the component code (from the website) and it works now.

Aaron
#12
10/14/2010 (7:29 pm)
I got the ObjectFocus component working and its brilliant, thanks again Aaron!

But I've just thought he-he!

I'm using Farseer physics to handle my collisions. I'm guessing this won't work with the stock T2D collision stuff, as from what Ron said, all the Farseer code overrides the T2D collision code?

So do I need a Farseer collision trigger?
#13
10/14/2010 (10:40 pm)
The T2DTriggerComponent collides with "objects types", just give your player an object type if it doesnt already have one. I use the T2DTriggerComponent in on of my Farseer driven games.

If you would rather setup a Farseer Collision delegate put the follwoing into your delegates file. Pino shared this code with me
private static bool FsTestHandler(Geom geometry1, Geom geometry2, ContactList contactList)

        {
            // place your code to do something here
            return true;

        }

 

        public static CollisionEventHandler FSCollisionHandler

        {
            get

            {
                return _FSCollisionHandler;

            }
        }

        private static CollisionEventHandler _FSCollisionHandler = FsTestHandler;

Let me know if it works, I have to leave for a few hours.
#14
10/15/2010 (7:36 am)
Ok, I added a T2DTriggerComponent to my player, enabled it and I couldn't get the trigger to fire.

I also tried mounting a blank scene object to my player with a T2DTriggerComponent attached. I enabled the trigger. Still nothing.

I then tried implementing the Farseer Collision delegate but I couldn't get it to appear in the builder?

Here's the code:

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 FarseerGames.FarseerPhysics.Collisions;


namespace StarterGame2D
{
    [TorqueXmlSchemaType]
    public class delegates
    {
        private static bool FsTestHandler(Geom geometry1, Geom geometry2, ContactList contactList)
        {
            // place your code to do something here
            return true;

        }



        public static CollisionEventHandler FSCollisionHandler
        {
            get
            {
                return _FSCollisionHandler;

            }
        }

        private static CollisionEventHandler _FSCollisionHandler = FsTestHandler;

    }
}

There's probably something I'm ding wrong here. I added:

using FarseerGames.FarseerPhysics.Collisions;

I'm stumped! Do I need to do anything else to the T2DTriggerComponent I attached to the player bar enable it?
#15
10/16/2010 (3:33 am)
The T2DTriggerComponent event will fire depending on which event you put it in... e.g. OnEnter, OnStay, OnLeave... it will fire when it collides with an object you specify with CollidesWith...
#16
10/16/2010 (8:43 am)
@Josh

Yeah I used the OnEnter event to fire off the deleagte but I don't think I used the CollidesWith, I assumed it would just ire when anything collided with it but thimking about it that is crazy!lol

Thanks I'll give it a try!
#17
10/16/2010 (9:07 am)
EDIT: IGNORE DOUBLE POST
#18
10/16/2010 (9:29 am)
@Josh

Ok I remember actually looking at this before, in the T2DTriggerComponent CollidesWith rollout there is nothing visible. I have given both trigger's scripted names is there anything else?

It would be nice if there were some documentation/tutorial on correctly setting up a trigger. I may do it once I get these working :-)
#19
10/18/2010 (7:26 pm)
If you click on a blank part of your scene and drop down "Scene Data" you can add Object Types. These object types can then be assigned to the objects in your levels under the "Scripting" drop down. Those object types should then show up in your CollidesWith rollout.
#20
10/18/2010 (8:56 pm)
@Josh,

Thank you! I've actually found them now. I thought I'd do a little investigating since I read your last post!

Much thanks though!:-)
Page «Previous 1 2