Android Question Need Starting help, which views needed for spider-solitaire game?

opus

Active Member
Licensed User
Longtime User
Hi,
I'm testing B4A and considering to buy it.
As a starter I'm trying to convert my Spider-Solitaire game (built in Vb.Net) into B4A.
In VB I did all the drawing on a PictureBox, that included the "static" parts (cards that are laying on the table as well as the "moving" cards (the cards that are moved using the mouse).
I used the ImageView for the static part with no problem, however the "moving" part is my problem.
How to get a _Touch Event? I believe the code needed for the moving part could/should be pplaced in such a Sub.
Or am I on the wrong track?
 

derez

Expert
Licensed User
Longtime User
I do not move any view, just allocate the card's image to another view per the rules. For the movement impression I use animation library.
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for the responses.
@Erel
For a start I tried it using two transparent panels (as in SimpleDrawingFunctions from the tutorial).
I managed to draw my "static part" on one layer and the moving on a another. The moving one is only showing when Action=Activity.Action_move.
What I also need is to change the static part whenever the Action is _up or _down. I did manage to get that, but SLOW.
In VB.Net I'm used to have a single Drawing Sub, which will draw all elements of the static part. This sub is called by the GUI whenever needed. When changing any part of it, I invalidate the part of the "layer" where the changed element was and the new postion. In B4A it seems to me (very limited knowledge) that I have to redraw the whole layer each time there is a change. Is that correct?

If yes to the last question, the use of the draggable view is coming into play.
I tried that also, the problem I was runing into was that I would like to print several bitmaps stacked over each other inside that draggable view, which I couldn't (the problem is me, as stated above).
Would the usage of such draggable views for each card (i.e. 104!) be usefull?

@ derez
Never used the animation library and for a start I would like to sitck to simple drawing functions.
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for the input on draggable view, however I did some tests on the first question.
The usage of a complete redraw on the canvas is causing the observed slow speed, if I wipe and draw only the changed rectangle it is noticeable faster.
So I asssume the correct technique in B4A is to as decribed above, but what is useage/sense of an Invalidate?
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
Thanks for the input on draggable view, however I did some tests on the first question.
The usage of a complete redraw on the canvas is causing the observed slow speed, if I wipe and draw only the changed rectangle it is noticeable faster.
So I asssume the correct technique in B4A is to as decribed above, but what is useage/sense of an Invalidate?
Invalidate tells Android that the screen has changed so that it can redraw everything. Without it, many changes will not be seen. You can use Invalidate2 or Invalidate3 to cause android to only redraw the portion that is changed, speeding things up even more.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim bm As Bitmap

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim iv As ImageView
    Dim pn As Panel
    Dim cnv As Canvas


End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    iv.Initialize("")
    bm.InitializeMutable(300dip,300dip) 'create a 300x300 bitmap
    iv.Bitmap = bm 'assign the bitmap to the imageview
    Activity.AddView(iv,10dip,10dip,300dip,300dip) 'add the imageview to the activity
    pn.Initialize("pn")
    pn.Color = Colors.Transparent
    Activity.AddView(pn,10dip,10dip,300dip,300dip) 'add a transparent panel for touch events
    cnv.Initialize2(bm)' create a canvas for drawing

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub pn_Touch (Action As Int, X As Float, Y As Float)
    If Action = Activity.ACTION_DOWN Then
        cnv.DrawCircle(X,Y,10dip,Colors.Green,True,1) 'draw a circle where we touched
        iv.Invalidate3(X-10dip,Y-10dip,X+10dip,Y+10dip) 'redraw the area where we just added a circle
    End If
End Sub
 
Upvote 0
Top