Mirage Source

Free ORPG making software.
It is currently Fri Apr 19, 2024 8:24 am

All times are UTC


Forum rules


Make sure your tutorials are kept up to date with the latest MS4 releases.



Post new topic Reply to topic  [ 1557 posts ]  Go to page 1, 2, 3, 4, 5 ... 63  Next
Author Message
PostPosted: Sun Feb 01, 2009 8:53 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
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.

General Change
Replace BltSprite with:

Code:
Private Sub BltSprite(ByVal Sprite As Long, ByVal x As Long, ByVal y As Long, rec As DxVBLib.RECT)
    If Sprite < 1 Or Sprite > NumSprites Then Exit Sub
   
    Call DD_BltFast(x, y, DDS_Sprite(Sprite).Surface, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
End Sub


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:
    'Pre-load graphic to get the width and height used in calculation
    Call DD_ReadySurface("sprites\" & Sprite, DDS_Sprite(Sprite))
   
    Select Case GetPlayerDir(Index)
        Case DIR_UP
            spriteleft = DIR_UP
        Case DIR_RIGHT
            spriteleft = DIR_RIGHT
        Case DIR_DOWN
            spriteleft = DIR_DOWN
        Case DIR_LEFT
            spriteleft = DIR_LEFT
    End Select
   
    With rec
        .Top = 0
        .Bottom = DDS_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDS_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 - ((DDS_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
    ' Is the player's height more than 32..?
    If (DDS_Sprite(Sprite).SurfDescription.lHeight) > 32 Then
        ' Create a 32 pixel offset for larger sprites
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - ((DDS_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)
        End With
        X = 0
    End If

    ' Is player's X more than max map values..?
    If X + (DDS_Sprite(Sprite).SurfDescription.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 - (DDS_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:
    'Pre-load graphic to get the width and height used in calculation
    Call DD_ReadySurface("sprites\" & Sprite, DDS_Sprite(Sprite))
   
    Select Case MapNpc(MapNpcNum).Dir
        Case DIR_UP
            spriteleft = DIR_UP
        Case DIR_RIGHT
            spriteleft = DIR_RIGHT
        Case DIR_DOWN
            spriteleft = DIR_DOWN
        Case DIR_LEFT
            spriteleft = DIR_LEFT
    End Select
   
    With rec
        .Top = 0
        .Bottom = DDS_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDS_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 - ((DDS_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
        ' Is sprite more than 32..?
        If ((DDS_Sprite(Sprite).SurfDescription.lHeight) - 32) > 0 Then
            ' Create a 32 pixel offset for larger sprites
            y = MapNpc(MapNpcNum).y * PIC_Y + MapNpc(MapNpcNum).YOffset - ((DDS_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 + (DDS_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!

_________________
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?


Image


Last edited by Robin on Mon Jun 01, 2009 5:58 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 8:57 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Here it is in action!

Image

Image

_________________
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?


Image


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 9:30 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Jul 24, 2008 6:42 am
Posts: 703
Google Talk: infectiousbyte@gmail.com
Awesome dude. About time someone posted a tut, besides me.

_________________
Image
GIAKEN wrote:
Since I'm into men, not women

GIAKEN wrote:
I can't take these huge penises anymore! All that's left is shame! And blood


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 9:33 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Nean wrote:
Awesome dude. About time someone posted a tut, besides me.


I did tons of work a few years back. Most of the games around have had me do features on them, hence why everyone knows me so well xD I just stopped after a while. DFA motivated me to finish some of my older work though, so you might see some more tutorials being posted by me.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 9:39 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Jul 24, 2008 6:42 am
Posts: 703
Google Talk: infectiousbyte@gmail.com
I'm glad. I can post tutorials on the simple stuff, but stuff like this, I probably wont be able to do for another year or more.

_________________
Image
GIAKEN wrote:
Since I'm into men, not women

GIAKEN wrote:
I can't take these huge penises anymore! All that's left is shame! And blood


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 11:10 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Updated to cover NPCs.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 11:23 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Great job. It's good to see tutorials being written.


Top
 Profile  
 
PostPosted: Sun Feb 01, 2009 11:36 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Screenshot of a few different sprite sizes. I've got an 84x84 unicorn, there's my classic 48x64 RM2K sprites and a small 32x32 RMVX :3

Also shows the NPCs working.

Image

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 3:13 am 
Offline
Knowledgeable
User avatar

Joined: Sun Feb 10, 2008 7:40 pm
Posts: 200
Very nice, this is good for dungeon bosses.

_________________
I is back!


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 1:55 pm 
Offline
Knowledgeable
User avatar

Joined: Fri Feb 02, 2007 4:50 am
Posts: 263
Location: usa michigan centriville
1problem when adding this though for players it works just fine but npcs there characters walk in reverse 0.0 in stead of the spirit there expose to use the rendering reverses there spirits. any idea?


NVM i fixed it heres the fix if it happens to you too.
NPC side fix ^^
Code:
With rec
        .Top = 0
        .Bottom = DDSD_Sprite(Sprite).lHeight
        .Left = (MapNpc(MapNpcNum).Dir * 3 + Anim) * (DDSD_Sprite(Sprite).lWidth / 12)
        .Right = .Left + (DDSD_Sprite(Sprite).lWidth / 12)
    End With


And remove the

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


Its is not needed and you can remove the dim Spiritleft as long as well.^^.

_________________
Fuck? I really joined in 2006.
Spirea, Chat Rooms, Discussions, Help. everything you need in one spot.
http://spirean.com
I love my computer, you never ask for more, you can be my princess or be my whore


Last edited by genusis on Mon Feb 02, 2009 2:12 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 2:09 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Oh yeah, it's this part:

Code:
    Case DIR_UP
            spriteleft = 0
        Case DIR_RIGHT
            spriteleft = 1
        Case DIR_DOWN
            spriteleft = 2
        Case DIR_LEFT
            spriteleft = 3


I set it up like that because my sprite sheet is set up in a different order.

Just change it to:

Code:
    Case DIR_UP
            spriteleft = 0
        Case DIR_RIGHT
            spriteleft = 3
        Case DIR_DOWN
            spriteleft = 1
        Case DIR_LEFT
            spriteleft = 2


Updated the tutorial with the fix. Sorry about that, just copied and pasted it without editing it for Ms4 xD

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 2:13 pm 
Offline
Knowledgeable
User avatar

Joined: Fri Feb 02, 2007 4:50 am
Posts: 263
Location: usa michigan centriville
its ok haha well really you don't have to have the new case stuff ^^ you could remove it. like what i did in my other post i edited it ^^.

You did a good job robin^^. i still get over 200fps even with this added. i just optimize stuff more and more to improve speed so far i have my own roofing tiles and another animation and it goes beyond 200FPS Woot =]

_________________
Fuck? I really joined in 2006.
Spirea, Chat Rooms, Discussions, Help. everything you need in one spot.
http://spirean.com
I love my computer, you never ask for more, you can be my princess or be my whore


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 2:29 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
genusis wrote:
its ok haha well really you don't have to have the new case stuff ^^ you could remove it. like what i did in my other post i edited it ^^.

You did a good job robin^^. i still get over 200fps even with this added. i just optimize stuff more and more to improve speed so far i have my own roofing tiles and another animation and it goes beyond 200FPS Woot =]


I could remove it, but there's really no point removing something that just adds extra functions to the game. Although, moving it to a constant would probably be more optimised.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 2:32 pm 
Offline
Knowledgeable
User avatar

Joined: Fri Feb 02, 2007 4:50 am
Posts: 263
Location: usa michigan centriville
in bltnpc and player for spells you can do this
Player
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

NPC
With rec
.Top = 0
.Bottom = DDSD_Spell(SpellNum).lHeight
.Left = MapNpc(MapNpcNum).SpellAnimations(i).FramePointer * (DDSD_Spell(SpellNum).lWidth / 12)
.Right = .Left + (DDSD_Spell(SpellNum).lWidth / 12)
End With

ya i removed the new cases you added and it seemed to speed the fps up a bit ^^.

_________________
Fuck? I really joined in 2006.
Spirea, Chat Rooms, Discussions, Help. everything you need in one spot.
http://spirean.com
I love my computer, you never ask for more, you can be my princess or be my whore


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 6:22 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
I had this done for Asphodel a while ago :(

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 6:25 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
GIAKEN wrote:
I had this done for Asphodel a while ago :(


I've had it for years. Used to sell it.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 6:27 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Oh...

Well when I release Asphodel people will be like "You got this from Robin lol!!!!!!!!!!!!"

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 6:34 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
GIAKEN wrote:
Oh...

Well when I release Asphodel people will be like "You got this from Robin lol!!!!!!!!!!!!"


Well of course. I'm much more popular than you.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 6:38 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Well my way is different than yours so I'll be ok.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 8:03 pm 
They won't know it's different.. Lol.


Top
  
 
PostPosted: Mon Feb 02, 2009 8:16 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
GIAKEN wrote:
Well my way is different than yours so I'll be ok.


How do you do it different?

The only way to do it is by calculating the size from the sprite images.

_________________
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?


Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 9:55 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
I'll upload the source soon.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Mon Feb 02, 2009 11:01 pm 
Offline
Knowledgeable

Joined: Fri May 18, 2007 9:54 pm
Posts: 234
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 >.<

_________________
Image


Top
 Profile  
 
PostPosted: Tue Feb 03, 2009 12:44 am 
Offline
Regular

Joined: Wed Oct 31, 2007 11:41 pm
Posts: 43
eh had this working in 3.0.3 then my laptop battery died before i had saved it... o well guess i'll just readd in abit


anywayz thanks, nice tut


Top
 Profile  
 
PostPosted: Tue Feb 03, 2009 12:55 am 
You shouldn't use 303.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1557 posts ]  Go to page 1, 2, 3, 4, 5 ... 63  Next

All times are UTC


Who is online

Users browsing this forum: wanai and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group