![]() |
[Feature] Dynamic sprite sizes! - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51) +----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44) +------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13) +------ Thread: [Feature] Dynamic sprite sizes! (/showthread.php?tid=2543) |
[Feature] Dynamic sprite sizes! - Robin - 01-02-2009 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) 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 Find; Code: X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset and replace that entire block with; Code: ' Calculate the X Find; Code: If Y < 0 Then and replace that entire block with; Code: ' Is player's Y less than 0..? 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 Find; Code: With MapNpc(MapNpcNum) and replace entire block with; Code: With MapNpc(MapNpcNum) Find; Code: If Y < 0 Then and replace entire block with; Code: ' Is player's Y less than 0..? 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! Re: [Feature] Dynamic sprite sizes! - Robin - 01-02-2009 Here it is in action! ![]() ![]() Re: [Feature] Dynamic sprite sizes! - Nean - 01-02-2009 Awesome dude. About time someone posted a tut, besides me. Re: [Feature] Dynamic sprite sizes! - Robin - 01-02-2009 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. Re: [Feature] Dynamic sprite sizes! - Nean - 01-02-2009 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. Re: [Feature] Dynamic sprite sizes! - Robin - 01-02-2009 Updated to cover NPCs. Re: [Feature] Dynamic sprite sizes! - Jacob - 01-02-2009 Great job. It's good to see tutorials being written. Re: [Feature] Dynamic sprite sizes! - Robin - 01-02-2009 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. ![]() Re: [Feature] Dynamic sprite sizes! - timster0 - 02-02-2009 Very nice, this is good for dungeon bosses. Re: [Feature] Dynamic sprite sizes! - genusis - 02-02-2009 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 And remove the Code: Select Case GetPlayerDir(Index) Its is not needed and you can remove the dim Spiritleft as long as well.^^. Re: [Feature] Dynamic sprite sizes! - Robin - 02-02-2009 Oh yeah, it's this part: Code: Case DIR_UP 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 Updated the tutorial with the fix. Sorry about that, just copied and pasted it without editing it for Ms4 xD Re: [Feature] Dynamic sprite sizes! - genusis - 02-02-2009 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 =] Re: [Feature] Dynamic sprite sizes! - Robin - 02-02-2009 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 ^^. 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. Re: [Feature] Dynamic sprite sizes! - genusis - 02-02-2009 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 ^^. Re: [Feature] Dynamic sprite sizes! - GIAKEN - 02-02-2009 I had this done for Asphodel a while ago ![]() Re: [Feature] Dynamic sprite sizes! - Robin - 02-02-2009 GIAKEN Wrote:I had this done for Asphodel a while ago I've had it for years. Used to sell it. Re: [Feature] Dynamic sprite sizes! - GIAKEN - 02-02-2009 Oh... Well when I release Asphodel people will be like "You got this from Robin lol!!!!!!!!!!!!" Re: [Feature] Dynamic sprite sizes! - Robin - 02-02-2009 GIAKEN Wrote:Oh... Well of course. I'm much more popular than you. Re: [Feature] Dynamic sprite sizes! - GIAKEN - 02-02-2009 Well my way is different than yours so I'll be ok. Re: [Feature] Dynamic sprite sizes! - Matt - 02-02-2009 They won't know it's different.. Lol. Re: [Feature] Dynamic sprite sizes! - Robin - 02-02-2009 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. Re: [Feature] Dynamic sprite sizes! - GIAKEN - 02-02-2009 I'll upload the source soon. Re: [Feature] Dynamic sprite sizes! - jsventor - 02-02-2009 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 >. Re: [Feature] Dynamic sprite sizes! - james1992_2006 - 03-02-2009 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 Re: [Feature] Dynamic sprite sizes! - Matt - 03-02-2009 You shouldn't use 303. |