| Mirage Source http://web.miragesource.net/forums/ |
|
| Visual Inventory Tutorial http://web.miragesource.net/forums/viewtopic.php?f=210&t=1692 |
Page 1 of 2 |
| Author: | JokeofWeek [ Thu Apr 19, 2007 2:06 am ] |
| Post subject: | Visual Inventory Tutorial |
Alright well, on my way to programming my game, I was searching for a Visual Inventory code and found GSD's, but I saw that it was a very long code and was probably laggy, so I decided to remake the code. Then I wondered whether I should rip it from Elysium, and I decided not to, seeing as Elysium is very buggy. It's pretty simple, and will probably be less laggy, considering it doesn't re-load the item surface into a picture box and stuff. As you might notice, there are some similarities between GSD's and the Elysium and my tut. So first things first, this isn't a full tutorial. I have completed the code, but I want people to learn, and figuring out how to code things is the best way. Of course, you can ask questions on how to add the use + drop code in, but it's just not for copy paste. I'm just telling you how to blt the items and how to have a good base. You have to add the code for drop + using items. Oh my god, how hard So first, make a picture box called PicInventory, or whatever you want. Now, inside it, make 12 picInv boxes so it's an array. (However, make sure to start at 1 and not 0, so you have picInv 1 - picinv 12 and not picInv 0 - picInv - 11) Also, add a shape called SelectedItem with the following stats : BorderWidth = 2 Left = The left of the first picInv, - 1 Top = The top of the first picInv, - 1 Width = 35 Height = 35 Now, this is for a base base base mirage, with 24 inventory slots. Also, add a label or picturebox, whichever you want called PicUp and PicDown. These will be our scrollers. Now, at the top of frmMirage's code, add this : Code: Private InvScroll As Byte And add this in modGlobals Code: ' Used for visual inventory public InvSelected as byte Now, the inventory scrolling set set for a layout like this : x | x | x | x x | x | x | x x | x | x | x So if you want a differnt layout, figure it out ;) Then add this code : Code: Private Sub picDown_Click() If InvScroll <> 3 Then InvScroll = InvScroll + 1 End If End Sub Private Sub picUp_Click() If InvScroll <> 0 Then InvScroll = InvScroll - 1 End If End Sub Private Sub picInv_Click(Index As Integer) SelectedItem.Left = picInv(Index).Left - 1 SelectedItem.top = picInv(Index).top - 1 ItemSelected = index + (invscroll * 4) End Sub This is what sets the scrolling and selecting. Now for the blitting. Make a timer called tmrBltInv with an interval of 50 or 100 (your choice) and the enabled set to false Now add this code : Code: Private Sub tmrBltInv_Timer() Dim I As Long Dim Src As RECT For I = 1 To (picInv.Count) If picInv(I).Picture <> LoadPicture() Then picInv(I).Picture = LoadPicture() End If 'Else If GetPlayerInvItemNum(MyIndex, I + (InvScroll * 4)) = 0 Then picInv(I).Picture = LoadPicture() Else With Src .top = Item(GetPlayerInvItemNum(MyIndex, I + (InvScroll * 4))).Pic * PIC_Y .Bottom = .top + PIC_Y .Left = 0 .Right = .Left + PIC_X End With With rec .top = 0 .Bottom = .top + PIC_X .Left = 0 .Right = .Left + PIC_X End With Call DD_ItemSurf.BltToDC(picInv(I).hdc, Src, rec) End If 'End If Next I End Sub What this does is it clears the picture boxes that have items in them, and then if there is an item found, it blits it. We're almost done! Now, in sub initDirectX, under the code Code: frmMirage.show Add : Code: frmMirage.tmrBltInv.Enabled = True
And there you have it! You now have an optimized visual inventory system. Instead of blitting 24, it only blits 12 items, and instead of making picItems in the memory again as a picturebox on frmMirage, it blits directly from the surface. Now, up to you to add the drop / use code Any bug reports or comments, feel free to say so |
|
| Author: | Rian [ Thu Apr 19, 2007 2:17 am ] |
| Post subject: | |
Sweet tutorial dude. I'm gonna play with it a little when I get home I've been looking for a different way to do the visual inventory |
|
| Author: | JokeofWeek [ Thu Apr 19, 2007 2:20 am ] |
| Post subject: | |
Sonire wrote: Sweet tutorial dude. I'm gonna play with it a little when I get home
I've been looking for a different way to do the visual inventory Aha, no problem |
|
| Author: | original [ Wed Mar 26, 2008 4:09 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
When i add this, i get this error: Procedure declaration does not match description of event or procedure having the same name. It high lites this code: Code: Private Sub picInv_Click(Index As Integer
|
|
| Author: | Asrrin29 [ Wed Mar 26, 2008 7:09 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
you forgot a ")" at the end of that Sub. |
|
| Author: | original [ Wed Mar 26, 2008 11:33 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
I have that, what i showed you is what it highlighted. It didn't highlight ")". |
|
| Author: | Asrrin29 [ Thu Mar 27, 2008 3:52 am ] |
| Post subject: | Re: Visual Inventory Tutorial |
did you read this part? I see what the problem is and this looks like you might have missed it very easily: Quote: make 12 picInv boxes so it's an array. (However, make sure to start at 1 and not 0, so you have picInv 1 - picinv 12 and not picInv 0 - picInv - 11) Also, if that isn't the problem, I found this from another website concerning a similar error: Quote: It sounds like you accidentally named one of your own
functions with the same name as a control event and VB is complaining because your parameters don't match the event parameters. Isn't VB pointing out which one it is when you crash? |
|
| Author: | Robin [ Thu Mar 27, 2008 2:02 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
This tutorial is no better than the Elysium way of doing things. You need to move away from having a large array of bloated controls. You could easily have done this using only one picture box. |
|
| Author: | William [ Thu Mar 27, 2008 3:22 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
Robin wrote: This tutorial is no better than the Elysium way of doing things. Last time I checked es used bitblt? |
|
| Author: | Robin [ Thu Mar 27, 2008 3:32 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
William wrote: Robin wrote: This tutorial is no better than the Elysium way of doing things. Last time I checked es used bitblt? It doesn't matter if you use BitBlt or BltToDC or if you even set up a clipper to each bloody picture box and render it in DX7. The point is that using more than one picture box is simply lazy. |
|
| Author: | Lea [ Thu Mar 27, 2008 3:43 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
You know, someone should convert MS to use either pure GDI or pure DD. Mixing them is probably slowing things down with conversions and whatnot. |
|
| Author: | William [ Thu Mar 27, 2008 3:45 pm ] |
| Post subject: | Re: Visual Inventory Tutorial |
That might be the case here, but 2 picture boxes doesn't really matter. But of course, in one sence, it could be called lazy. |
|
| Author: | Joost [ Tue Apr 29, 2008 9:37 am ] |
| Post subject: | Re: Visual Inventory Tutorial |
I feel dumb, but anyway, The use item code is no problem, but I want to drop with right-click. What's the best way of doing that? Another parameter to the function or something like it? |
|
| Page 1 of 2 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|