I Can't See My Sprite (Offsets Tutorial)

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.
Post Reply
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

I Can't See My Sprite (Offsets Tutorial)

Post by Enjay »

One of the most common editing queries that appear on these forums relates to offsets. Usually the question goes something like:
I've put my sprite into my WAD/PK3 and I have put it inside the correct markers/folder and I've done everything you guys told me but when I play the game I can't see my sprite (or my sprite appears in the floor). The actor is there; I can pick it up/bump into it (etc) but I can't see it.
The answer to the problem is sprite offsets. By default, graphics imported into a project from an image file will have no offset stored (effectively they have offset 0,0).

The offsets of a sprite in Doom relate to the position that the sprite will be drawn. With objects that stand in the game world, a point half its width and at height 0 is important; that's where images are drawn from. Perhaps an image...

Image

On the left, the red box shows the position and size of the actor. The width (radius) and height values are defined in the DECORATE or ZScript definition of your actor. However, the sprite has offsets 0,0 and so is positioned below and to the right of the actor. Having offset 0,0 means that the image is drawn downwards and to the right of the middle-bottom of the actor. In other words, it's in the floor.

On the right is the intended situation: actor and sprite of similar size and in the same position.

It is worth emphasising that the the physical position of the actor (red box) can be quite different to visual position (green box) of the graphic/sprite due to its offsets. That's why you might be able to bump into your actor even if you cant see it.

So, how does offset 0,0 look in game?:

Software renderer:
Image
OMG my kewl rad suit is in the ground and off to one side. That's not what I want.

Hardware (OpenGL) renderer:
Image
OMG OMG my sprite isn't even there. (It is, you just can see it.)

In both cases, the actor is present and in the right place. Why is there a difference between software and hardware? Software can render sprites below the floor. In fact, most of the original sprites have offsets that put the bottom of the sprite slightly below the floor. This is probably a deliberate decision to try and make them look as if they are not standing on tip-toes etc.

Here is an example of somewhere that it can be seen quite easily. Doom2 MAP02 using the software renderer:

Image

However, hardware (OpenGL) cannot render things under the floor so they just get cut off. Hardware would cut off the toes of the zombieman and the bottom of the health potions (GZDoom has sprite-clipping options in its menu to compensate for this). If the sprite is completely below the floor (offset 0,0 for example), you won't see it at all. There's more on this in the old infographics at the end of this post.

So, How Do We Fix This?

You need a tool that can modify offsets. There are a number of options here but Slade is probably the most commonly used one. Forum thread: viewtopic.php?t=24955

Load your WAD/PK3 up in Slade and select your graphic. I've cropped the images for forum spacing sanity.

Image
There's my sprite in all it's glory (thanks Mars3D) but look at the offsets below it: 0,0. See also how its top left is at the centre of the crosshair? When Slade is in sprite mode, the crosshair is centred on the middle, bottom of where the actor would be (remember my very first image?).

See also the button to the right of the word "Auto"? We can use that to generate our sprite offsets or we can enter them manually by typing in the boxes that currently say 0 (or by using the little arrow scrollers beside them).

So, let's press that button:

Image
Here we are, and we have some options. Generally, for an item standing in the world, you'll want to use the "Monster" or "Monster (GL-friendly)" options. The other options are very useful, but not what we are talking about right now. What's the difference between the two "Monster" options? Remember what I said about sprites tending to have their bottom few pixels below the floor? That's how "Monster" sets things up. Remember how I said hardware cannot render things below the floor? "GL-friendly" positions the sprite so that nothing is below the floor.

Good offsets are typically an X value of half the sprite's width and a Y value that is the same as its full height for "GL-friendly" or 3 or 4 pixels less than its full height for "Monster"-like offsets.

I picked Monster (GL-friendly):

Image
My graphic is 34x57 and Slade auto-chose offsets of X17, Y57 for me. This is fine for a nice, symmetrical sprite. See how the suit is now standing on the crosshair and centred on it in the X direction? Perfect!

Save your file and test.

Here is the file with the above offsets in game:

Software:
Image

Hardware:
Image

Image Yay! Success. Image Note, nothing is different in these images versus the earlier ones other than the sprite offsets. That's all that was wrong.




So, those are the basics...


________________________________________________


Extra Stuff

If the graphic is an asymmetrical one (e.g. with a monster standing off to one side while firing) you may want/need to adjust the X value to make the image look more centred on the centre line of the Slade crosshair. Slade has no way of knowing if your graphic is asymmetrical so it cannot compensate for that. If you are using automatic sprite offsets in Slade, it will centre the sprite. Even with asymmetrical images, the automatic values give you a good starting point for you to then tweak the offsets as you see fit.

As an example from DOOM2.WAD, the revenant can be seen to skip around a bit while swinging his arm. Consider this image of the revenant punch attack. The offsets are those found in the IWAD (i.e. the ones that id software set.):

Image
As you can see, the revenant's body is way over to one side compared to the centre line.

Perhaps offset's something like this would have been more suitable:
Image
DO NOT MODIFY YOUR IWAD If you want to modify sprites from your IWAD, extract them to a PWAD. Modify them there and then load the PWAD when you play.


Projectiles tend to have different offsets (they tend to be centred on the crosshair in Slade (offsets of half their width and half their height are typical)).

Image
Arctangent wrote:I should point out that the way projectiles are offset is actually pretty dumb. Projectiles don't magically extend their vertical hitbox from their "center," so putting the center of the spirte at y0 means that half of the sprite is in the hitbox, half of it isn't, and there's possibly quite a bit of hitbox that has no sprite as part of it.

I imagine the reason why projectiles are offset like that in the base games is to help make them appear from the proper height and to make it harder for them to block the player's vision after launch. In ZDoom, that's not exactly necessary since you can change the offset of the projectile itself, however.

Weapons are quite different (and outwith the scope of this tutorial).

Slade can also be very useful for setting up large numbers of sprites and comparing consecutive animations. Because the crosshair is always centred in the same place, you can see how your sprite will look as it cycles through its various frames by selecting consecutive images.

e.g. here's how the player sprite looks using the Doom2 offsets it was given by id.

Image
Very nice. Arguably he could be slightly more to the left but the two firing frames line up perfectly.

and here's how it looks after I deliberately gave PLAYF1 a bad X offset (I moved it right by 1 unit).

Image
In this case, in game the player would look as if he was jiggling around a little as he fired his weapon.


And, for completeness, I may as well post a couple of ancient infographics that I made a long time ago that help illustrate the difference between Monster-like and GL-friendly-like offsets (and a couple of other things too, such as relation to actor size):

Image

Image
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Nash »

Sweet, detailed tutorial Enjay, thanks for putting this up because yes, it is a very common problem that even til this day sometimes gets even me (I get impatient to test stuff and had forgotten to set the offsets of my newly imported sprites - d'oh!). :D
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Enjay »

Thanks. I figured that it's probably something that most of the long-term forum members have explained to someone at least once in the past so I thought it would be useful to put up a tutorial that people could link to instead.
User avatar
ReX
Posts: 1578
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by ReX »

Enjay wrote:A bunch of stuff that is very informative but must have taken a shit-load of time to pull together.
Sounds like summer vacation has begun in the educational institutions of the Highlands.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Enjay »

Not yet. I was actually procrastinating. I have a bunch of reports to write this weekend. :?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Arctangent »

I should point out that the way projectiles are offset is actually pretty dumb. Projectiles don't magically extend their vertical hitbox from their "center," so putting the center of the spirte at y0 means that half of the sprite is in the hitbox, half of it isn't, and there's possibly quite a bit of hitbox that has no sprite as part of it.

I imagine the reason why projectiles are offset like that in the base games is to help make them appear from the proper height and to make it harder for them to block the player's vision after launch. In ZDoom, that's not exactly necessary since you can change the offset of the projectile itself, however.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Enjay »

Good point. I keep forgetting that projectiles are set up like that. It doesn't make anything I said wrong, but it is certainly useful information to keep in mind.

I've edited the tutorial to quote your post in the relevant section. Thanks. :D
User avatar
unRyker
Posts: 170
Joined: Tue Jul 28, 2015 6:30 am
Location: United States
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by unRyker »

You definitely took some time with this tutorial to make it nice, simple to follow and clean... Have you considered making this an all-in-one tutorial with tips for weapon offsets and more? I always seem to have difficulty lining up the muzzle-flash quickly and efficiently in particular.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Enjay »

The main reason I didn't cover weapons is that they have always been a bit trial and error for me too.
User avatar
Rachael
Posts: 13532
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Rachael »

With centered weapons, find the bottom and center point of your weapon, then apply the following math to your offsets:
x -= 160;
y -= 200;
This puts the offset in the upper-left corner of the screen on a 320x200 display, as is present in Vanilla Doom.

With weapons coming in from the right side of the screen, find the lower-right corner of the weapon (assuming 4:3, unfortunately - you will have to adjust for widescreen sprites), apply the offset, and then use the following math to adjust the offsets:
x -= 320;
y -= 200;

The same thing for weapons coming in from the left side, except you find the lower-left corner (again, assuming 4:3) and subtract nothing from X.

As you can see, in all 3 cases, y is always subtracted by 200.
Gez
 
 
Posts: 17834
Joined: Fri Jul 06, 2007 3:22 pm

Re: I Can't See My Sprite (Offsets Tutorial)

Post by Gez »

Arctangent wrote:I should point out that the way projectiles are offset is actually pretty dumb. Projectiles don't magically extend their vertical hitbox from their "center," so putting the center of the spirte at y0 means that half of the sprite is in the hitbox, half of it isn't, and there's possibly quite a bit of hitbox that has no sprite as part of it.

I imagine the reason why projectiles are offset like that in the base games is to help make them appear from the proper height and to make it harder for them to block the player's vision after launch. In ZDoom, that's not exactly necessary since you can change the offset of the projectile itself, however.
I think the real reason is to avoid having a projectile moving vertically as it changes size. Consider the following animation, with projectile offsets:

Image

Now let's look at it, but with monster offsets:
Image

See how it climbs up when it explodes? It'll be even worse if the sprite changes size as it moves. Here's a good example with arachnotron plasma:
Image
Look at the one on the left bobbing up and down annoyingly, it's aligned to the bottom like a good monster sprite. Now look at the one on the right that looks shiny and perfect, it's aligned incorrectly on the center and therefore technically wrong, but it looks so much better!
Post Reply

Return to “Tutorials”