Games How to get the width and height of an object?

Marc De Loose

Member
Licensed User
Longtime User
I have this and it works but I would like to know how big the objects are. and maybe resize them if needed

Im stuck

my class code. (that works as intended) I just need to know the size
B4X:
Sub Class_Globals
    Public bw As X2BodyWrapper
    Private x2 As X2Utils 'ignore
    Private IDfirstRPMled As Int = 44
    Public myTag As String
    Public Posx As Float
    Public PosY As Float
End Sub

Public Sub Initialize (wrapper As X2BodyWrapper)
    bw = wrapper
    x2 = bw.X2
    bw.DelegateTo = Me
    CreateRPMLED
End Sub


Public Sub Tick (GS As X2GameStep)
    If GS.ShouldDraw Then
        'Log("myTag :" & myTag)
    End If
End Sub

private Sub CreateRPMLED
    Log("myTag :" & myTag)
    Log("x2.ScreenAABB.TopRight.X:" & x2.ScreenAABB.TopRight.X & "  -  " & "x2.ScreenAABB.TopRight.Y:" & x2.ScreenAABB.TopRight.Y)
    Log("x2.ScreenAABB.BottomLeft.X:" & x2.ScreenAABB.BottomLeft.X & "  -  " & "x2.ScreenAABB.BottomLeft.Y:" & x2.ScreenAABB.BottomLeft.Y)
    
    For i = 0 To 14 '14
        Dim template As X2TileObjectTemplate = x2.mGame.TileMap.GetObjectTemplate(x2.mGame.ObjectLayer,bw.Id+i)
        x2.mGame.TileMap.CreateObject(template)
    Next
    
    Dim testbod As X2BodyWrapper = x2.GetBodyWrapperById(bw.Id)
    
    Log("testbod.Body.GravityScale : " & testbod.Body.GravityScale)
    Log("testbod.X2.ScreenAABB.Width : " & testbod.X2.ScreenAABB.Width & "  -  " & "testbod.X2.ScreenAABB.Height : " & testbod.X2.ScreenAABB.Height)
    
End Sub
 

Marc De Loose

Member
Licensed User
Longtime User
This seems to get me be the size in meters.

For i = 0 To 14 '14
Dim template As X2TileObjectTemplate = x2.mGame.TileMap.GetObjectTemplate(x2.mGame.ObjectLayer,bw.Id+i)
x2.mGame.TileMap.CreateObject(template)
Dim size As B2Vec2 = x2.GraphicCache.GetGraphicSizeMeters(bw.GraphicName,0)
Log("size.X : " & size.X & " - " & "size.Y : " & size.Y)
Next

No It would be nice to know how to set the size
 
Top