Games [XUI2D] Tank Example

Discussion in 'Game Development' started by Erel, Aug 27, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User



    A simple example with a tank that moves and shoots.

    The interesting point in this example is the usage of RevoluteJoint to move and control the cannon.
    1. Limits are set to limit the cannon movement.
    2. The joint motor is enabled all the time and we just need to change the target speed to move or hold the cannon:
    Code:
    If UpDown Then
       revjoint.MotorSpeed = 
    1
    Else If DownDown Then
       revjoint.MotorEnabled = 
    True
       revjoint.MotorSpeed = -
    1
    Else
       revjoint.MotorSpeed = 
    0
       Kane.Body.AngularVelocity = 
    0
    End If
    By setting the MotorSpeed to 0 the joint motor prevents the cannon from moving when forces act on the tank.

    Code to fire a cannon ball:
    Code:
    Private Sub Fire
       
    Dim template As X2TileObjectTemplate = TileMap.GetObjectTemplateByName(ObjectLayer, "bullet")
       template.BodyDef.Position = Kane.Body.Position
       
    'set the velocity direction based on the cannon direction.
       template.BodyDef.LinearVelocity = Kane.Body.Transform.MultiplyRot(X2.CreateVec2(300))
       
    'better simulation of fast moving objects
       template.BodyDef.Bullet = True
       TileMap.CreateObject(template)
    End Sub
    To prevent the bullet from hitting the "kane" object the bullet category bits is set to 2 and the kane mask bits are set to 65533 (65535 - 2). Category bits must be a power of 2.


    As usual all the game objects are defined with a tiled map:

    [​IMG]

    If you don't see the custom properties in the Tiled editor then you need to import the custom properties.

    The example is included in the example pack.
    https://www.b4x.com/android/forum/threads/xui2d-example-pack.96454/
     
  2. LucaMs

    LucaMs Expert Licensed User

    ... and hits and what it hits...! :)
     
  3. sorex

    sorex Expert Licensed User

    what is the meaning of this objecttypes.json file?

    was it created with Tiled aswell?

    I see an object editor under view but there I can only load xml files
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It defines the custom properties and their default values.

    You need to import it with: View - Object Types Editor -

    [​IMG]

    It is only required once or after the file is updated.
     
    Last edited: Aug 27, 2018
  5. sorex

    sorex Expert Licensed User

    for some reason it's not working here.

    I need to type in the filename because it will only list xml files but then it gives the error that it doesn't contains object types.

    not really a problem for now as I can see it in the json.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It is important to see the custom types.

    Are you sure that you are doing it in the right place? It can be confusing.
     
  7. sorex

    sorex Expert Licensed User

    I guess it's the right window. And the filename is correct otherwise it gives another error.

    objects.gif
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Are you using Tiled v1.1.6?
     
    ilan likes this.
  9. sorex

    sorex Expert Licensed User

    the help>about gives 0.17.0

    wait a minute copyright date is 2016 altho I downloaded and installed the latest.

    let me verify something
     
  10. sorex

    sorex Expert Licensed User

    sorry about that.

    it appeared that I was still running the old one as it installed the new one in a different folder.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice