For p=0 To t
// works
g.DrawPicture(score0, x, y)
// Parameter "image" expects class Picture, but this is type String.
g.DrawPicture("score" + s.Middle(p,1), x, y)
Next
is there a way to call the image score0 like “score” + str(0)?
i need to do this dynamically…
dim thePath() as String
thePath.Add("ur_setup_imap_lite@2x.png")
thePath.Add("ur_setup_email_lite@2x.png")
thePath.Add("ur_setup_mailboxes_lite@2x.png")
Make images out of the paths:
dim ManualImages(-1) as Picture
for currentPath as Integer = 0 to thePath.LastIndex
dim PictureFile as FolderItem = GetFileFromPath(SpecialFolder.Resources, thePath(currentPath))
if PictureFile <> nil and PictureFile.Exists then
ManualImages.Add Picture.Open(PictureFile)
else
globals.theErrorLog.DialogErrorProceed(kImageNotFound.Replace("<<image>>", thePath(currentPath)))
Exit
end if
next
Now you have an array of images which you can draw. Actually, the dictionary would work better here instead of my array so that you can have a name and a picture.
image will be a Picture
picName is the string name of the picture - “score0”, “score1”, “score2”, etc.
scoreDictionary is a Dictionary that you previously loaded the images into, keyed by their string names, so that later, you can construct the name and get the correspnding Picture.
Regardless, you won’t get the result you expect. Perhaps you should use a Timer instead of the for/next loop. Have the timer determine the next image to draw, assign it to a property of the canvas or window and then refresh the canvas.
games draw many frames per seconds, so score would also paint with it at last on top.
if you add pictures to the game use the name in the source code in a switch case.
use a sub method like game.DrawScore(g) in the paint event of canvas.
the refresh/redraw of canvas can be triggered in a timer event.
as i have only 10 digits, i used select case to do what i need. worked as expected.
Public Sub generateScoreNumbers(g as Graphics, x as integer, y as integer, score as integer = 0)
Var s As String = score.ToString
Var p As Integer
Var t As Integer = s.Length
Var pict As Picture
For p=0 To t-1
Select Case s.Middle(p,1)
Case "0"
pict = score0
Case "1"
pict = score1
Case "2"
pict = score2
Case "3"
pict = score3
Case "4"
pict = score4
Case "5"
pict = score5
Case "6"
pict = score6
Case "7"
pict = score7
Case "8"
pict = score8
Case "9"
pict = score9
End Select
g.DrawPicture(pict, x, y)
x = x + 16
Next
End Sub
but i i’ll change to dictionary. i think it’s more elegant solution.