Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Feature] Dynamic sprite sizes!
#26
[quote="jsventor"]I added this and everything is working except for the walking animations, the frames dont change, and I have no Idea what it could be, I spent about 20 minutes looking >.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#27
yea got that, heres my sub,

Code:
Public Sub BltPlayer(ByVal Index As Long)
Dim Anim As Byte
Dim i As Long
Dim SpellNum As Long
Dim X As Long
Dim Y As Long
Dim Sprite As Long, spriteleft As Long
Dim rec As DXVBLib.RECT

    Sprite = GetPlayerSprite(Index)

    ' Check for animation
    Anim = 0
    If Player(Index).Attacking = 0 Then
Select Case GetPlayerDir(Index)
        Case DIR_UP
            spriteleft = 0
        Case DIR_RIGHT
            spriteleft = 3
        Case DIR_DOWN
            spriteleft = 1
        Case DIR_LEFT
            spriteleft = 2
    End Select
  
    With rec
        .Top = 0
        .Bottom = DDSD_Sprite(Sprite).lHeight
        .Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).lWidth / 12)
    End With
    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
    
    X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset - ((DDSD_Sprite(Sprite).lWidth / 12 - 32) / 2)
    If ((DDSD_Sprite(Sprite).lHeight) - 32) > 0 Then
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - ((DDSD_Sprite(Sprite).lHeight) - 32)
    Else
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset
    End If
    
    ' Check if its out of bounds because of the offset
     ' Is player's Y less than 0..?
    If Y < 0 Then
        With rec
            .Top = .Top - Y
        End With
        Y = 0
    End If

    ' Is player's X less than 0..?
    If X < 0 Then
        With rec
            .Left = .Left + (X * -1)
            '.Right = .Left + 48 - (x * -1)
        End With
        X = 0
    End If

    ' Is player's X more than max map values..?
    If X + (DDSD_Sprite(Sprite).lWidth / 12) > MAX_MAPX * 32 + 32 Then
        With rec
            .Right = .Right + (X - (MAX_MAPX * 32))
        End With
    End If
        
    Call BltSprite(Sprite, X, Y, rec)
    
    ' ** Blit Spells Animations **
    For i = 1 To MAX_SPELLANIM
        SpellNum = Player(Index).SpellAnimations(i).SpellNum
        
        If SpellNum > 0 Then
        
            If Player(Index).SpellAnimations(i).Timer < GetTickCount Then
            
                Player(Index).SpellAnimations(i).FramePointer = Player(Index).SpellAnimations(i).FramePointer + 1
                Player(Index).SpellAnimations(i).Timer = GetTickCount + 120
                
                If Player(Index).SpellAnimations(i).FramePointer >= DDSD_Spell(SpellNum).lWidth \ SIZE_X Then
                    Player(Index).SpellAnimations(i).SpellNum = 0
                    Player(Index).SpellAnimations(i).Timer = 0
                    Player(Index).SpellAnimations(i).FramePointer = 0
                End If

            End If
        
            If Player(Index).SpellAnimations(i).SpellNum > 0 Then
                With rec
.Top = 0
.Bottom = DDSD_Spell(SpellNum).lHeight
.Left = Player(Index).SpellAnimations(i).FramePointer * (DDSD_Spell(SpellNum).lWidth / 12)
.Right = .Left + (DDSD_Spell(SpellNum).lWidth / 12)
End With
        
                Call BltSpell(Spell(SpellNum).Pic, X, Y, rec)
            End If
            
        End If
    Next
End Sub
Reply
#28
Why have you put;

Code:
With rec
        .Top = 0
        .Bottom = DDSD_Sprite(Sprite).lHeight
        .Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).lWidth / 12)
    End With

In the stepping code?

How about reading the actual tutorial?
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#29
Well originally I replaced the original With rec with the one you posted, and no matter where it is, it does the same thing.
Reply
#30
Bumping my own topic. Big Grin
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#31
Robin Wrote:Bumping my own topic. Big Grin
I'll bite.

Nice tutorial Robin. I especially like how how it allows me to cut my sprite file sizes nearly in half.
Reply
#32
Whenever I try to compile this feature with a fresh copy of MS4 (3.77), I get the "Sub or Function not defined" Compile error.

"DDSD_Sprite" is the resulting text that is highlighted. I can't seem to figure this out, I'm sure someone else has?

Edit : Wow, I can't believe I waited this long to post something.
Reply
#33
DJMaxus Wrote:Whenever I try to compile this feature with a fresh copy of MS4 (3.77), I get the "Sub or Function not defined" Compile error.

"DDSD_Sprite" is the resulting text that is highlighted. I can't seem to figure this out, I'm sure someone else has?

Pretty sure it's DDS_Sprite..
Reply
#34
Matt Wrote:
DJMaxus Wrote:Whenever I try to compile this feature with a fresh copy of MS4 (3.77), I get the "Sub or Function not defined" Compile error.

"DDSD_Sprite" is the resulting text that is highlighted. I can't seem to figure this out, I'm sure someone else has?

Pretty sure it's DDS_Sprite..
Thank you! That got rid of the DDS error, now it's giving me the "Method or data member not found" and it's highlighting ".lHeight" Though I see it used in other places in the source. I appreciate the responses.
Reply
#35
It's slightly different now, lheight is notdeclared yet. You'll have to declare them when you load the surface.

Robin is going to update this tutorial when he has free time, I believe.
Reply
#36
Hey well im just going through all the tutorials and imma fix them. But i've got stuck on this. anyone care to help?

its in

Public Sub BltNpc(ByVal MapNpcNum As Long)

Quote: ' Check to see if we want to stop making him attack
With MapNpc(MapNpcNum)
' Calculate X
X = .X * PIC_X + .XOffset - ((DDS_Sprite(Sprite).lWidth / 12 - 32) / 2)
' Is sprite more than 32..?
If ((DDS_Sprite(Sprite).lHeight) - 32) > 0 Then
' Create a 32 pixel offset for larger sprites
Y = MapNpc(MapNpcNum).Y * PIC_Y + MapNpc(MapNpcNum).YOffset - ((DDS_Sprite(Sprite).lHeight) - 32)
Else
' Proceed as normal
Y = MapNpc(MapNpcNum).Y * PIC_Y + MapNpc(MapNpcNum).YOffset
End If
End With

Meathod or data member not found
Reply
#37
Lochie Wrote:It's slightly different now, lheight is notdeclared yet. You'll have to declare them when you load the surface.

Robin is going to update this tutorial when he has free time, I believe.

1 post above you Doomy. Read.
Reply
#38
i did and i have talked to robin. He said he was going to do it li ke a month ago. So i doubt that he is going to do it soon. (Sorry robin)
Reply
#39
When I wrote this tutorial, we were still using the default surfaces. Now Dmitry has written in a custom surface type. You need to declare a new variable in there to store width/height.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#40
i thought i did that. Maybe i did it wrong. Ill try it again
Reply
#41
Robin Wrote:Dynamic sprite sizes! Now 100% free!

Basically, this system is a more generic BltPlayer and DrawPlayerName subroutine fix, which calculates the size of the sprite by the width and height of the image file which is loaded. This will only work with a sprite system that houses each sprite in a seperate file, but in the default Mirage layout.

It's a very easy fix, and I'm really not sure how anyone could have trouble adding it.

Players
BltPlayer Subroutine:

Find;
Code:
Dim Sprite As Long

and replace with;
Code:
Dim Sprite As Long, spriteleft As Long

Find;
Code:
.Top = 0

and replace that entire block with;
Code:
Select Case GetPlayerDir(Index)
        Case DIR_UP
            spriteleft = 0
        Case DIR_RIGHT
            spriteleft = 3
        Case DIR_DOWN
            spriteleft = 1
        Case DIR_LEFT
            spriteleft = 2
    End Select
    
    With rec
        .Top = 0
        .Bottom = DDSD_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
    End With

Find;
Code:
X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset

and replace that entire block with;
Code:
' Calculate the X
    X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset - ((DDSD_Sprite(Sprite).lWidth / 12 - 32) / 2)
    ' Is the player's height more than 32..?
    If ((DDSD_Sprite(Sprite).lHeight) - 32) > 0 Then
        ' Create a 32 pixel offset for larger sprites
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - ((DDSD_Sprite(Sprite).SurfDescription.lHeight) - 32)
    Else
        ' Proceed as normal
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset
    End If

Find;
Code:
If Y < 0 Then

and replace that entire block with;
Code:
' Is player's Y less than 0..?
    If Y < 0 Then
        With rec
            .Top = .Top - Y
        End With
        Y = 0
    End If

    ' Is player's X less than 0..?
    If X < 0 Then
        With rec
            .Left = .Left + (X * -1)
            '.Right = .Left + 48 - (x * -1)
        End With
        X = 0
    End If

    ' Is player's X more than max map values..?
    If X + (DDSD_Sprite(Sprite).lWidth / 12) > MAX_MAPX * 32 + 32 Then
        With rec
            .Right = .Right + (X - (MAX_MAPX * 32))
        End With
    End If

That finishes the BltPlayer stuff! Basically, the Spriteleft is just a system I made so the sprite layout doesn't have to be Up, Down, Left, Right. The X, Y and REC edits are just changing it so instead of assuming the sprite is 32x32, it reads the values from the sprite surface. The height is set to the height of the surface, and the width is set to the width of the surface divided by 12, which is the amount of different sprite frames are set in one surface. Very simple.

Now, we edit the name code.

DrawPlayerName Subroutine:

Find;
Code:
TextY = GetPlayerY(Index) * PIC_Y

and replace with;
Code:
TextY = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - (DDSD_Sprite(GetPlayerSprite(Index)).SurfDescription.lHeight) + 16

Again, we're just using the height of the surface to calculate how high it should be, then removing 16 pixels, because we need to ;D

None Player Characters
BltNPC Subroutine:

Find;
Code:
Dim Sprite As Long

and replace with;
Code:
Dim Sprite As Long, spriteleft As Long

Find;
Code:
.Top = 0

and replace entire block with;
Code:
Select Case MapNpc(MapNpcNum).Dir
        Case DIR_UP
            spriteleft = 0
        Case DIR_RIGHT
            spriteleft = 3
        Case DIR_DOWN
            spriteleft = 1
        Case DIR_LEFT
            spriteleft = 2
    End Select
    
    With rec
        .Top = 0
        .Bottom = DDSD_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
    End With

Find;
Code:
With MapNpc(MapNpcNum)

and replace entire block with;
Code:
With MapNpc(MapNpcNum)
        ' Calculate X
        X = .X * PIC_X + .XOffset - ((DDSD_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
        ' Is sprite more than 32..?
        If ((DDSD_Sprite(Sprite).SurfDescription.lHeight) - 32) > 0 Then
            ' Create a 32 pixel offset for larger sprites
            Y = MapNpc(MapNpcNum).Y * PIC_Y + MapNpc(MapNpcNum).YOffset - ((DDSD_Sprite(Sprite).SurfDescription.lHeight) - 32)
        Else
            ' Proceed as normal
            Y = MapNpc(MapNpcNum).Y * PIC_Y + MapNpc(MapNpcNum).YOffset
        End If
    End With

Find;
Code:
If Y < 0 Then

and replace entire block with;
Code:
' Is player's Y less than 0..?
    If Y < 0 Then
        With rec
            .Top = .Top - Y
        End With
        Y = 0
    End If

    ' Is player's X less than 0..?
    If X < 0 Then
        With rec
            .Left = .Left + (X * -1)
            '.Right = .Left + 48 - (x * -1)
        End With
        X = 0
    End If

    ' Is player's X more than max map values..?
    If X + (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12) > MAX_MAPX * 32 + 32 Then
        With rec
            .Right = .Right + (X - (MAX_MAPX * 32))
        End With
    End If

Same things happening as last time, just updated syntax for the MapNPC variables.

That's it! Enjoy your new dynamically driven system.

This feature only uses one subroutine for the rendering of the player, meaning you'll have clipping issues unless you use a Y-based sprite rendering system. You can find my quick tutorial on how to make this by following this link;
http://web.miragesource.com/forums/viewt...48&start=0

Can use this tutorial freely in your game/engine, as long as you don't claim it as your own. That means you, Frozengod!

That should work with the new version of MS4. For those of you who can't see what I changed:

Find any instance of DDS_Sprite(Sprite).lWidth and DDS_Sprite(Sprite).lHeight and change them to:

Code:
DDS_Sprite(Sprite).SurfDescription.lWidth
DDS_Sprite(Sprite).SurfDescription.lHeight

Good luck. Tested it for Doomy, worked, but in the source he sent me, the sprites weren't animated.
Reply
#42
that isn't the only thing to fix the dynamic sprites. Ill upload my source with fixed dynamic sprites in a min
Reply
#43
should I add this to Feature-rich mirage? Working of course..
Reply
#44
Labmonkey Wrote:should I add this to Feature-rich mirage? Working of course..

Definitely. There is absolutely no reason why you shouldn't when it's working.
Reply
#45
Labmonkey Wrote:should I add this to Feature-rich mirage? Working of course..

Along with the y-based rendering system, there is no reason this shouldn't be added.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#46
well don't add it yet. Im currently getting spamed with an error and i don't know what to do. When i fix it ill tell you how i did.


(DD_BltFast) Error Rendering Graphics: The provided rectangle was invalid.

i keep getting that error in the chat box if you wish to help
Reply
#47
There is a bit of a problem with this and fringe tiles. I am gana work out a new loop for that in a bit.
Reply
#48
if you fix it tell me
Reply
#49
I just did, but I realized that it will only work with certain tiles (in particular, rmvx as the trees have only 1 tile in fringe), therefore I wont release. If you really want to do this then you need to make trees not tiles, but objects.


Then again, who thinks that trees should be objects (select a tree attribute tile) and not tiles in feature-rich mirage?
Reply
#50
the error im having is wierd and i cannot fix it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)