Hello Guest

Author Topic: How to Register an Entity in Collider.cs?  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

cracylord

  • Member
  • Posts: 3
    • View Profile
How to Register an Entity in Collider.cs?
« on: May 19, 2015, 07:57:54 AM »
Hey it's me again,

when I try to call the GetRect() function from my player class I get an NullReferenceException in Otter.dll and it seems that the Entity in this function
Code: [Select]
//collider.cs

public virtual float Left {
    get { return X + Entity.X - OriginX; }
}
is null.
How can I register an Entity in this class?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: How to Register an Entity in Collider.cs?
« Reply #1 on: May 19, 2015, 09:28:41 PM »
Collider.cs is used as a base class only.  You want to use the classes that extend it, like BoxCollider, GridCollider, CircleCollider, etc.  To add a collider to an entity you can just do something like this:

Code: [Select]
AddCollider(new BoxCollider(50, 50, 0));

cracylord

  • Member
  • Posts: 3
    • View Profile
Re: How to Register an Entity in Collider.cs?
« Reply #2 on: June 02, 2015, 05:35:24 AM »
hmm, ok we changed how we do it and are using OGMO as a tile editor

Code: [Select]
Global.ogmoProj1 = new OgmoProject(Assets.OGMO_PROJECT, Assets.OGMO_IMG);
            Global.ogmoProj1.LoadLevel(Assets.OGMO_MAP, this);
            Global.ogmoProj1.RegisterTag(1, "Walls");
            Global.ogmoProj1.RegisterTag(2, "Chests");
            Global.ogmoProj1.BaseTileDepth = 0;
            Global.ogmoProj1.TileDepthIncrement = 0;
now i have to initialize the collider
Code: [Select]
int[] tags = {1,2};
            Global.col = new GridCollider(736, 480, 32, 32, tags);

how can I change the collider to work with the ogmo Project?

I've got another question: How can I find out which number I have to use in the RegisterTag() function? (sorry if I'm annoying you)

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: How to Register an Entity in Collider.cs?
« Reply #3 on: June 02, 2015, 08:40:27 PM »
You want to make sure you're doing LoadLevel after you've done all your set up methods.  In this case you want to do LoadLevel after you've done your RegisterTag, BaseTileDepth, and TileDepthIncrement calls.  These methods are setting up things in the OgmoProject that will then be used when LoadLevel is called.  If you call LoadLevel first, it will just use all the default parameters.

If you have your tags registered for your grids in Ogmo, you shouldn't have to manually create a grid, as it will be created for you when the LoadLevel function is called.

As for the numbers thing: you choose what tag you want associated with each grid.  You can use Enums or ints I believe, and it's totally up to you what to use.  If you want to just use 1 and 2, that works just fine.  To access the grid you can use GetEntityByLayerName() and use the layer name like "Walls" "Chest" etc.  This will return the Entity with the grid collider, so you can do GetEntityByLayerName("Walls").Collider to access it.