| Mirage Source http://web.miragesource.net/forums/ |
|
| Blting Errors... Help? http://web.miragesource.net/forums/viewtopic.php?f=201&t=4067 |
Page 1 of 1 |
| Author: | Leighland [ Mon Jul 28, 2008 12:20 am ] |
| Post subject: | Blting Errors... Help? |
So I've not gotten into blting stuff too much. I managed to make a pretty good paperdoll system from scratch and so far it's gone okay, except this one thing... lol When you are on the first tile of the map, as in Y=0, helmet's don't seem to work out Good Helmet: SPOILER: (click to show)
Bad helmet: SPOILER: (click to show)
And here's the code for blt'ing the helmets/tops of players: Code: Public Sub BltPlayerTop(ByVal index As Long) '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Optimized function. '**************************************************************** Dim Anim As Byte Dim X As Long, Y As Long ' Only used if ever want to switch to blt rather then bltfast With rec_pos .top = GetPlayerY(index) * PIC_Y + Player(index).YOffset .Bottom = .top + PIC_Y .Left = GetPlayerX(index) * PIC_X + Player(index).XOffset .Right = .Left + PIC_X End With ' Check for animation Anim = 0 If Player(index).Attacking = 0 Then Select Case GetPlayerDir(index) Case DIR_UP If (Player(index).YOffset < PIC_Y / 2) Then Anim = 1 Case DIR_DOWN If (Player(index).YOffset < PIC_Y / 2 * -1) Then Anim = 1 Case DIR_LEFT If (Player(index).XOffset < PIC_Y / 2) Then Anim = 1 Case DIR_RIGHT If (Player(index).XOffset < PIC_Y / 2 * -1) Then Anim = 1 End Select Else If Player(index).AttackTimer + 500 > GetTickCount Then Anim = 2 End If End If ' Check to see if we want to stop making him attack With Player(index) If .AttackTimer + 1000 < GetTickCount Then .Attacking = 0 .AttackTimer = 0 End If End With With rec .top = GetPlayerSprite(index) * PIC_Y .Bottom = .top + PIC_Y .Left = (GetPlayerDir(index) * 3 + Anim) * PIC_X .Right = .Left + PIC_X End With X = GetPlayerX(index) * PIC_X + Player(index).XOffset Y = GetPlayerY(index) * PIC_Y + Player(index).YOffset - 4 ' Check if its out of bounds because of the offset Y = Y - 32 If Y < 0 And Y > -32 Then With rec .top = .top - Y Y = 0 End With End If Call DD_BackBuffer.BltFast(X, Y, DD_PlayerSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) End Sub Code: Public Sub BltHelmet(ByVal index As Long) Dim Anim As Byte Dim X As Long, Y As Long Dim F As Long Dim BltF As Long If GetPlayerHelmetSlot(index) <= 0 Then Exit Sub F = Item(GetPlayerHelmetSlot(index)).Pic Select Case F Case I_Helmet1 BltF = 27 Case I_Helmet2 BltF = 29 Case I_Helmet3 BltF = 31 Case I_Helmet4 BltF = 33 Case I_Helmet5 BltF = 35 Case I_Helmet6 BltF = 37 Case I_Helmet7 BltF = 39 Case I_Helmet8 BltF = 41 End Select ' Only used if ever want to switch to blt rather then bltfast With rec_pos .top = GetPlayerY(index) * PIC_Y + Player(index).YOffset .Bottom = .top + PIC_Y .Left = GetPlayerX(index) * PIC_X + Player(index).XOffset .Right = .Left + PIC_X End With ' Check for animation Anim = 0 If Player(index).Attacking = 0 Then Select Case GetPlayerDir(index) Case DIR_UP If (Player(index).YOffset < PIC_Y / 2) Then Anim = 1 Case DIR_DOWN If (Player(index).YOffset < PIC_Y / 2 * -1) Then Anim = 1 Case DIR_LEFT If (Player(index).XOffset < PIC_Y / 2) Then Anim = 1 Case DIR_RIGHT If (Player(index).XOffset < PIC_Y / 2 * -1) Then Anim = 1 End Select Else If Player(index).AttackTimer + 500 > GetTickCount Then Anim = 2 End If End If ' Check to see if we want to stop making him attack With Player(index) If .AttackTimer + 1000 < GetTickCount Then .Attacking = 0 .AttackTimer = 0 End If End With With rec .top = BltF * PIC_Y .Bottom = .top + PIC_Y * 2 .Left = (GetPlayerDir(index) * 3 + Anim) * PIC_X .Right = .Left + PIC_X End With X = GetPlayerX(index) * PIC_X + Player(index).XOffset Y = (GetPlayerY(index) * PIC_Y) - PIC_Y + Player(index).YOffset - 4 ' Check if its out of bounds because of the offset ' If Y < 0 Then ' Y = 0 ' With rec ' .top = .top + (Y * -1) ' End With ' End If If Y < 0 And Y > -32 Then With rec .top = .top - Y Y = 0 End With End If Call DD_BackBuffer.BltFast(X, Y, DD_PDollSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY) End Sub I'm also having some trouble with the names. I have finally created a way that names are always drawn in the exact center of the sprites, so everything looks nice and neat. However, for some reason, there is always one name (maybe the first one to blt) that is off center, and I can't figure out why. It happens with both player's, and npc's. I use two seperate subs to blt the names for players and npc's but that seems to be irrelevant here. If I warp to a map with no npcs my players name is off center. If I add one npc, it's name is off center and the player name becomes centered. If another player enters the map, it's the same thing. The other players name will show off centered, but my player's name will be centered. It's kind odd.... here's a screenshot of that phenomena as well, and the code: SPOILER: (click to show)
Code: Sub BltPlayerName(ByVal index As Long) Dim TextX As Long, a As Long, b As Long, C As Long, d As Long Dim TextY As Long Dim Color As Long, Color2 As Long ' Check access level If GetPlayerPK(index) = NO Then Select Case GetPlayerAccess(index) Case 0 Color = QBColor(White) Case 1 Color = QBColor(Pink) Case 2 Color = QBColor(BrightCyan) Case 3 Color = QBColor(Yellow) Case 4 Color = QBColor(BrightGreen) End Select Else Color = QBColor(BrightRed) End If TextX = (GetPlayerX(index) * PIC_X + Player(index).XOffset) - ((getSize(TexthDC, Trim(GetPlayerName(index))).width - 32) / 2) TextY = GetPlayerY(index) * PIC_Y + Player(index).YOffset - Int(PIC_Y / 2) - 20 Call DrawText(TexthDC, TextX, TextY, GetPlayerName(index), Color) End Sub Code: Sub BltNpcName(ByVal index As Long) Dim TextX As Long, TextY As Long, Color As Long, NpcNum As Long NpcNum = MapNpc(index).Num If NpcNum = 0 Then Exit Sub Color = QBColor(Yellow) If Npc(MapNpc(index).Num).Level > GetPlayerLevel(MyIndex) + 10 Then Color = QBColor(BrightRed) ElseIf Npc(MapNpc(index).Num).Level < GetPlayerLevel(MyIndex) - 10 Then Color = QBColor(BrightGreen) End If ' Draw name TextX = ((MapNpc(index).X * PIC_X) + MapNpc(index).XOffset) - ((getSize(TexthDC, Trim(Npc(NpcNum).Name)).width - 32) / 2) If Npc(MapNpc(index).Num).Size = SIZE_BIG Then TextY = MapNpc(index).Y * PIC_Y + MapNpc(index).YOffset - Int(PIC_Y / 2) - 16 Else TextY = MapNpc(index).Y * PIC_Y + MapNpc(index).YOffset - Int(PIC_Y / 2) - 4 End If If Npc(MapNpc(index).Num).Behavior = NPC_BEHAVIOR_QUEST _ Or Npc(MapNpc(index).Num).Behavior = NPC_BEHAVIOR_SHOPKEEPER _ Or Npc(MapNpc(index).Num).Behavior = NPC_BEHAVIOR_BANKER _ Or Npc(MapNpc(index).Num).Behavior = NPC_BEHAVIOR_GAMBLER Then Call DrawText(TexthDC, TextX, TextY, Trim(Npc(NpcNum).Name), QBColor(BrightCyan)) Else Call DrawText(TexthDC, TextX, TextY, Trim(Npc(NpcNum).Name), Color) End If End Sub Any thoughts or ideas would help! |
|
| Author: | Coke [ Mon Jul 28, 2008 12:55 am ] |
| Post subject: | Re: Blting Errors... Help? |
Its because you can't start blt'ing from a co-ordinate that doesn't exist. |
|
| Author: | Leighland [ Mon Jul 28, 2008 12:57 am ] |
| Post subject: | Re: Blting Errors... Help? |
I figured that was the problem with the paperdoll. Any ideas on the names being weird? |
|
| Author: | Lea [ Mon Jul 28, 2008 12:59 am ] |
| Post subject: | Re: Blting Errors... Help? |
I'm not certain, and cant be bothered to look at the code right now... But I believe the helmet is trying to blit off of the viewable surface, and being dropped all together. If you modify the rect using a DD Clipper (forgot the exact name?) you should be able to do it ok. |
|
| Author: | Leighland [ Mon Jul 28, 2008 1:07 am ] |
| Post subject: | Re: Blting Errors... Help? |
Dave wrote: I'm not certain, and cant be bothered to look at the code right now... But I believe the helmet is trying to blit off of the viewable surface, and being dropped all together. If you modify the rect using a DD Clipper (forgot the exact name?) you should be able to do it ok. Thanks i'll try that |
|
| Author: | GIAKEN [ Mon Jul 28, 2008 6:35 pm ] |
| Post subject: | Re: Blting Errors... Help? |
Why do you minus the text width by 32? Also getSize doesn't return the correct size of text. |
|
| Author: | Leighland [ Mon Jul 28, 2008 11:02 pm ] |
| Post subject: | Re: Blting Errors... Help? |
Because, without it the text alwasy appears 32 pixels to far to the right. I don't know why, but it works for every length of name i've tried it with. I've never been one for math lol |
|
| Author: | Leighland [ Mon Aug 18, 2008 2:36 am ] |
| Post subject: | Re: Blting Errors... Help? |
So i fixed my blting errors FINALLY! I'm so dumb it's almost hilarious. With 32x64 sprites we usually have to blt the top 32x32 and the bottom 32x32, at least thats how I have done it in my source, and probably how most other people do it too. With the helmets, I had them set on the paperdoll sprite sheet so that they spanned 64 pixels... and was blting both parts of the helmet in the same sub. Code: With rec .top = BltF * PIC_Y .Bottom = .top + PIC_Y * 2 .Left = (GetPlayerDir(index) * 3 + Anim) * PIC_X .Right = .Left + PIC_X End With This doesn't work when you move the the y=0 because of how the rec is declared. All I did was create a second sub for BltHelmetTop, copied the code structure from the bltPlayerTop sub and voila! It works |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|