Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. I am using primative polygons because that is what was used in the book I have. BTW, I don't recommend this book. Only after purchasing this book, I discovered that it was full of syntax errors, wrong class names (he used DirectX8 class names from time to time, for example), and a myriad of other code-related problems. The only reason that this book is even usable is because it comes with a CD that includes working code. After reading enough of this book, however, I really have to question the author's level of professionalism, and I've seen nothing but bad reviews online. I am going to try my program on other computers that have different hardware and see what happens, but I have never seen another program do this on my computer. If it were a hardware issue, I would expect to have observed this behavior before. The tiles are actually stored in an array of the GameEngine class. (It is a fairly simple game and doesn't need a Map class. If and when I apply what I am learning about Direct3D, if I need a flexible or expandable solution, of course I will use a Map class.) The GameEngine's Draw() method renders the array of tiles. Questions regarding the sprite class: is the performance of sprites the same as or close to that of polygon-based tiles? Are they easy or similar to use (or does anyone know about a tutorial or have any tips if they are not). And another question: Suppose I load two textures like this: Images(0) = TextureLoader.FromFile(Device, "Image1.bmp") Images(1) = TextureLoader.FromFile(Device, "Image1.bmp") Will two separate textures actually be loaded (as opposed to returning the same instance of a Texture object the second time)? Anything else would be counter-intuitive, but in the book I am using, a TextureLoader.FromFile is used to load a texture for each individual tile, with only a dozen textures and over a thousand tiles. I modified the code, adding a texture managing class to preload the textures, only calling TextureLoader.FromFile once for each texture and the program seemed to start up faster.
  2. Since DirectDraw has been deprecated, I am learning how to use Direct3D to make a 2D tile-based game, using the book ".NET Game Programming with DirectX 9.0" (VB .NET Edition). The problem I have is a row of pixels from the textures seems to wrap around on the right and bottom edges. This only happens when I use a hardware device, not a reference device. http://ilab.ahemm.org/temp.JPG The textures are 32x32 and the squares that they are rendered in are 32x32. This happened both with my source and the source included on a CD that came with the book. I tried using different overloads to load the textures. I tried changing the coordinates of the texture to be applied from (0 to 1) to (0 to .999), which helped somewhat, but I am worried that both the problem and that solution may vary depending on hardware. I googled, it scoured the DirectX documentation, and looked through the object browser for and relevant classes and properties, and found nothing that helped. Here is the code I am using: 'To load textures Images(i) = TextureLoader.FromFile(Device, _ IO.Path.Combine(ImagePath, ImageList(i))) 'To create polygons Const Size As Integer = 32 'Vertex = (X, Y, Z, tU, tV) Vertices(0) = New CustomVertex(X * Size, Y * Size, 1, 0, 1) Vertices(1) = New CustomVertex(X * Size + Size, Y * Size, 1, 1, 1) Vertices(2) = New CustomVertex(X * Size, Y * Size + Size, 1, 0, 0) Vertices(3) = New CustomVertex(X * Size + Size, Y * Size + Size, 1, 1, 0) 'To render polygons Direct3DDevice.SetTexture(0, SpriteImage) Direct3DDevice.SetStreamSource(0, VertBuffer, 0) Direct3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2) Can anyone explain to me why this is occuring or how to prevent it? I've spent hours trying to figure this out. My head hurts.
  3. That doesn't sound reliable at all. How are you planning on getting the name of the application after the double-click? By the window it creates? The application isn't even going to be open at the time of the double-click. You don't have a way of knowing how long until the application's main window is displayed, if it will recieve focus when it is shown, etc. If you somehow intercept the filename, you don't know if it is an application (.exe is not the only valid executable extension), a shorcut that might run an application, a batch file that might run an application, etc. Perhaps there is an API that will enumerate applications, or at least top-level windows which you could then filter by something like whether or not they are displayed in the taskbar...
  4. What, specifically, is the issue? If it is detecting the f1 key, you can do that with the KeyDown or KeyUp event. You can do it either for a specific control, or you can set the form's KeyPreview property to true, and handle the KeyDown or KeyUp event for the form, which will catch all keyboard input. If the problem is communicating data between forms, then you should probably add some properties or functions to pass the data from one form to the other. Details can be found in the tutor's corner, here. If the problem is something else, you will need to be more specific.
  5. The error is being thrown in ladder.dll. What is ladder.dll? Is it managed? And what is decode supposed ot do? Its hard to figure out what is going wrong when we don't even know what is going on.
  6. It keeps your code tighter. It mostly helps me keep more aware of what is going on in my code. With option strict on, you can't make a narrowing conversion or cast without knowing it. With option strict off, people sometimes find themselves doing things like adding the numeric values of strings instead of concatenating them, or treating one type of object like another. Sometimes it is a little extra typing because you have to explicitly code all narrowing conversions (Integer to byte, String to integer, Object to Control, etc.) but it also helps because you can't perform a cast or conversion that could potentially cause errors without knowing it.
  7. Array lists are useful, but they aren't strongly typed. All the casting involved give me a headache. I find myself implementing my own collection classes often. It is simple enough to do, and can save you a lot of DirectCasts.
  8. I can't say about the MSIL, my guess is that it will come out about the same, but... Dim Ctrl As Control = Something Do Until Ctrl Is Nothing 'Do whatever Ctrl = Ctrl.Parent() Loop You probably don't need to worry about Ctrl going out of scope... the reference gets freed anyways, allowing gc to do its thing, And VB doesnt have the ? operator, but again, the MSIL shouldn't be too different if you do something like this: Dim C As Control Dim text As String If C Is Nothing Then text = "" Else text = C.Text End If I would compile the code and compare the IL if I had time right now... but I don't. Just a note: check out the .Net Reflector. You can actually use it to compile C# and decompile it into VB, and vice-versa.
  9. That 3D 2-pixel label is pretty nifty (for a quick&dirty solution).
  10. Just add a timer component to your form. Set the interval property (in milliseconds) and either set the enabled property (in the property grid) to true, or call the .Start method (in code). Double click the timer in the designer and it will pop up the code with a handler template for the Tick event. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick End Sub Just put the code that should be executed every-so-often inside that sub.
  11. You can't compare a label to a number. One is a number, and the other is... well... a label. Try this: void BtnBankStickClick(object sender, System.EventArgs e) { if (Math.Abs(Int32.Parse(lblRandom.Text) - thisScore) > Math.Abs(Int32.Parse(lblBankRandom.Text) - totalScore)) { lblplayerWin.Show(); }} You have to parse the text of the labels. Note that this will cause an error if either of the labels' text is not a valid number.
  12. This code ReDims the array for each item to be added. That means that for each item you add, VB needs to allocate a new array and copy the contents of the old array to the new one. If you have 20 items to add, that means allocating and copying 20 items. I'm not sure if this is 100% right, but it using an idea like this can save the gc and ram some trouble. Dim list As String() = New String() {"list1", "list2"} Dim dt As DataTable 'Fill your table at some point 'Resize the array and get the insertion point (Offset) where the new items will go Dim Offset As Integer = list.Length ReDim Preserve list(list.Length + dt.Rows.Count - 1) 'Fill the array For iLp As Integer = 0 To dt.Rows.Count - 1 list(Offset + iLp) = dt.Rows(iLp).Item(0) Next iLp
  13. I think you do it like this: this.KeyPress -= new KeyPressEventHandler(TextBoxMaxNr_KeyPress); Create the new delegate, and use the -= operator to have that function removed from the list of handlers.
  14. C++ would be just fine. There are still people, especially those running win9x, that don't have the .net framework (and believe it or not, there are a few people without the VB6 runtimes, and more who don't have ActiveX controls commonly used with VB). As far as I know, Visual C++ 6 (I've never used 7) builds what you need into the exe. If you need to use the MFC, even older machines will have that. I generally wouldn't use anything that requires a VM in the way that a Java applet or flash does. For a lightweight app, I wouldn't even recommend Java or .Net. The few Java applications that I have used have been pretty bulky (this may not be the norm, I don't know).
  15. I am trying to access registry keys. I don't know beforehand, however, if the user will have permission to access the keys. I have read the information in MSDN on .Net security, and it just gave me a headache. Can anyone tell me, simply, how to determine if a user has permission to access a registry key? Or a file for that matter. I tried declaring a RegistryPermission object, specifying the key I needed to access, and specifying read/write/create access, and using the Demand() method, which, to my understanding, should simply throw a SecurityException if the user does not have permission. But rather than the exception being caught, a window would pop up, explaining to the user that the app tried to do something it didn't have permission to, asked the user if he wanted to ignore the error or quit the app, and if the user clicks ignore, the rest of the function does not execute (I assume the thread is being terminated).
  16. There is System.Reflection.EventInfo class. The System.Type class has a method, GetEvents(), which returns an array of EventInfo objects representing each of a certain type's events. How to handle these events without a preexisting delegate is beyond me.
  17. Just in case anyone else runs into this problem: After a few hours of trying to solve this issue, I figured this out tonight. Although I discovered that this exception will only occur when visual styles are enabled, this exception does not occur at all when I do something that I should have been doing in the first place. Calling ListView.BeginUpdate() before modifying the ListViewItemCollection, and calling ListView.EndUpdate() after modifying the collection prevents this exception from being raised.
  18. You might also want to consider embedding resources. It's nicer to distribute a single file when possible.
  19. I haven't tried this, but can it be done using reflection? (Imports System.Reflection) Dim Assm As [Assembly] = _ [Assembly].GetExecutingAssembly Dim Control As Object = Assm.CreateInstance("Namespace.TypeName") 'TypeName must be fully qualified
  20. If you mean mscorlib.dll, thats the core library for the .Net Framework
  21. I just sent a zip to myself, it went fine. I couldn't possibly see them blocking zips.
  22. First of all, this question belongs in the syntax specific form. Perhaps a mod will move it for you. Secondly, the feature that you are refering to is called short-circuiting: when the first value in an and operation evaluates to true, the second value is not evaluated. This feature was previously unavailable as an operator in Visual Basic. In Visual Basic .Net, this feature was added. To use a short-circuited and operation, use the AndAlso operator. The reason that And is not short-circuited is probably for code portability between VB6 and VB.Net.
  23. Have you googled this? A google search (for something like [.net "Windows Xp Sp2" debug]) revealed a variety of different (but appearently not too common) issues with SP2 and debugging in .Net, some of which were solved with Windows Update hotfixes. Have you used Windows Update to bring your computer up to date after installing SP2?
  24. This variable would also have to be declared publicly, allowing other programmers to access it and cause potential problems. Also, This might work of you have only a single instance of the control. If you have many, that would have to turn into a static array or collection that would have to be indexable by the reference of the controls. The designer does have a reference to the control it is designing... the ControlDesigner.Control property. internal class FixedHeightControlDesigner : System.Windows.Forms.Design.ControlDesigner { public override SelectionRules SelectionRules { get { MyControl control = (MyControl) this.Control; if (Control.Multiline) return SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Visible; else return SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.TopSizeable | SelectionRules.BottomSizeable | SelectionRules.RightSizeable | SelectionRules.Visible; } } } I got this to work fine in VB, but I don't know much C#, so I don't know if the syntax is right. Also, this won't prevent the programmer from changing the control size at run time. You might want to implement some size checking in the resize event. [Edit]Fixed a typo in the code[/Edit]
×
×
  • Create New...