Mirage Source
http://miragesource.net/forums/

[Feature] Dynamic sprite sizes!
http://miragesource.net/forums/viewtopic.php?f=183&t=5047
Page 2 of 63

Author:  Robin [ Tue Feb 03, 2009 10:31 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

jsventor wrote:
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 >.<


The animation code is this part:

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).lHeight
        .Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).lWidth / 12)
    End With

Author:  jsventor [ Tue Feb 03, 2009 10:23 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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

Author:  Robin [ Wed Feb 04, 2009 1:09 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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?

Author:  jsventor [ Wed Feb 04, 2009 1:28 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

Well originally I replaced the original With rec with the one you posted, and no matter where it is, it does the same thing.

Author:  Robin [ Tue Mar 03, 2009 2:23 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

Bumping my own topic. :D

Author:  Rian [ Tue Mar 03, 2009 5:22 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

Robin wrote:
Bumping my own topic. :D

I'll bite.

Nice tutorial Robin. I especially like how how it allows me to cut my sprite file sizes nearly in half.

Author:  DJMaxus [ Fri Mar 06, 2009 4:09 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Matt [ Fri Mar 06, 2009 4:10 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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..

Author:  DJMaxus [ Fri Mar 06, 2009 4:24 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Lochie [ Fri Mar 06, 2009 5:03 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Doomy [ Sun Apr 12, 2009 5:25 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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

Author:  Acruno [ Sun Apr 12, 2009 2:40 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Doomy [ Sun Apr 12, 2009 4:28 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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)

Author:  Robin [ Sun Apr 12, 2009 4:35 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Doomy [ Sun Apr 12, 2009 4:42 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

i thought i did that. Maybe i did it wrong. Ill try it again

Author:  Matt [ Mon Apr 13, 2009 3:02 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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/viewtopic.php?f=124&t=5048&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.

Author:  Doomy [ Mon Apr 13, 2009 3:07 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

that isn't the only thing to fix the dynamic sprites. Ill upload my source with fixed dynamic sprites in a min

Author:  Labmonkey [ Mon Apr 13, 2009 11:26 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

should I add this to Feature-rich mirage? Working of course..

Author:  Acruno [ Mon Apr 13, 2009 11:41 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Robin [ Mon Apr 13, 2009 12:20 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Doomy [ Mon Apr 13, 2009 5:32 pm ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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

Author:  Labmonkey [ Tue Apr 14, 2009 12:35 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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.

Author:  Doomy [ Tue Apr 14, 2009 12:38 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

if you fix it tell me

Author:  Labmonkey [ Tue Apr 14, 2009 12:46 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

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?

Author:  Doomy [ Tue Apr 14, 2009 1:13 am ]
Post subject:  Re: [Feature] Dynamic sprite sizes!

the error im having is wierd and i cannot fix it

Page 2 of 63 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/