|
-
Jun 10th, 2011, 03:41 PM
#1
Thread Starter
Lively Member
vb 2010 module's
hey
im making a game in vb 2010. but im new to 2010 so i dont know how it works (because i used 6.0 before).
I have a form, where the graphics should be drawn on. "frmMainGame"
I have a module where I want to put all Graphic things in.
so I have in my module Graphics.vb
Code:
Public Sub DrawPlayerCoordinates()
G.DrawString("Map: " & GetPlayerMap(MyIndex) & vbCrLf & "X: " & GetPlayerX(MyIndex) & vbCrLf & "Y: " & GetPlayerY(MyIndex), Game.font, Brushes.Red, 15, 15)
End Sub
now I have a button what calls the sub "Call DrawPlayerCoordinates()"
but now it gives an error because it don't know where to draw the string. So how do the code above know it should draw it on "frmMainGame" and not in a module what isn't possible?
-
Jun 10th, 2011, 03:50 PM
#2
Re: vb 2010 module's
try this:
vb Code:
Module Module1
Public Sub DrawPlayerCoordinates(ByVal frm As Form)
Dim g As Graphics = frm.CreateGraphics
g.DrawString("Map: " & GetPlayerMap(MyIndex) & vbCrLf & "X: " & GetPlayerX(MyIndex) & vbCrLf & "Y: " & GetPlayerY(MyIndex), frm.Font, Brushes.Red, 15, 15)
End Sub
End Module
to call it from your button_click event:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DrawPlayerCoordinates(Me)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 10th, 2011, 03:58 PM
#3
Thread Starter
Lively Member
Re: vb 2010 module's
no errors, but it's not drawing anything.. :/
-
Jun 10th, 2011, 04:00 PM
#4
Re: vb 2010 module's
are you sure theres an empty part of the form at 15, 15?
it won't draw over controls
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 10th, 2011, 04:11 PM
#5
Thread Starter
Lively Member
Re: vb 2010 module's
actually it should draw over the colors or not? if not -> how should i draw it over the colors?
Code:
G.DrawString(Player(0).Name, Me.Font, Brushes.AntiqueWhite, 145, 140)
this draws the name of my player and i'll see the text. (this code is still in frmMainGame but should be also in the modGraphics).
-
Jun 10th, 2011, 04:22 PM
#6
Re: vb 2010 module's
the problem with drawing on your form with CreateGraphics is that the graphics aren't persistent + they'll be erased next time the form is repainted.
the easiest workaround is to put the:
vb Code:
DrawPlayerCoordinates(Me)
...line in the form's _paint event
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|