B4A Library libGDX - Game Engine

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Sep 12, 2013.

  1. sterlingy

    sterlingy Active Member Licensed User

    Informatix,

    I've been studying some Java code, but I'm still perplexed. Maybe you can decipher it.

    I don't need to render the object as this code does. It's the casting that always throws me off. The code is something like this:

    Code:
    Private ShapeRenderer sr;
    .
    .
    .

    sr.setProjectionMatrix(
    camera.combined);
    for (mapObject object:  map.getLayers().get("objects").getObjects)){

    Polyline line = ((PolylineMapObject) Object).getPolyline();

    sr.begin(ShapeType.line);
    sr.polyline(line.getTransformedVertices());
    sr.end();
    }
     
  2. sterlingy

    sterlingy Active Member Licensed User

    Informatix,

    I should also mention that I get random null pointer exceptions, and they don't seem to be tied to anything in particular. Once I get the polyline issue resolved, I'll send the project to you. Maybe you can figure it out. The app will just crash, even when it isn't being manipulated.

    -S
     
  3. Informatix

    Informatix Expert Licensed User

    Here's an example to get the first object (a polyline) in the object layer named "myobjects":
    Code:
    Dim ObjectLayer As lgMapLayer
    ObjectLayer = Maps.Layers.Get2(
    "myobjects")
    Dim myPolyObj As lgMapPolylineMapObject = ObjectLayer.Objects.Get(0)
    Dim myPoly As lgMathPolyline = myPolyObj.Polyline
     
  4. Informatix

    Informatix Expert Licensed User

    Ok.
     
  5. sterlingy

    sterlingy Active Member Licensed User

    Informatix,

    I can read the Vertices and draw the Polyline as a ChainShape, but of course, the the Vertices are in an unscaled coordinate system. Any thoughts on applying a scale to all vertices?

    I doubt I need to explain this, but when the TiledMap is rendered, I can supply a UnitScale, however, I can't figure out how to do the same with the Polyline, nor can I scale the ChainShape. The Polyline has both setScale and Scale methods, but they don't seem to do anything.

    -SterlingY
     
    Last edited: Jan 4, 2014
  6. sterlingy

    sterlingy Active Member Licensed User

    I'm trying to get a list of joints associated with a Box2D body, but for some reason, when I check the size, it always returns Zero, which destroys my If Then loop

    The code is something like this:

    Code:
    Dim heroBody As lgBox2DBody
        
    Dim currentJoints As lgArray
        currentJoints.Initialize
       
        heroBody = globals.numbersHeld.Get(
    0)
        heroBody.GetJointList(currentJoints)
    currentJoints.size is always ZERO despite the fact that joints exist and are functioning as intended. I can manipulate heroBody in every other factor I have tried.

    -S
     
  7. Informatix

    Informatix Expert Licensed User

    I never used a polyline so I have no idea on the subject, except that I see in the code that you have to call getTransformedVertices if you changed the scale of your polyline.
     
  8. Informatix

    Informatix Expert Licensed User

    Same problem for GetFixtureList. I'm going to fix that. Thanks for the report.
     
  9. sterlingy

    sterlingy Active Member Licensed User

    Funny how I completely miss something. This problem is solved. Thanks. In regards to the getJointsList, I'm on hold until there is a solution. I can work on other aspects of the app, however.

    -SterlingY
     
  10. sorex

    sorex Expert Licensed User

    @Informatix

    I know you probably hate questions like this but...

    I there a way to seperate things so that we don't need all the 3D, physics and other moders stuff
    when we just want to create an 80 style retro games

    I mean, 2Mb to move a sprite around the screen is slightly overkill :)
     
  11. Informatix

    Informatix Expert Licensed User

    That's why I created the Lite version, but I agree that this version is still a big fat baby. I could reduce a lot more the JAR size but I don't want to maintain too much different versions of the library. And the choice is difficult to do among the things to remove (probably the network and the math stuff, maybe the stage classes...).
     
  12. Informatix

    Informatix Expert Licensed User

    The new version fixes the issue with GetJointList (it was due to a stupid assignment between two arrays).
     
  13. sterlingy

    sterlingy Active Member Licensed User

    New version! YAY!!

    I'll be working with it over the next few days, but as I'll be travelling I'm not sure how much time I can give it. With the Joint List problem solved, however, I think I'll have a fully functioning app, minus graphics and level design. Fingers crossed.

    -SterlingY
     
    JEG likes this.
  14. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Frederick, thanks for the new version of libgdx, i recently started working on my next app after finishing up everything else i had going on, i must say i'm very excited to finally have time to dig into libgdx completely.
    My app is based on the whack a mole game, so far i have the background set up and can make the moles pop up and detect the hits then they pop back down into their holes.
    I wanted to switch the image of the mole when it gets hit to an image of a bleeding mole, but i came across a strange behavior on the textures when i try to implement that.
    for example right now i have an image of justin beiber and when you tap him on the head i switch to another image of him but one where he is bruised and bleeding, the strange behavior is when i hide him back down, it switches to another different image, then the next time it switches to a completely different image, i'm not sure what's going on, i'm probably going crazy but i've already gone at least 20 times through my code and can't find where the mistake is.

    this is the code where i set up the image on the texture in the LG_Create sub
    Code:
    For i = 0 To 8
        moletexture(i).Initialize(
    "assets/beiber.png")
        moletextureregion(i).InitializeWithTexture2(moletexture(i), 
    128128)
        
    Next
    this is where the actor is initialized
    Code:
    moleactor(0).Initialize("moleactor1")
        moleactor(
    0).setSize(18%x28.33%y)
        moleactor(
    0).setPosition(lGdx.Graphics.Width/2 - 8.165%x642 - (128 + 660))
        moleactor(
    0).ZIndex = 1
    and when the actor is hit i switch the image to a different image here in the Molelistener_Click Event
    Code:
    Sub molelistener_Click(Event As lgScn2DInputEvent, X As Float, Y As Float)
    moletexture(
    0).Initialize("assets/bleeding.png")
    moletextureregion(
    0).InitializeWithTexture2(moletexture(0), 256256)
    actorhit = 
    True
    End Sub
    i'm including the apk file so you can see the issue i'm having, hopefully you'll be able to figure out what's going on.
    https://dl.dropboxusercontent.com/u/82367588/Whack A Beiber.apk

    Thanks for your hard work Frederick

    Walter
     
  15. Informatix

    Informatix Expert Licensed User

    It seems that you have a little sister.... :)

    Your snippets of code reveal two problems: one is with memory (you create eight times the same texture and do not dispose it when you re-initialize the instance) and another with programming: why do you load many times the same texture? You should load two textures, one with Beiber and his angel face, and one with a bruised face. Convert this texture to a drawable (Texture -> TextureRegion -> lgScn2DTextureRegionDrawable or Texture -> Sprite -> lgScn2DSpriteDrawable). Then create eight actors (lgScn2DImage class) that use one of these drawables depending on the context (cf. the drawable property).

    And if the problem is still there after a proper rewriting, you should place a Log() everywhere to know what functions are called, what values are set, what parameters are passed, etc. (since you cannot use reliably the B4A debugger).

    Hope that helps.

    Note: I receive all forum messages in my mailbox so it is useless to send a private message to notify me. If I don't answer, there's a reason (I was too busy the past days and not always behind my computer).
     
    Last edited: Jan 13, 2014
  16. sterlingy

    sterlingy Active Member Licensed User

    Informatix,

    I've had time to work with v.93

    So Get..List functions are working, but I'm not making much headway with doing anything with it. I'll explain what I'm trying to do: Imagine trying to create a train where each car is a BODY, and the connection between them is a JOINT, but periodically, I want to insert a new car between the first and second car. My thought was to get the JOINT from car1, and change it's BodyB to the car being inserted, then create a new JOINT to attach the inserted car to what is now the third car.

    The problem is that I can get the list of associated joints, but I can only read, not write to the BodyA and BodyB properties.

    As a temporary fix, I destroy the list of world's joints and then reconstruct the order of the bodies and associated joints. This is however sloppy and ultimately will not work for me, and it's a bit buggy.

    On another topic, I looked at your Skater example, hoping the repeating background would have solved the repeating or swapping tiled maps, but I see it's a different beast. Any update on when you might be able to work on that?

    About flipped sprites. Is it proper behavior that Sprite.Flip(x,y) flips every time you call it? For example every time you code Sprite.Flip(false, true) it performs a flip operation, as opposed to keeping it flipped from it's original state.

    I started to clean up my code and make it better organized so I can scale it more efficiently, and I created a new Activity to handle loading of assets, the main menu and options, then make the gameplay a separate Activity. It occurred to me that this might be the wrong approach with libGDX. What are your thoughts?

    Lastly, you may remember a problem we discussed a few months ago, where there were some anomalies when moving around a tiled map. I thought the problem was solved when the tileset didn't have a pixel gap between each tile. Seems like I'm wrong. I think you knew what caused it. Any hopes in it being resolved?

    Cheers,

    SterlingY

    P.S. I haven't played with the Perspective Camera yet, but I think I need to get everything else through my head first.
     
  17. sterlingy

    sterlingy Active Member Licensed User

    Some info on the inserting Bodies and Joints into a chain:

    I rewrite my code, after I learned that it is not possible to change a Joint's BODY associations, once it has been created.

    Code:
    Public Sub Initialize(vBodyA As lgBox2DBody, vBodyB As lgBox2DBody)


        
    Dim heroBody As lgBox2DBody
        
    Dim connectionsList As lgArray
        connectionsList.Initialize
       
        heroBody = globals.numbersHeld.Get(
    0)
        heroBody.GetJointList(connectionsList)
       
        
    If globals.numbersHeld.Size = 1 Then
            globals.numbersHeld.Add(vBodyB)
        
    Else
            globals.numbersHeld.InsertAt(
    1, vBodyB)
        
    End If

        
    Log("numHeld:" & globals.numbersHeld.Size)
        
    Log("cJ: " & globals.connectionsList.Size)

        
    'Dim HeroJoint As lgBox2DRevoluteJoint
        If connectionsList.Size > 0 Then
        
    '    HeroJoint = connectionsList.Get(0)
            GamePlay.World.DestroyJoint(connectionsList.Get(0))
        
    End If

        
    Dim connectorJointDef As lgBox2DRevoluteJointDef
           
        
    If globals.numbersHeld.size = 2 Then
            connectorJointDef.bodyA = globals.numbersHeld.Get(
    0)   
            connectorJointDef.bodyB = globals.numbersHeld.Get(
    1)
           
            connectorJointDef.localAnchorA.Set(-
    5 , 0)
            connectorJointDef.localAnchorB.Set(
    2 , 0)
            connectorJointDef.collideConnected = 
    False
           
            GamePlay.World.CreateJoint(connectorJointDef)
        
    Else
            connectorJointDef.bodyA = globals.numbersHeld.Get(
    1)   
            connectorJointDef.bodyB = globals.numbersHeld.Get(
    2)
           
            connectorJointDef.localAnchorA.Set(-
    2 , 0)
            connectorJointDef.localAnchorB.Set(
    2 , 0)
            connectorJointDef.collideConnected = 
    False
           
            GamePlay.World.CreateJoint(connectorJointDef)
        
    End If

    End Sub
    I'm getting a class mismatch error on the following line: "
    GamePlay.World.DestroyJoint(connectionsList.Get(0))"

    It says that you can't cast a JointEdge to a Joint.

    DestroyJoint wants an lgBox2DJoint, and my joints are RevoluteJoints.

    -SterlingY
     
  18. Informatix

    Informatix Expert Licensed User

    Hello,

    I cannot fully help you before tomorrow evening because I have a lot of important things to do but here are quick answers to some of your questions: the pixel gap is due to roundings and the only solution that I know is to use the screen resolution for your tile renderer (no unit scale set); I didn't forget your demand for an endless scroll; Flip() flips the sprite every time; World.GetAllJoints returns a list of Joints but Body.GetJointList returns a list of JointEdges so, to remove the joint, you have to use myJointEdge.Joint.
     
  19. sterlingy

    sterlingy Active Member Licensed User

    Thanks for checking in. I'll see what I can do in the meantime.

    -SterlingY
     
  20. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Frederick, thanks for the reply, in talking to Sterlingy about this same issue, he also suggested a couple of things, i've also implemented your suggestions of converting the texture to a drawable, and i'm not creating the same texture eight times as i was doing previous, i created a different class which takes care of creating the actors, however i did struggle a bit in placing the background actors and the main actors in the right zindex order, another issue i was having was when adding a clicklistener to the actors, for some reason only the last added actor was actually firing the change image code inside of it, it is now working, i had to change the click listener code to the main activity, i defined the click listener from the main activity and just passed it as a parameter to the creator actor sub in the createactors class, this is now working as i wanted. Thanks alot for your reply again Frederick, i understand that you only port this libraries but still i'am aware that this requires a lot of work and for that i'm greatful as this provides us with an opportunity to create better apps.

    On another note, i've been trying to do some research about creating a camera shaking effect, for example when there's an explosion i've seen some really nice apps where the whole screen does this shaking effect, i noticed you posted the simplex noise library and that this is based on the perlin algorithm, i'm not sure if you have any input or experience on this, but would you know if the simplex noise library would be able to be used for something like that?

    Thanks,
    Walter
     
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