Android Question LibGDX multi touch lgInputProcessor

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

I am currently trying to code my first game with LibGDX.
Starting from nothing I wanted to code a "pong" which should be the "hello world" of the games !

Getting inspiration from Cloneybird example, I have now a working basis where the ball hits the walls.
I want now to implement the paddles.
It is quite easy to draw them but to make them alive I need users interaction.

My idea is to use the lgInputProcessor

But I would like to have two players.
My question is : is it possible to have 2*lgInputProcessor or only one but with multi touch features ?

Thanks
 

freedom2000

Well-Known Member
Licensed User
Longtime User
I have tested a single input processor with the "drag event".

Surprisingly (at least for me) if I put two fingers on the screen and select the events with the "Y" position, I can share the screen into two parts and both events of the top paddle and bottom paddle are triggered.

B4X:
Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Dim delta, pos As Float

   
            If ScreenY > Activity.Height/2 Then                        'paddle1
                ... do things
            Else                                                        'paddle2
                .... do things for paddle2
            End If

I didn't expected this behavior, but it is really nice !
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I have tested a single input processor with the "drag event".

Surprisingly (at least for me) if I put two fingers on the screen and select the events with the "Y" position, I can share the screen into two parts and both events of the top paddle and bottom paddle are triggered.

B4X:
Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    Dim delta, pos As Float

  
            If ScreenY > Activity.Height/2 Then                        'paddle1
                ... do things
            Else                                                        'paddle2
                .... do things for paddle2
            End If

I didn't expected this behavior, but it is really nice !
You can also use the Pointer parameter. 0 is the first finger on screen, 1 is the second finger. That helps when a finger enters the other area.
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
You can also use the Pointer parameter. 0 is the first finger on screen, 1 is the second finger. That helps when a finger enters the other area.

@Informatix thank you for this usefull tip

BTW, I also would liket to write a text with 90° rotation, does it exist an easy way to do this with this fantastic libGDX ?

Thanks
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
I'll give it a try this evening !

thanks

Well, I succeeded in creating the label definition

B4X:
        'Creates the score label
    Dim lblStyle As lgScn2DLabelStyle
    lblStyle.Initialize(bitmapfont, bitmapfont.Color.WHITE)
    lblScore.Initialize("Score: 00", lblStyle, "")
    lblScore.setOrigin(vpW/3, vpH/2)


but I really don't know how to add it to the batch...

I tried drawtex, tex2... but as it is not a texture I am a bit lost...

Please give me a track !

OK found it !

B4X:
    lblScore.Draw(Batch,1)
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Well, I succeeded in creating the label definition

B4X:
        'Creates the score label
    Dim lblStyle As lgScn2DLabelStyle
    lblStyle.Initialize(bitmapfont, bitmapfont.Color.WHITE)
    lblScore.Initialize("Score: 00", lblStyle, "")
    lblScore.setOrigin(vpW/3, vpH/2)


but I really don't know how to add it to the batch...

I tried drawtex, tex2... but as it is not a texture I am a bit lost...

Please give me a track !

OK found it !

B4X:
    lblScore.Draw(Batch,1)
All Scene2D objects have Scn2D in their name. They are supposed to be managed and drawn by the lgScn2DStage class.
 
Upvote 0
Top