Hello,
I'm running B4A Version 10.2 on Win10 Pro.
I'm trying to install - on an Android device - the Firework code found on this thread:
The relevant code:
The IDE shows me an error on the declaration of:
Private fx As JFX
I've checked the "PATH" environment variables, and it contains on the top of the declared paths the right directory, which in my case is
C:\java\jdk-11.0.1
Inside that there is also a "javafx" directory.
Running the command "java -version" on a Dos-prompt gives the expected java version present on the above path.
The path declared on the B4A-IDE for javac.exe under Path-Configuration is "C:\java\jdk-11.0.1\bin\javac.exe".
The question: should this code work also for B4A or am I wrong here ? Or better said, should the declaration
Private fx As JFX
work also on B4A, or is that specific for B4J instead ?
If anyone would share his knowledge on this aspect, would be really helpful.
Many thanks in advance
Sergio
I'm running B4A Version 10.2 on Win10 Pro.
I'm trying to install - on an Android device - the Firework code found on this thread:
B4X:
Type=Class
Version=4.7
ModulesStructureVersion=1
B4J=true
@EndOfDesignText@
Sub Class_Globals
Type Particle(X As Float, Y As Float, Xv As Float, Yv As Float, life As Short, rw As Short, cl As Short)
Type FireWork(X As Float, Y As Float, Height As Short, Exploded As Boolean, P As List)
Private fx As JFX
Private FW() As FireWork
Private RocketSpeed As Short
Private Timer As Timer
Private ivFireW As ImageView
Private Rocket() As ImageView
Private nFires As Short
Private soundCk As Boolean
Private fIdx As Short = -1
Private Parent As Form
Private cvsD As Canvas
Private imgTmp As Image
Private imgSparks As Image
End Sub
'nfr = Amount of rockets
Public Sub Initialize(vGV As ImageView, prt As Form, nFr As Short)
ivFireW = vGV
nFires = nFr
Parent = prt
cvsD.Initialize("")
imgSparks.Initialize(File.DirAssets, "Sparks.png")
Dim FW(nFires) As FireWork
Dim Rocket(nFires) As ImageView
RocketSpeed = 10
Timer.Initialize("Timer", 48)
For i = 0 To nFires - 1
FW(i).Initialize
FW(i).Y = -1
Rocket(i).Initialize("")
Next
createRocket
StartFireWork
CallSubDelayed(Me, "starTimer")
End Sub
Private Sub starTimer
Timer.Enabled = True
End Sub
Private Sub StartFireWork
cvsD.Width = ivFireW.Width
cvsD.Height = ivFireW.Height
For i = 0 To nFires - 1
If FW(i).Y = -1 Then 'Not initialized
FW(i).X = Rnd(ivFireW.Width *.1 , ivFireW.Width *.8) 'Initial x rocket position
FW(i).Y = ivFireW.Height 'Initial y rocket position
FW(i).Height = Rnd(20, (ivFireW.Height * .50)) 'Rocket blast point (y)
FW(i).Exploded = False
FW(i).P.Initialize
Rocket(i).Top = ivFireW.Height
Rocket(i).Left = FW(i).X
Main.SoundPlay(0)
End If
Next
End Sub
Private Sub DrawFireWork(idx As Short)
Dim DeadCount As Short
Dim RndSpeed As Float
Dim RndDeg As Float
If FW(idx).Exploded Then
Dim szP As Int = FW(idx).P.Size
Dim t, st As Double
st = 17 / (szP-1) '(17) Changes the size of the particle
For i = 0 To szP - 1 'Draws particles
Dim nFW As Particle = FW(idx).P.Get(i)
If nFW.Life > 0 Then
nFW.Life = nFW.Life - 1
nFW.X = nFW.X + nFW.Xv
nFW.Y = nFW.Y + nFW.Yv
nFW.Xv = nFW.Xv / 1.05
nFW.Yv = nFW.Yv / 1.05 + 0.05
t = t + st
cvsD.DrawImage2(imgSparks, nFW.cl, nFW.rw, 15.0, 15.0, nFW.X, nFW.Y, t, t)
Else If nFW.Life > -40 Then
nFW.Life = nFW.Life - 1
nFW.X = nFW.X + nFW.Xv + (0.5 - Rnd(0, 100)/100)
nFW.Y = nFW.Y + nFW.Yv + 0.1
nFW.Xv = nFW.Xv / 1.05
nFW.Yv = nFW.Yv
t = t + st
cvsD.DrawImage2(imgSparks, nFW.cl, nFW.rw, 15.0, 15.0, nFW.X, nFW.Y, t, t)
Else
DeadCount = DeadCount + 1
End If
Next
If soundCk Then
Main.SoundPlay(1)
soundCk = False
End If
If DeadCount > FW(idx).P.Size -1 Then
FW(idx).Y = -1 'Rocket restart
StartFireWork
End If
Else
FW(idx).Y = FW(idx).Y - RocketSpeed
If FW(idx).Y < FW(idx).Height Then
moveRoket(idx, FW(idx).X, Parent.Height)
Dim ExplosionShape As Short
ExplosionShape = Rnd(0, 3)
soundCk = True
Select Case ExplosionShape
Case 0 'Regular
Dim p As Int = Rnd(0, 400)
Dim sTmp As Short = p Mod 20
If sTmp = 0 Then sTmp = 20
Dim tot As Short = Rnd(0, 100) + 100
For i = 0 To tot-1
Dim nFW As Particle
nFW.Initialize
nFW.X = FW(idx).X
nFW.Y = FW(idx).Y
nFW.Life = Rnd(0, 20) + 20
RndSpeed = Rnd(0, 6)
RndDeg = Rnd(0, 360) / 57.3
nFW.Xv = RndSpeed * Cos(RndDeg)
nFW.Yv = RndSpeed * Sin(RndDeg)
nFW.cl = 15 * (sTmp-1)
nFW.rw = ((p-sTmp)/20) * 15
FW(idx).P.Add(nFW)
Next
FW(idx).Exploded = True
Case 1 'Spiral
Dim p As Int = Rnd(0, 400)
Dim sTmp As Short = p Mod 20
If sTmp = 0 Then sTmp = 20
RndDeg = Rnd(0, 360)
For i = 0 To 49
Dim nFW As Particle
nFW.Initialize
nFW.X = FW(idx).X
nFW.Y = FW(idx).Y
nFW.Life = 40
nFW.Xv = (i * 0.1) * Cos(((360 / 25) * (i + 1) + RndDeg) / 57.3)
nFW.Yv = (i * 0.1) * Sin(((360 / 25) * (i + 1) + RndDeg) / 57.3)
nFW.cl = 15 * (sTmp-1)
nFW.rw = ((p-sTmp)/20) * 15
FW(idx).P.Add(nFW)
Next
FW(idx).Exploded = True
Case 2 'Regular Random
Dim tot As Short = Rnd(0, 100) + 100
For i = 0 To tot-1
Dim p As Int = Rnd(0, 400)
Dim sTmp As Short = p Mod 20
If sTmp = 0 Then sTmp = 20
Dim nFW As Particle
nFW.Initialize
nFW.X = FW(idx).X
nFW.Y = FW(idx).Y
nFW.Life = Rnd(0, 20) + 20
RndSpeed = Rnd(0, 6)
RndDeg = Rnd(0, 360) / 57.3
nFW.Xv = RndSpeed * Cos(RndDeg)
nFW.Yv = RndSpeed * Sin(RndDeg)
nFW.cl = 15 * (sTmp-1)
nFW.rw = ((p-sTmp)/20) * 15
FW(idx).P.Add(nFW)
Next
FW(idx).Exploded = True
End Select
Else
moveRoket(idx, FW(idx).X, FW(idx).Y)
End If
End If
End Sub
Private Sub moveRoket(ix As Short, l As Float, t As Float)
Rocket(ix).Top = t
Rocket(ix).Left = l
End Sub
Private Sub createRocket
For i = 0 To nFires - 1
Dim cvs As Canvas
cvs.Initialize("")
cvs.Width = 1
cvs.Height = 32
cvs.DrawRect(0, 0, 1, 32, fx.Colors.Transparent, True, 0)
For z = 0 To 4
Dim alp As Int = 255 - z * 51
cvs.DrawLine(0, z * 8, 0, z * 8 + 8 , fx.Colors.ARGB(alp, 243, 167, 51),1)
Next
Dim g, jot As JavaObject
g.InitializeNewInstance("javafx.scene.SnapshotParameters",Null)
g.RunMethod("setFill",Array(fx.Colors.Transparent))
jot = cvs
Parent.RootPane.AddNode(Rocket(i), 0, 0, 1, 32)
Rocket(i).SetImage(jot.RunMethod("snapshot",Array As Object(g, Null)))
Next
End Sub
Private Sub Timer_Tick
CreateImageWithAlpha(220/255)
For fIdx = 0 To nFires - 1
DrawFireWork(fIdx)
Next
ivFireW.SetImage(imgTmp)
End Sub
Public Sub Stop
Timer.Enabled = False
Dim g, jot As JavaObject
g.InitializeNewInstance("javafx.scene.SnapshotParameters",Null)
g.RunMethod("setFill",Array(fx.Colors.Transparent))
jot = cvsD
cvsD.ClearRect(0, 0 , cvsD.Width, cvsD.Height)
imgTmp = jot.RunMethod("snapshot",Array As Object(g,Null))
ivFireW.SetImage(imgTmp)
For i = 0 To nFires - 1
Rocket(i).RemoveNodeFromParent
Next
End Sub
Private Sub CreateImageWithAlpha(newAlpha As Double)
Dim g, gc, jot As JavaObject
g.InitializeNewInstance("javafx.scene.SnapshotParameters",Null)
g.RunMethod("setFill",Array(fx.Colors.Transparent))
jot = cvsD
gc = jot.RunMethod("getGraphicsContext2D",Null)
gc.RunMethod("setGlobalAlpha",Array(newAlpha))
imgTmp = jot.RunMethod("snapshot",Array As Object(g,Null))
cvsD.ClearRect(0, 0 , cvsD.Width, cvsD.Height)
cvsD.DrawImage(imgTmp, 0, 0 , imgTmp.Width, imgTmp.Height)
End Sub
The IDE shows me an error on the declaration of:
Private fx As JFX
I've checked the "PATH" environment variables, and it contains on the top of the declared paths the right directory, which in my case is
C:\java\jdk-11.0.1
Inside that there is also a "javafx" directory.
Running the command "java -version" on a Dos-prompt gives the expected java version present on the above path.
The path declared on the B4A-IDE for javac.exe under Path-Configuration is "C:\java\jdk-11.0.1\bin\javac.exe".
The question: should this code work also for B4A or am I wrong here ? Or better said, should the declaration
Private fx As JFX
work also on B4A, or is that specific for B4J instead ?
If anyone would share his knowledge on this aspect, would be really helpful.
Many thanks in advance
Sergio
Last edited: