Hello Guest

Author Topic: How to get OgmoData from entities  (Read 3325 times)

0 Members and 1 Guest are viewing this topic.

BMarley

  • Member
  • Posts: 2
    • View Profile
How to get OgmoData from entities
« on: March 03, 2016, 05:38:44 AM »
Hello,

Do you have an example to get OgmoData data from this method?
Here is my code create entities from Ogmo level using reflexion :

Code: [Select]

Class entityStoneLevel1Size1
        Inherits Entity
        Dim id As Integer = 1
        Dim StoneLevel1Size1 As New Image(Globals.GameDir & "data/entities/stones/stonewhite.png")
        Public colliderStoneLevel1Size1 As New BoxCollider(16, 16, CInt(entityPlayer.collisionTags.tStoneslevel1size1))

        Public Sub New(x As Single, y As Single, data As OgmoData)
            MyBase.New(x, y)
            AddGraphic(StoneLevel1Size1)
            AddCollider(colliderStoneLevel1Size1)
            id = data.GetInt("id", 1)
        End Sub

        Public Overrides Sub Render()
            MyBase.Render()
            If Globals.DEBUG Then colliderStoneLevel1Size1.Render()
        End Sub


    End Class

Collisions are managed by Overlap tests on each collision tags like this :

Code: [Select]
   

For Each s In ([Enum].GetValues(GetType(collisionTags)))

                If (Overlap(X, Y , CInt(s))) Then
                    currentCollisions.Add(CInt(s))
                End If

Next s


I wanna retrive OgmoData value when a collision append.
Thanks

TaintedGoat

  • Member
  • Posts: 8
    • View Profile
Re: How to get OgmoData from entities
« Reply #1 on: March 04, 2016, 10:54:07 AM »
Hello BMarley. We dont use this forum a lot lately. But if you want to join a more active place to talk/make questions about otter and gamedev in general. You can join everyone on Slack http://otter2d.com/slack.php
In regards to your question. I guess you can pretty much do anything. You can add the OgmoData as a variable and then check if the collided entity (Using Collide() rather than Overlap(). You can also use Overlapped) is an instance of entityStoneLevel1Size1 so you cast it and can access said variable.
Sorry if it wasnt too helpful. But as i said. You can come join us on Slack where there's more people that can help you.

BMarley

  • Member
  • Posts: 2
    • View Profile
Re: How to get OgmoData from entities
« Reply #2 on: March 08, 2016, 02:16:35 PM »
Each line of your post was really really helpful for me!
I used property for my Ogmo data in my Entity class

Code: [Select]

Private dataOgmo As Integer
Public Property id As Integer
            Get
                Return dataOgmo
            End Get
            Set(ByVal value As Integer)
                dataOgmo = value
            End Set
End Property

And i test Overlap and try to know if the Overllaped entity is an instance of my class, and i cast it

Code: [Select]
      If TypeOf (Overlapped) Is entityStoneLevel1Size1 Then
                        Dim castData = TryCast(Overlapped, entityStoneLevel1Size1)
                        CastedData = castData.id
       End If

Thanks a lot. Next time i will use Slack! I just wanna close the topic her ;)