ThePentiumGuy Posted December 30, 2004 Posted December 30, 2004 Hey, Is there a way to use ur Graphics object in another class? For example, I've done something like public class Gameclass Public shared gfx as Graphics Public Sub Paint(e as painteventargs) gfx = e.graphics gfx.drawimage("etc...") <-- this line works ... but end sub end class Public class clsSomething Public sub Paint() gameclass.gfx.drawimage("etc...") <-- this one doesn't. End Sub End class Oh btw, i'm getting the graphics by going to form1_paint: myGameClass.Paint(e) I'm getting an argument error (In clsSomething.Paint), although I'm using the exact same arguments for DrawImage in GameClass as well as clsSomething. What's going on? I just want to be able to draw from other classes (preferably from the graphics object in GameClass). Or should I take another route and use AddHandler in GameClass to do the same, if so - can you please remind me how to use it? Heh I need to brush up my AddHandler skills. -The Pentium Guy -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Leaders Iceplug Posted December 30, 2004 Leaders Posted December 30, 2004 Well, when the Paint event is raised, that could be a different Graphics object returned... so, you may want to do: gfx = Me.CreateGraphics() in Form_Load. In the Paint event, draw with gfx. Then, you should surely be able to draw with gfx in another class. Do you have the image available in the clsSomething class? What does the error say? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ThePentiumGuy Posted December 30, 2004 Author Posted December 30, 2004 when the Paint event is raised, that could be a different Graphics object returned Oh. Good point ;). "gfx = Me.CreateGraphics()" I'll give that a try. Thanks. [Do you have the image available in the clsSomething class?] Yep. Right there in my bin folder. The error was some Invalid Argument error. I'll give what you said a try (computer with .net doesn't have internet). -The Pentium Guy Edit: Wow. WYS is NOT WYG. I typed the post in normal characters and somehow it got to italics. Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted December 31, 2004 Author Posted December 31, 2004 Hm. Is there any way to make what's drawn stay drawn? (I think?). It gets drawn for just a second and then disappears. Putting it in a loop does the same. -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Leaders Iceplug Posted December 31, 2004 Leaders Posted December 31, 2004 Are you doing something that may cause the form to be redrawn? Do you have a Timer or something on your form? Are you changing some of the form's properties regularly? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ThePentiumGuy Posted December 31, 2004 Author Posted December 31, 2004 On keydown, my form is redrawn. No timer. No changing properties, I maximize in the load procedure and that's it. So even if I hold down a key, the text flashes. It doesn't come out clearly (and yes, I have doublebuffering...etc all that stuff turned on). -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Leaders Iceplug Posted January 1, 2005 Leaders Posted January 1, 2005 So, what are you drawing in the KeyDown event? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ThePentiumGuy Posted January 1, 2005 Author Posted January 1, 2005 Nothing. I just created a new project to test this out. And uhh... all I'm doing in keydown is Me.Invalidate lol. -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Napivo1972 Posted January 3, 2005 Posted January 3, 2005 Unless I am mistaken you can use the technique I use for GDI and DirectX objects. I don�t like to have my paint function know what needs to be done to draw and I always want to be able to draw everywhere. Multiple forms, Bitmaps or basicly everything that has a graphics object. So how do I do this? I create a class that hold all parameters for the particular shape Let�s say an regular N-Gon Properties Diameter of the containing circle, Sides, Pen, Edge color and fillcolor , . This of course can be exended to the inner circle and so on�� but we keep it simple Then I create a sub named draw that take the graphics object as parameter. Here I explain how the shape should be drawn. I also have a container Class that has the ability to contain the above class. Yes it is basically an araylist that also has the Draw sub and also takes the graphics bject as a parameter. In the draw sub I just call every shape that�s in my arraylist and call their draw method. This has the advantage that you can even place containers into other containers and that you can call the root container or any of it�s children if you only want to draw a partial image. Having a visible property is always useful. I would give you an example but I have only a very complex vector world map drawing system here with me that�s far from completed so you understand this would make a lousy example. Quote
Leaders Iceplug Posted January 3, 2005 Leaders Posted January 3, 2005 You could create an empty bitmap, and do all of your drawing onto that. Then, when it's time to display what you have drawn, you just use the Graphics object that draws to your 'display', and then .DrawImage. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ThePentiumGuy Posted January 3, 2005 Author Posted January 3, 2005 All this seems redundant just for one small thing :). I've just thrown all my drawing code into the GameClass.Paint event and it works fine: Public Sub New(Gameform as form) AddHandler gameform.Paint, me.Paint End Sub Public Sub Paint(sender as object, e as paintevnetargs) e.graphics.drawimage(etc) If Not clsSomething.TheBitmapItNeedsToDraw = Nothing Then e.graphics.drawimage(clsSomething.TheBitmapThatItneedsToDraw) End If End Sub I wish Microsoft offered a simpler solution to this. But oh well, the one I'm using right now works. -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.