|
Post by johnno56 on Aug 11, 2019 23:45:40 GMT -6
So as not to "clutter" the news forum....
Testing the "Beast Demo" by using the android app worked like a charm. The program itself uses numeric keys to change the music and escape to quit.
Although the demo ran, I couldn't change the music or exit using esc.... I suppose there are ways around these problems but I do not know enough to figure it out. Some assistance would be appreciated...
Thank you. J
|
|
|
Post by eyfenna on Aug 12, 2019 3:03:46 GMT -6
Have you tried to code a button and check for touchscreen events at the place of the button on the device? I'll post a button example when I get back from work.
|
|
|
Post by johnno56 on Aug 12, 2019 3:49:14 GMT -6
All I did was to use the android app to convert an rcbasic program to an apk file. I am not familiar with with touch events. An example will be appreciated.
J
|
|
|
Post by n00b on Aug 12, 2019 8:40:58 GMT -6
Hey Johnno. Here is a simple way to deal with touch events.
WindowOpen(0, "Touch Test", 0, 0, 640, 480, 0) CanvasOpen(0, 640, 480, 0, 0, 640, 480, 0) ClearCanvas
Dim x Dim y Dim pressue
box_x = 10 box_y = 10 box_w = 50 box_h = 50
c = RGB(255,255,255)
While True SetColor(c) RectFill(box_x, box_y, box_w, box_h) c = RGB(255,255,255) 'Will make white the default color if there is no touch event
'Check to see if there are any fingers touching the screen If NumFingers() > 0 Then 'Loop through each touch event For i = 0 to NumFingers()-1 GetTouchFinger(i, x, y, pressure) 'gets the x, y, and pressure of the touch 'Checks to see if the finger touched inside the box If x >= box_x And x < (box_x + box_w) And y >= box_y And y < (box_y + box_h) Then c = RGB(255,0,0) 'Changes color of box to Red if finger is inside it End If
Next
End If
Update Wend
|
|
|
Post by eyfenna on Aug 12, 2019 10:30:32 GMT -6
Thanks for the great example n00b.
Actually I think n00b's example is quicker to implenet: store the filenames that play loadmusic should load in a string array. dim a restartmusic variable with false.
just when a fingerpress event happens scan for the specific location and assign a switch music one track lower until zero or higher until four and set restartmusic to true. after that if restartmusic is true:
- load music from specific string array whos element number has been set before
- set music to play - set restartmusic to false
Here is an example for a button that reswitches after being pressed and one that needs to be manually switched back, the graphic for the button is in the attachment of the posting:
dim buttonactive[30] dim buttonx[30] dim buttony[30] dim buttonpressed[30] dim buttonstatic[30] dim buttontouched[30]
sub registerButton(number,x,y, static) buttonactive[number] = 1 buttonx[number] = x buttony[number] = y buttonstatic[number] = static end sub
sub drawButton(number) if buttonpressed[number] = 0 then drawImage_Blit(4000,buttonx[number], buttony[number],0,0,30,30) elseif buttonpressed[number] = 1 then drawImage_Blit(4000,buttonx[number], buttony[number],30,0,30,30) end if end sub
sub resetButton(number) buttonpressed[number] = 0 end sub
sub resetButtons() for i = 0 to 29 if buttontouched[i] > 0 then buttontouched[i] = buttontouched[i] -1 end if if buttonstatic[i] = 0 then buttonpressed[i] = 0 end if next end sub
sub drawButtons() for i = 0 to 29 if buttonactive[i] = 1 then drawButton(i) end if next end sub
sub pressButton(mx,my) for i = 0 to 29 if mx >= buttonx[i] and mx <= buttonx[i]+29 and my >= buttony[i] and my <= buttony[i]+29 then if buttontouched[i] = 0 then if buttonstatic[i] = 0 then buttonpressed[i] = 1 buttontouched[i] = 10 elseif buttonstatic[i] = 1 then if buttonpressed[i] = 0 then buttonpressed[i] = 1 buttontouched[i] = 10 elseif buttonpressed[i] = 1 then buttonpressed[i] = 0 buttontouched[i] = 10 end if end if end if end if next end sub
winx = 40 winy = 40 WindowOpen(0, "Text Test", winx, winy, 800, 600, 0) CanvasOpen(0, 800, 600, winx, winy, 800, 600, 1)
LoadImage(4000,"button.png")
registerButton(0,100,30,0) registerButton(1,100,100,1) dim mx dim my dim mb1 dim mb2 dim mb3
while true canvas(0) clearcanvas
resetButtons() getMouse(mx,my,mb1,mb2,mb3) if mb1 then pressButton(mx-winx,my-winy) end if print(mx) print(my) drawButtons() update()
wend
Attachments:
|
|
|
Post by johnno56 on Aug 12, 2019 17:10:46 GMT -6
n00b,
Thank you for the example. Although it ran, I couldn't test it, as my desktop PC does not have a touch screen. Transferred to the Tablet without error and was presented with a white square. But touching it did not change its colour... Oh well... It was probably something I either did or didn't do... lol
|
|
|
Post by johnno56 on Aug 12, 2019 17:26:25 GMT -6
eyfenna,
Thank you also for the example.
This what I would affectionately call 'old school' method. Create/detect a 'zone' for the mouse pointer. If within zone (mouse over) do this; if within zone and mouse button pressed (click) do that; else do nothing. But your method is more efficient than mine. Nicely done.
It is painfully obvious that my skills (or lack of them... lol), in regards to Androids, are in need of improving... lol
|
|
|
Post by eyfenna on Aug 13, 2019 6:41:47 GMT -6
Jhonno I found my method to be too efficient, it jumps to first or last track. In so far it needs a kind of break intervall before accepting input from the same button again.
|
|