Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d game, what size should sprites be?

Author
Message
Alaror
13
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 11th May 2011 20:09
I had a basic question about the size of sprites for a 2d game. The world will be built out of blocks of equal size, with the player being a little less than two blocks wide and three blocks high.

I've noticed that many games use sizes which are powers of 2, namely 16x16, 32x32, 64x64, etc. Is there a reason for this? Does it somehow make things easier to draw/program? Would there be any downfall to using 20x20 for the block size?
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 11th May 2011 23:18
Sizes which not the powers of 2 will result in distorted texture both in sprites and 3D. This is due to the way the graphics cards work with the images, and the way how DBP handles sprites as 'locked onto the screen' 3D plains.

So nope, this won't be easier to handle, in fact it is very uncomfortable to work with if your media does not fit into a nice box.

However as i recently discovered, you can work around this by creating an animated sprite! If the sprite is not animated, you just give it flags saying it is one frame both horizontally and vertically, and there you can have a custom sized / resolution sprite.

Also be aware of that there is a paste sprite command, which disables the need of separate sprites for every little aspects of your game. For example if you want to write text using a custom bitmap font, you only need one animated sprite loaded with the bmp containing the predrawn letters, you set the sprite's frame each time, and paste it in the next letter's position.

-In.Dev.X: A unique heavy story based shoot'em ~25%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th May 2011 01:14
It used to be preferable when graphics card memory was at a premium and they worked only in texture sizes to the power of two. Today, even integrated graphics cards do not need this. Very old, cheap cards can still have a problem.

There are two ways to work out whether the user has a problem:

You can work out if your user has a problem by loading an image into a memblock, and checking the size of the memblock. It should be (height * width * 4) + 12 bytes. If it's more, then the card has automatically resized the image to be square and the nearest power of 2. This is a definitive check as you are testing the consequences.

The easier way is to use ONLYSQUARETEXTURES AVAILABLE() and also NONPOWTEXTURES AVAILABLE(). This queries the card and tells you whether it only deals with square textures, and only powers of two. However, I don't know what it will do to the textures on every incompatible card.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th May 2011 05:02
As long as you grab the image with a texture flag of 1 it won't distort the image in any way. If you want to rotate the sprite though you should pick a size that has a center that is equal on all sides (powers of 2). Otherwise it'll look funny rotating on it's not-quite-centered center.

Login to post a reply

Server time is: 2024-11-22 22:05:08
Your offset time is: 2024-11-22 22:05:08