Controller? Multitouch handling

oddchild

New member
Joined
Jul 18, 2017
Messages
14
Hi All,



I am trying to make a simple game, I was able to make some controls, but only work if they are touched one at a time. How do I make a controller that will allow the user to hit more than one buttons at a time?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
557
I'd like to help, but I am not sure what you want to achieve. Could you explain what kind of controller you want to create. Is is some real game controller like for xbox or is it some keyboard controls or maybe some touch input buttons?
It is also easier for us, if you provide some working code that shows the problem and your approach of solving it.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
14
Code:
DrawImage btnprayer, 640, 400 'player 1
DrawImage btnprayer, 0, 400

DrawImage imgleft, 690, 400 'player 1
DrawImage imgleft, 60, 400

DrawImage imgright, 775, 400 'player 1
DrawImage imgright, 160, 400


DrawImage imgdown, 730, 400 'player 1
DrawImage imgdown, 110, 400

DrawImage imgup, 730, 350 'player 1
DrawImage imgup, 110, 350


If TouchDown Then

    'restart button

    If datimer < 1 Then
        If TouchX > 400 AND TouchX < 550 And TouchY > 200 AND TouchY < 250 Then
            datimer = 1500
            score = 0
            tractsremaining = 0
            tractsremaining2 =0
        Endif

    EndIf
    'prayer for player2
    If TouchX > 0 AND TouchX < 50 And TouchY > 400 AND TouchY < 450 And firing = False And datimer > 1 Then


        firing = True
        prayerx2 = herox2
        prayery2 = heroy2
        moving = 0
        origin = 2
    EndIf


    'prayer button for player 1

    If TouchX > 640 AND TouchX < 690 And TouchY > 400 AND TouchY < 450 And firing = False And datimer > 1 Then

        firing = True
        prayerx = herox
        prayery = heroy
        moving = 0
        origin = 1
    Endif

    'left for player 2
    If TouchX > 60 AND TouchX < 110 And TouchY > 400 AND TouchY < 450 And datimer > 1 And datimer > 1 Then

        If firing = False Then dadirection2 = 1


        If framer2 < 10 Then framer2 = 10
        'If framer = 12 Then framer = 10
        If framer2 < 13 Then framer2 = framer2 + 1
        If framer2 = 12 Then framer2 = 10



        herox2 = herox2 - 5 -speed2
        If herox = 10 And herox2 = 10 Then
            If mapx > -560 Then mapx = mapx + 5
        Endif
        If herox2 < 10 Then herox2 = 10



    Endif



    'Left Button on Screen for player 1
    If TouchX > 690 AND TouchX < 740 And TouchY > 400 AND TouchY < 450 And datimer > 1 And datimer > 1 Then

        If firing = False Then dadirection = 1
        If framer < 10 Then framer = 10
        'If framer = 12 Then framer = 10
        If framer < 13 Then framer = framer + 1
        If framer = 12 Then framer = 10

        herox = herox - 5 - speed1

        If herox = 10 And herox2 = 10 Then
            If mapx > -560 Then mapx = mapx +5
        Endif
        If herox < 10 Then herox = 10
    End If


    'right button for player 2
    If TouchX > 160 AND TouchX < 210 And TouchY > 400 AND TouchY < 450 And datimer > 1 And datimer > 1 Then
        If firing = False Then dadirection2 = 2
        If framer2 > 0 Then framer2 = 3

        framer2 = framer2 + 1
        If framer2 > 5 Then framer2 = 3
        herox2 = herox2 + 5 +speed2
        If herox2 > 800 Then herox2 = 800
        If herox = 800 And herox2 = 800 Then
            If mapx > -560 Then mapx = mapx -1
        Endif
    Endif


    'button for go right
    If TouchX > 775 AND TouchX < 825 And TouchY > 400 AND TouchY < 450 And datimer > 1 Then
        If firing = False Then dadirection = 2
        framer = framer + 1
        If framer > 5 Then framer = 3
        herox = herox + 5 +speed1

        If herox > 800 Then herox = 800
        If herox = 800 And herox2 = 800
            If mapx < -560 Then mapx = mapx -5
        Endif
    End If

    'button for player 2 to go up


    If TouchX > 110 AND TouchX < 150 And TouchY > 350 AND TouchY < 400 And datimer > 1 Then
        If firing = False Then dadirection2 = 3
        If framer2 > 0 Then framer2 = 3

        framer2 = framer2 + 1
        If framer2 > 2 Then framer2 = 0
        heroy2 = heroy2 - 5 -speed2
        If heroy2 < 0 Then heroy2 = 0
        If heroy = 0 And heroy2 = 0 And mapy < 0 Then mapy = mapy + 5



    Endif
    ' button for go up
    If TouchX > 730 AND TouchX < 780 And TouchY > 350 AND TouchY < 400 And datimer > 1 Then


        If firing = False Then dadirection = 3
        framer = framer + 1
        If framer > 2 Then framer = 0

        heroy = heroy - 5 -speed1
        If heroy < 0 Then heroy = 0
        If heroy = 0 And heroy2 = 0 And mapy < 0 Then mapy = mapy + 5
    Endif


    'down for player 2

    If TouchX > 110 AND TouchX < 150 And TouchY > 400 AND TouchY < 450 And datimer > 1 Then

        If firing = False Then dadirection2 = 4
        If framer2 > 0 Then framer2 = 3

        framer2 = framer2 + 1
        If framer2 > 8 Then framer2 = 6
        If framer2 < 6 Then framer2 = 6
        heroy2= heroy2+ 5 + speed2
        If heroy2> 420 Then heroy2= 420
        If heroy = 420 And heroy2 = 420 And mapy > -720 Then mapy = mapy -1


    Endif

    'button for go down



    If TouchX > 730 AND TouchX < 780 And TouchY > 400 AND TouchY < 450 Then




        If firing = False Then dadirection = 4
        framer = framer + 1
        If framer > 8 Then framer = 6
        If framer < 6 Then framer = 6
        heroy= heroy+ 5 + speed1
        If heroy> 420 Then heroy= 420
        If heroy = 420 And heroy2 = 420 And mapy > -720 Then mapy = mapy -1
    End If



EndIf
 
Last edited by a moderator:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
557
So you are talking about two fingers on the screen, right?
You can use the index of touchX(index) to get the position of multiple fingers.
Just be aware that it is not always the case that the holding finger is index 0 and the hiting one is index 1.
It should be saver to check for both indices if they are on the field or on the button.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
14
so instead of TouchX I should use a list? and have it check each item in the list?


Thanks for your help!
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
557
You just have to check for both TouchX(0) and TouchX(1), no need for a list.
 
Top Bottom