This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Character X,Y position vs. metasprite locations

Character X,Y position vs. metasprite locations
by on (#153091)
Howdy!

I have a question. How do you guys tend to position your metasprites in relation to your character X,Y position?

It seems like there would be advantages and disadvantages to each.

If your x position is in the center, then character flipping is much easier.

If your x position is on the left, then it seems like collision detection math is a little simpler.

If your y position is on the bottom, will this save any calculations for ground checks?

Curious to hear some different opinions on this. I centered my metasprites for animation, but now that I'm doing collision detection, I'm wondering if that was the right call.
Re: Character X,Y position vs. metasprite locations
by on (#153093)
I think you've outlined the important critera already, I don't really have much to add, other than to point out that flipping and collision are related, so centering might help flipped collision as well.

Every game has different needs, so as long as you've got a good idea of what you need and what the consequences are, you should be able to make the right choice.

In my own current game, I usually set the pivot point one pixel below the centre of the sprite. Usually the bounding boxes are symmetrical, so I can use the same ones if the character is flipped or not, and the Y value is ready to test the ground. There are some other reasons I do this, but they're very specific to my game. I also do it differently for some character types, for various reasons. If an object type has unique code it doesn't necessarily need to be set up like the others.
Re: Character X,Y position vs. metasprite locations
by on (#153113)
I tend to place it at bottom-center but have also been wondering which would be the optimal setup. Placing it at one corner of the collision bounding box should make it easier to calculate the bounding box in world coordinates, like you said. I have flipped variations of the metasprites in ROM (ROM space vs CPU usage tradeoff), so the flipping thing you mentioned isn't a problem.

Of course placing the origin at the corner might mean that you will need to adjust the coordinate more in other places (say, to spawn a dust cloud at the player's feet), so yeah, it depends.
Re: Character X,Y position vs. metasprite locations
by on (#153124)
I tend to use the bottom center as the reference point for meta sprites, because that's usually the point of contact with surfaces, but my meta sprite system uses signed offsets for the X and Y of each sprite, so I can have the reference point be anywhere I want. This way I can have sprites with protruding features and still keep the hotspots at the correct positions.