Jag håller på att försöka göra en kod som ritar upp en bana till ett RPG spel som kommer att likna Zelda typ. Men jag lyckas inte få koden att visa bilderna då jag kör spelet. Nån som vet hur det ska vara eller nått ännu bättre sätt än det jag försökt med? Du måste tilldela bilden till en kontroll eller rite ut den på en kontroll. Det räcker inte med att anropa bara LoadPicture. Jag ändrade koden så att den såg ut såhär men får ett fel på raden Opps.... Hmm. nu är det fel i RPG spel
KOD:
Private Sub Form_Load()
'Arrey som gör ett rutnät med värden i rutorna som du anger med x och y kordinater
Dim rutmonster(15, 15) As String
'Road
rutmonster(3, 0) = "SPL"
rutmonster(3, 1) = "SPL"
rutmonster(3, 2) = "SPL"
rutmonster(3, 3) = "SPL"
'stump
rutmonster(2, 3) = "X"
'Road
rutmonster(3, 4) = "SPCL"
rutmonster(2, 4) = "SPV"
rutmonster(1, 4) = "SPV"
rutmonster(0, 4) = "SPV"
rutmonster(3, 5) = "SPL"
rutmonster(3, 6) = "SPL"
rutmonster(3, 7) = "SPL"
rutmonster(3, 8) = "SPCuU"
rutmonster(4, 8) = "SPV"
rutmonster(5, 8) = "SPV"
rutmonster(6, 8) = "SPV"
rutmonster(7, 8) = "SPV"
rutmonster(8, 8) = "SPV"
rutmonster(9, 8) = "SPV"
rutmonster(10, 8) = "SPV"
rutmonster(11, 8) = "SPV"
rutmonster(12, 8) = "SPV"
rutmonster(13, 8) = "SPV"
rutmonster(15, 8) = "SPV"
'Sand
rutmonster(6, 1) = "SCuH"
rutmonster(6, 2) = "SH"
rutmonster(6, 3) = "SCuU"
rutmonster(7, 1) = "SU"
rutmonster(7, 2) = "S"
rutmonster(7, 3) = "SN"
rutmonster(8, 1) = "SCuN"
rutmonster(8, 2) = "SH"
rutmonster(8, 3) = "SCuV"
'Kod som skriver ut bilderna så att dom blir synliga
For raknare_horizontell = 0 To 14
For raknare_vertikal = 0 To 14
fil_namn = Hamtar_fil_namn(rutmonster(x, y))
LoadPicture fil_namn
Next
Next
End Sub
'Function som kollar värden i rutnätet och ändrar dom till en adress
Private Function Hamtar_fil_namn(bild_kod As String)
If bild_kod = "W" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Water.bmp"
ElseIf bild_kod = "G" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass.bmp"
ElseIf bild_kod = "S" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand.bmp"
ElseIf bild_kod = "GEH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_EdgeH.bmp"
ElseIf bild_kod = "GEV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_EdgeV.bmp"
ElseIf bild_kod = "GEU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_EdgeU.bmp"
ElseIf bild_kod = "GEN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_EdgeN.bmp"
ElseIf bild_kod = "GCV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_CornerV.bmp"
ElseIf bild_kod = "GCH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_CornerH.bmp"
ElseIf bild_kod = "GCN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_CornerN.bmp"
ElseIf bild_kod = "GCU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Grass_CornerU.bmp"
ElseIf bild_kod = "SH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_H.bmp"
ElseIf bild_kod = "SN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_N.bmp"
ElseIf bild_kod = "SU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_U.bmp"
ElseIf bild_kod = "SV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_V.bmp"
ElseIf bild_kod = "SCuV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_CurbV.bmp"
ElseIf bild_kod = "SCuH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_CurbH.bmp"
ElseIf bild_kod = "SCuU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_CurbU.bmp"
ElseIf bild_kod = "SCuN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_CurbN.bmp"
ElseIf bild_kod = "SPL" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathL.bmp"
ElseIf bild_kod = "SPV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathV.bmp"
ElseIf bild_kod = "SPCH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCrossingH.bmp"
ElseIf bild_kod = "SPCV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCrossingV.bmp"
ElseIf bild_kod = "SPCN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCrossingN.bmp"
ElseIf bild_kod = "SPCU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCrossingU.bmp"
ElseIf bild_kod = "SPCuH" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCurbH.bmp"
ElseIf bild_kod = "SPCuN" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCurbN.bmp"
ElseIf bild_kod = "SPCuV" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCurbV.bmp"
ElseIf bild_kod = "SPCuU" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Sand_PathCurbU.bmp"
ElseIf bild_kod = "StP1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Stone_plates1.bmp"
ElseIf bild_kod = "StP2" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Stone_plates2.bmp"
ElseIf bild_kod = "StP3" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Stone_plates3.bmp"
ElseIf bild_kod = "StP4" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Stone_plates4.bmp"
ElseIf bild_kod = "SPPL1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathL1.bmp"
ElseIf bild_kod = "SPPV1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathV1.bmp"
ElseIf bild_kod = "SPPL2" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathL2.bmp"
ElseIf bild_kod = "SPPV2" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathV2.bmp"
ElseIf bild_kod = "SPPCuU1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathCurbU1.bmp"
ElseIf bild_kod = "SPPCuN1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathCurbN1.bmp"
ElseIf bild_kod = "SPPCuV1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathCurbV1.bmp"
ElseIf bild_kod = "SPPCuH1" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\StonePlate_PathCurbH1.bmp"
ElseIf bild_kod = "X" Then
fil_namn = "C:\exempel\The hidden kingdom\Bitmaps\Stump.bmp"
End If
Hamtar_fil_namn = fil_namn
End FunctionSv: RPG spel
<code>
Set Image1.Picture = LoadPicture("C:\Bild.bmp")
</code>
Eftersom du kommer ha många blider är det ibättre att rita upp. Här är ett exempel:
<code>
Private mPictures As Collection
Private Function LoadPictures(Path As String) As Collection
Set LoadPictures = New Collection
LoadPictures.Add LoadPicture(Path & "Water.bmp"), "W"
LoadPictures.Add LoadPicture(Path & "Grass.bmp"), "G"
LoadPictures.Add LoadPicture(Path & "Sand.bmp"), "S"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeH.bmp"), "GEH"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeV.bmp"), "GEV"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeU.bmp"), "GEU"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeN.bmp"), "GEN"
LoadPictures.Add LoadPicture(Path & "Grass_CornerV.bmp"), "GCV"
LoadPictures.Add LoadPicture(Path & "Grass_CornerH.bmp"), "GCH"
LoadPictures.Add LoadPicture(Path & "Grass_CornerN.bmp"), "GCN"
LoadPictures.Add LoadPicture(Path & "Grass_CornerU.bmp"), "GCU"
LoadPictures.Add LoadPicture(Path & "Sand_H.bmp"), "SH"
LoadPictures.Add LoadPicture(Path & "Sand_N.bmp"), "SN"
LoadPictures.Add LoadPicture(Path & "Sand_U.bmp"), "SU"
LoadPictures.Add LoadPicture(Path & "Sand_V.bmp"), "SV"
LoadPictures.Add LoadPicture(Path & "Sand_CurbV.bmp"), "SCuV"
LoadPictures.Add LoadPicture(Path & "Sand_CurbH.bmp"), "SCuH"
LoadPictures.Add LoadPicture(Path & "Sand_CurbU.bmp"), "SCuU"
LoadPictures.Add LoadPicture(Path & "Sand_CurbN.bmp"), "SCuN"
LoadPictures.Add LoadPicture(Path & "Sand_PathL.bmp"), "SPL"
LoadPictures.Add LoadPicture(Path & "Sand_PathV.bmp"), "SPV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingH.bmp"), "SPCH"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingV.bmp"), "SPCV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingN.bmp"), "SPCN"
LoadPictures.Add LoadPicture(Path & "SPCU"), "Sand_PathCrossingU.bmp"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbH.bmp"), "SPCuH"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbN.bmp"), "SPCuN"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbV.bmp"), "SPCuV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbU.bmp"), "SPCuU"
LoadPictures.Add LoadPicture(Path & "Stone_plates1.bmp"), "StP1"
LoadPictures.Add LoadPicture(Path & "Stone_plates2.bmp"), "StP2"
LoadPictures.Add LoadPicture(Path & "Stone_plates3.bmp"), "StP3"
LoadPictures.Add LoadPicture(Path & "Stone_plates4.bmp"), "StP4"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathL1.bmp"), "SPPL1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathV1.bmp"), "SPPV1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathL2.bmp"), "SPPL2"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathV2.bmp"), "SPPV2"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbU1.bmp"), "SPPCuU1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbN1.bmp"), "SPPCuN1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbV1.bmp"), "SPPCuV1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbH1.bmp"), "SPPCuH1"
LoadPictures.Add LoadPicture(Path & "Stump.bmp"), "X"
End Function
Private Sub Form_Load()
Dim X As Single
Dim Y As Single
Dim pic As StdPicture
Dim PicLeft As Single
Dim PicTop As Single
Dim PicWidth As Single
Dim PicHeight As Single
Picture1.Autoredraw = True
PicWidth = Picture1.ScaleX(15, vbPixels)
PicHeight = Picture1.ScaleX(15, vbPixels)
Set mPictures = LoadPictures("C:\exempel\The hidden kingdom\Bitmaps\")
For Y = 0 To 14
For X = 0 To 14
Set pic = mPictures(rutmonster(X, Y))
Picture1.PaintPicture PicLeft, PicTop, PicWidth, PicHeight
PicLeft = PicLeft + PicWidth
Next
PicLeft = 0
PicTop = PicTop + PicHeight
Next
End Sub
</code>Sv: RPG spel
Picture1.PaintPicture PicLeft, PicTop, PicWidth, PicHeight
Det är PicLeft som spökar. Har gjort en picurebox på formensom heter Picture1
Private mPictures As Collection
Private Function LoadPictures(Path As String) As Collection
Set LoadPictures = New Collection
LoadPictures.Add LoadPicture(Path & "Water.bmp"), "W"
LoadPictures.Add LoadPicture(Path & "Grass.bmp"), "G"
LoadPictures.Add LoadPicture(Path & "Sand.bmp"), "S"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeH.bmp"), "GEH"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeV.bmp"), "GEV"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeU.bmp"), "GEU"
LoadPictures.Add LoadPicture(Path & "Grass_EdgeN.bmp"), "GEN"
LoadPictures.Add LoadPicture(Path & "Grass_CornerV.bmp"), "GCV"
LoadPictures.Add LoadPicture(Path & "Grass_CornerH.bmp"), "GCH"
LoadPictures.Add LoadPicture(Path & "Grass_CornerN.bmp"), "GCN"
LoadPictures.Add LoadPicture(Path & "Grass_CornerU.bmp"), "GCU"
LoadPictures.Add LoadPicture(Path & "Sand_H.bmp"), "SH"
LoadPictures.Add LoadPicture(Path & "Sand_N.bmp"), "SN"
LoadPictures.Add LoadPicture(Path & "Sand_U.bmp"), "SU"
LoadPictures.Add LoadPicture(Path & "Sand_V.bmp"), "SV"
LoadPictures.Add LoadPicture(Path & "Sand_CurbV.bmp"), "SCuV"
LoadPictures.Add LoadPicture(Path & "Sand_CurbH.bmp"), "SCuH"
LoadPictures.Add LoadPicture(Path & "Sand_CurbU.bmp"), "SCuU"
LoadPictures.Add LoadPicture(Path & "Sand_CurbN.bmp"), "SCuN"
LoadPictures.Add LoadPicture(Path & "Sand_PathL.bmp"), "SPL"
LoadPictures.Add LoadPicture(Path & "Sand_PathV.bmp"), "SPV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingH.bmp"), "SPCH"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingV.bmp"), "SPCV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCrossingN.bmp"), "SPCN"
LoadPictures.Add LoadPicture(Path & "SPCU"), "Sand_PathCrossingU.bmp"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbH.bmp"), "SPCuH"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbN.bmp"), "SPCuN"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbV.bmp"), "SPCuV"
LoadPictures.Add LoadPicture(Path & "Sand_PathCurbU.bmp"), "SPCuU"
LoadPictures.Add LoadPicture(Path & "Stone_plates1.bmp"), "StP1"
LoadPictures.Add LoadPicture(Path & "Stone_plates2.bmp"), "StP2"
LoadPictures.Add LoadPicture(Path & "Stone_plates3.bmp"), "StP3"
LoadPictures.Add LoadPicture(Path & "Stone_plates4.bmp"), "StP4"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathL1.bmp"), "SPPL1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathV1.bmp"), "SPPV1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathL2.bmp"), "SPPL2"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathV2.bmp"), "SPPV2"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbU1.bmp"), "SPPCuU1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbN1.bmp"), "SPPCuN1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbV1.bmp"), "SPPCuV1"
LoadPictures.Add LoadPicture(Path & "StonePlate_PathCurbH1.bmp"), "SPPCuH1"
LoadPictures.Add LoadPicture(Path & "Stump.bmp"), "X"
End Function
Private Sub Form_Load()
'Arrey som gör ett rutnät med värden i rutorna som du anger med x och y kordinater
Dim rutmonster(15, 15) As String
'Road
rutmonster(3, 0) = "SPL"
rutmonster(3, 1) = "SPL"
rutmonster(3, 2) = "SPL"
rutmonster(3, 3) = "SPL"
'stump
rutmonster(2, 3) = "X"
'Road
rutmonster(3, 4) = "SPCL"
rutmonster(2, 4) = "SPV"
rutmonster(1, 4) = "SPV"
rutmonster(0, 4) = "SPV"
rutmonster(3, 5) = "SPL"
rutmonster(3, 6) = "SPL"
rutmonster(3, 7) = "SPL"
rutmonster(3, 8) = "SPCuU"
rutmonster(4, 8) = "SPV"
rutmonster(5, 8) = "SPV"
rutmonster(6, 8) = "SPV"
rutmonster(7, 8) = "SPV"
rutmonster(8, 8) = "SPV"
rutmonster(9, 8) = "SPV"
rutmonster(10, 8) = "SPV"
rutmonster(11, 8) = "SPV"
rutmonster(12, 8) = "SPV"
rutmonster(13, 8) = "SPV"
rutmonster(15, 8) = "SPV"
'Sand
rutmonster(6, 1) = "SCuH"
rutmonster(6, 2) = "SH"
rutmonster(6, 3) = "SCuU"
rutmonster(7, 1) = "SU"
rutmonster(7, 2) = "S"
rutmonster(7, 3) = "SN"
rutmonster(8, 1) = "SCuN"
rutmonster(8, 2) = "SH"
rutmonster(8, 3) = "SCuV"
Dim X As Single
Dim Y As Single
Dim pic As StdPicture
Dim PicLeft As Single
Dim PicTop As Single
Dim PicWidth As Single
Dim PicHeight As Single
Picture1.AutoRedraw = True
PicWidth = Picture1.ScaleX(15, vbPixels)
PicHeight = Picture1.ScaleX(15, vbPixels)
Set mPictures = LoadPictures("C:\exempel\The hidden kingdom\Bitmaps\")
For Y = 0 To 14
For X = 0 To 14
Set pic = mPictures(rutmonster(X, Y))
Picture1.PaintPicture PicLeft, PicTop, PicWidth, PicHeight
PicLeft = PicLeft + PicWidth
Next
PicLeft = 0
PicTop = PicTop + PicHeight
NextSv: RPG spel
Glömde lägga in pic as första argumentet:
<code>
Picture1.PaintPicture pic, PicLeft, PicTop, PicWidth, PicHeight
</code>Sv: RPG spel
Set pic = mPictures(rutmonster(X, Y))
Run-time error '5':
Invalid procedure call or argument