سلام بچه ها من رو این تیکه موندم اگه بزرگی کنید راهنمایی کنید ممنون میشم مفهوم این کد چیه ؟ برای 13 تا دکمه نوشته شده که روی هر کدوم میزنی صدا درمیاره کسی میتونه توضیح بده چیجوری میشه این رو برای 16 تا دکمه نوشت ؟
#Region Project Attributes
#ApplicationLabel: B4A Piano Example2
#VersionCode: 1
#VersionName: 1.03
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
Dim piano_mp(17) As MediaPlayer
End Sub
Sub Globals
Type Point(Id As Int, prevX As Int, prevY As Int)
Private list_TOUCHING, list_TOUCHED As List
Dim G As Gestures
Dim TouchMap As Map
Dim pnl_keys(17) As Panel
Private key1,key2,key3,key4,key5,key6,key7,key8,key9,key10,key11,key12,key13,key14,key15,key16,key17 As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
list_TOUCHING.Initialize
list_TOUCHED.Initialize
G.SetOnTouchListener(Activity, "GesturesTouch")
TouchMap.Initialize
loadsound 'load sound
setallpanels 'set panels
End Sub
Sub loadsound
For i = 0 To piano_mp.Length -1 'black keys are first because their z order
piano_mp(i).Initialize
piano_mp(i).Load(File.DirAssets,"newsound/" & i & ".mp3")
piano_mp(i).Looping = False
Next
End Sub
Sub setallpanels
pnl_keys(0) = key1
pnl_keys(1) = key2
pnl_keys(2) = key3
pnl_keys(3) = key4
pnl_keys(4) = key5
pnl_keys(5) = key6
pnl_keys(6) = key7
pnl_keys(7) = key8
pnl_keys(8) = key9
pnl_keys(9) = key10
pnl_keys(10) = key11
pnl_keys(11) = key12
pnl_keys(12) = key13
pnl_keys(13) = key14
pnl_keys(14) = key15
pnl_keys(15) = key16
pnl_keys(16) = key17
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
setallkeystofalse
End Sub
Sub setallkeystofalse
list_TOUCHING.Clear
list_TOUCHING.Clear
TouchMap.Clear
resetcolors
End Sub
Sub resetcolors
For i = 0 To pnl_keys.Length - 1
If i < 7 Then
pnl_keys(i).Color = Colors.Black
Else
pnl_keys(i).Color = Colors.White
End If
Next
End Sub
Sub GesturesTouch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
Dim p As Point
Select Action
Case G.ACTION_DOWN, G.ACTION_POINTER_DOWN
p.Id = PointerID
TouchMap.Put(PointerID, p)
Case G.ACTION_POINTER_UP
TouchMap.Remove(PointerID)
Case G.ACTION_UP
setallkeystofalse
End Select
list_TOUCHING.Clear 'reset touching list
For i = 0 To TouchMap.Size - 1
Dim px, py As Int
p = TouchMap.GetValueAt(i)
px = G.GetX(p.id)
py = G.GetY(p.id)
For Each pnl As Panel In pnl_keys
If px > pnl.Left And px < pnl.Left + pnl.Width Then
If py > pnl.Top And py < pnl.Top + pnl.Height Then
If pnl.Tag > 0 Then
If list_TOUCHED.IndexOf("1") > -1 Or list_TOUCHED.IndexOf("2") > -1 Or list_TOUCHED.IndexOf("3") > -1 Or list_TOUCHED.IndexOf("4") > -1 Or list_TOUCHED.IndexOf("5") > -1 Then
If py < pnl_keys(0).Height Then
If pnl.Tag = "0" Or pnl.Tag = "0" Then 'right side
If px > (pnl.Left + pnl.Width) - (pnl_keys(0).Width / 0) Then Continue
else if pnl.Tag = "0" Or pnl.Tag = "0" Then 'left side
If px < pnl.Left + (pnl_keys(0).Width / 0) Then Continue
else if pnl.tag = "0" Then
Else
If px > (pnl.Left + pnl.Width) - (pnl_keys(0).Width / 0) Or px < pnl.Left + (pnl_keys(0).Width / 0) Then Continue
End If
End If
End If
End If
list_TOUCHING.Add(pnl.Tag)
If list_TOUCHED.IndexOf(pnl.Tag) = -1 Then
list_TOUCHED.Add(pnl.Tag)
piano_mp(pnl.Tag).Position = 17
piano_mp(pnl.Tag).Play
End If
End If
End If
Next
Next
resetcolors
For i = 0 To list_TOUCHING.Size - 1
Dim index As String = list_TOUCHING.Get(i)
If index < 5 Then
pnl_keys(index).Color = Colors.Blue
Else
pnl_keys(index).Color = Colors.ARGB(100,0,0,0)
End If
Next
For i = (list_TOUCHED.Size-1) To 0 Step -1
If list_TOUCHING.IndexOf(list_TOUCHED.Get(i)) = -1 Then list_TOUCHED.RemoveAt(i)
Next
Return True
End Sub
سوال
mohammade79 127
سلام بچه ها من رو این تیکه موندم اگه بزرگی کنید راهنمایی کنید ممنون میشم مفهوم این کد چیه ؟ برای 13 تا دکمه نوشته شده که روی هر کدوم میزنی صدا درمیاره کسی میتونه توضیح بده چیجوری میشه این رو برای 16 تا دکمه نوشت ؟
#Region Project Attributes #ApplicationLabel: B4A Piano Example2 #VersionCode: 1 #VersionName: 1.03 'SupportedOrientations possible values: unspecified, landscape or portrait. #SupportedOrientations: landscape #CanInstallToExternalStorage: False #End Region #Region Activity Attributes #FullScreen: False #IncludeTitle: False #End Region Sub Process_Globals Dim piano_mp(17) As MediaPlayer End Sub Sub Globals Type Point(Id As Int, prevX As Int, prevY As Int) Private list_TOUCHING, list_TOUCHED As List Dim G As Gestures Dim TouchMap As Map Dim pnl_keys(17) As Panel Private key1,key2,key3,key4,key5,key6,key7,key8,key9,key10,key11,key12,key13,key14,key15,key16,key17 As Panel End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("1") list_TOUCHING.Initialize list_TOUCHED.Initialize G.SetOnTouchListener(Activity, "GesturesTouch") TouchMap.Initialize loadsound 'load sound setallpanels 'set panels End Sub Sub loadsound For i = 0 To piano_mp.Length -1 'black keys are first because their z order piano_mp(i).Initialize piano_mp(i).Load(File.DirAssets,"newsound/" & i & ".mp3") piano_mp(i).Looping = False Next End Sub Sub setallpanels pnl_keys(0) = key1 pnl_keys(1) = key2 pnl_keys(2) = key3 pnl_keys(3) = key4 pnl_keys(4) = key5 pnl_keys(5) = key6 pnl_keys(6) = key7 pnl_keys(7) = key8 pnl_keys(8) = key9 pnl_keys(9) = key10 pnl_keys(10) = key11 pnl_keys(11) = key12 pnl_keys(12) = key13 pnl_keys(13) = key14 pnl_keys(14) = key15 pnl_keys(15) = key16 pnl_keys(16) = key17 End Sub Sub Activity_Resume End Sub Sub Activity_Pause (UserClosed As Boolean) setallkeystofalse End Sub Sub setallkeystofalse list_TOUCHING.Clear list_TOUCHING.Clear TouchMap.Clear resetcolors End Sub Sub resetcolors For i = 0 To pnl_keys.Length - 1 If i < 7 Then pnl_keys(i).Color = Colors.Black Else pnl_keys(i).Color = Colors.White End If Next End Sub Sub GesturesTouch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean Dim p As Point Select Action Case G.ACTION_DOWN, G.ACTION_POINTER_DOWN p.Id = PointerID TouchMap.Put(PointerID, p) Case G.ACTION_POINTER_UP TouchMap.Remove(PointerID) Case G.ACTION_UP setallkeystofalse End Select list_TOUCHING.Clear 'reset touching list For i = 0 To TouchMap.Size - 1 Dim px, py As Int p = TouchMap.GetValueAt(i) px = G.GetX(p.id) py = G.GetY(p.id) For Each pnl As Panel In pnl_keys If px > pnl.Left And px < pnl.Left + pnl.Width Then If py > pnl.Top And py < pnl.Top + pnl.Height Then If pnl.Tag > 0 Then If list_TOUCHED.IndexOf("1") > -1 Or list_TOUCHED.IndexOf("2") > -1 Or list_TOUCHED.IndexOf("3") > -1 Or list_TOUCHED.IndexOf("4") > -1 Or list_TOUCHED.IndexOf("5") > -1 Then If py < pnl_keys(0).Height Then If pnl.Tag = "0" Or pnl.Tag = "0" Then 'right side If px > (pnl.Left + pnl.Width) - (pnl_keys(0).Width / 0) Then Continue else if pnl.Tag = "0" Or pnl.Tag = "0" Then 'left side If px < pnl.Left + (pnl_keys(0).Width / 0) Then Continue else if pnl.tag = "0" Then Else If px > (pnl.Left + pnl.Width) - (pnl_keys(0).Width / 0) Or px < pnl.Left + (pnl_keys(0).Width / 0) Then Continue End If End If End If End If list_TOUCHING.Add(pnl.Tag) If list_TOUCHED.IndexOf(pnl.Tag) = -1 Then list_TOUCHED.Add(pnl.Tag) piano_mp(pnl.Tag).Position = 17 piano_mp(pnl.Tag).Play End If End If End If Next Next resetcolors For i = 0 To list_TOUCHING.Size - 1 Dim index As String = list_TOUCHING.Get(i) If index < 5 Then pnl_keys(index).Color = Colors.Blue Else pnl_keys(index).Color = Colors.ARGB(100,0,0,0) End If Next For i = (list_TOUCHED.Size-1) To 0 Step -1 If list_TOUCHING.IndexOf(list_TOUCHED.Get(i)) = -1 Then list_TOUCHED.RemoveAt(i) Next Return True End Sub
لینک ارسال
به اشتراک گذاری در سایت های دیگر
11 پاسخ به این سوال تاکنون داده شده است
ارسالهای توصیه شده
بایگانی شده
این موضوع بایگانی و قفل شده و دیگر امکان ارسال پاسخ نیست.