| Mirage Source http://web.miragesource.net/forums/ |
|
| Help with Displaying Character Sprites http://web.miragesource.net/forums/viewtopic.php?f=201&t=3100 |
Page 1 of 1 |
| Author: | Stomach Pulser [ Sat Dec 01, 2007 10:45 pm ] |
| Post subject: | Help with Displaying Character Sprites |
Hello, I have recently added grimsk8ter11's "Display Sprite At Character Create" tutorial http://web.miragesource.com/forums/viewtopic.php?f=75&t=32 and I played around with one line of code to display the character facing south. And it works fine. The code I changed was the timer's function to this (I removed the Male and Female If-Then Statement and added the PIC_X * 3 to where a 0 was in the bitBlt. Code: Private Sub timNew_Timer() Call BitBlt(picpic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 3, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) End Sub And, I was trying to display it so that the picture box displayed a character walking loop (i.e. It shows the first frame, second frame, first frame, second frame, etc.) So, I came up with this code: Code: Private Sub timNew_Timer() Dim is Byte i = 0 Select Case i Case 0 Call BitBlt(picpic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 3, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) i = i + 1 Case 1 Call BitBlt(picpic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 4, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) i = 0 End Select End Sub But it didn't work, So I played around with the timer interval, making update once every second, but still no luck. I was wondering if anyone could possibly point me in the right direction (don't just fix it for me, but tell me what is wrong and maybe a hint on how to fix it). Also, all sprites are 32x32. Thank you. |
|
| Author: | Lea [ Sat Dec 01, 2007 10:58 pm ] |
| Post subject: | Re: Help with Displaying Character Sprites |
I suspect your problem is with the i = 0 line. You blit the 0 frame every loop. I bet you can get around this easily with a static variable. |
|
| Author: | Stomach Pulser [ Sun Dec 02, 2007 4:10 am ] |
| Post subject: | Re: Help with Displaying Character Sprites |
Thanks, I figured out the rest form there. Basically, I have it set so that if we are not browsing through the classes, then the sprite will animate. But, it takes about a second to load once we start the form and every time we change sprites, there is slight delay. Any tips on improving the code I use to animate? Code: Option Explicit
Public canUpdate As Byte Private Sub cmbClass_Click() lblHP.Caption = STR(Class(cmbClass.ListIndex).HP) lblMP.Caption = STR(Class(cmbClass.ListIndex).MP) lblSP.Caption = STR(Class(cmbClass.ListIndex).SP) lblSTR.Caption = STR(Class(cmbClass.ListIndex).STR) lblDEF.Caption = STR(Class(cmbClass.ListIndex).DEF) lblSPEED.Caption = STR(Class(cmbClass.ListIndex).SPEED) lblMAGI.Caption = STR(Class(cmbClass.ListIndex).MAGI) canUpdate = 0 End Sub Private Sub cmbClass_Scroll() canUpdate = 1 End Sub Private Sub Form_Load() picSprites.Picture = LoadPicture(App.Path & GFX_PATH & "\sprites" & GFX_EXT) canUpdate = 1 End Sub Private Sub timNew_Timer() 'If we are scrolling, update the sprite box If canUpdate = 0 Then Exit Sub Call BitBlt(picPic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 3, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) End Sub Private Sub timUpdate_Timer() 'If we are set on a class, then update If canUpdate = 1 Then Exit Sub Static nxtAnim As Byte Select Case nxtAnim Case 0 Call BitBlt(picPic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 4, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) nxtAnim = 1 Case 1 Call BitBlt(picPic.hdc, 0, 0, PIC_X, PIC_Y, picSprites.hdc, PIC_X * 3, Int(Class(cmbClass.ListIndex).Sprite) * PIC_Y, SRCCOPY) nxtAnim = 0 End Select End Sub |
|
| Author: | Lea [ Sun Dec 02, 2007 5:23 am ] |
| Post subject: | Re: Help with Displaying Character Sprites |
The second to load opening the form would be from loading the very large sprites.bmp into the picture box. No way to get rid of that, really, at one point or another. You're doing it twice, though, because it's done again when frmMirage opens. A way to optimize that would be to load the sprites into the DX surface when the client is started, and use the sprites from the surface everywhere. The slight delay when changing sprites is probably because of the timer. The sprite image doesn't change until after the timer triggers, so if you change sprites right after the timer triggers, there will be a <timer interval> delay between the next update. If you make it manually call timUpdate_Timer() when you change sprites, you will get it to refresh, but the first frame will likely pass quicker than normal. The best solution would be to reset the timer, and draw the first frame manually, out side of the timer. This should reset the interval. You may want to move your nxtAnim variable to the module level, so you can reset that when you change sprites, as well. This would prevent it from potentially showing the same sprite for two cycles. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|