Getting Character Positions Correct

Started by SilverSpook, Sat 18/04/2015 00:51:34

Previous topic - Next topic

SilverSpook

So I'm trying to have a character be sitting at a desk.  The problem is, the room has character scales set to 120 (slightly larger than normal) and I can't figure out where the character will exactly be when he is sitting when I'm setting the room up.  The problem is the scale moves the character, and also I can't figure out how to set the character's animation state to "sitting" in the room editing view.  Right now I'm doing trial-and-error, just running the game, seeing where the character is, then adjusting a bit, running the game again... But there must be another faster way right?  Any help appreciated! 

Ghost

#1
Technically the position of a character is always the centre of their sprite's bottom (in a normal sprite, just between their feet). You should be able to at least find the x position you need very reliably- and then tweak the y axis a little until everything looks smooth.

Since the room preview only allows you to see the character's walk view, one simple workaround would be to replace the first frame of your walkcycle with the sitting sprite, then move it around as required, and then replace the sprites in the view. It's awkward but should get the job done. You can also, in-game, press CTRL D to get exhaustive info about position/frame/state of everything in a room to calculate from that (that's a useful debugger code especially in low-res games where you can count pixels with ease).

I did try out the scale ration btw, and 120 is a relatively weak scale- do you actually need to scale up the character at this point? It's a personal thing but I avoid to put any critical animations in places where characters scale, it often leads to odd results, especially when a scaling character interacts with a non-scaling object.

SilverSpook

Hm, ok thanks for the advice, Ghost. 

Yeah, that's good to know when it's generally not a good idea to try something in AGS if it's going to be more difficult, such as scaling characters.  I'm finding having to backtrack is a real time-sink taking up time I could've been designing!

Thanks!

monkey0506

Code: ags
ViewFrame *frame = Game.GetViewFrame(cEgo.View, cEgo.Loop, cEgo.Frame);
int width = 0;
int height = 0;
if (frame != null)
{
  int scale = cEgo.Scaling;
  width = (Game.SpriteWidth[frame.Graphic] * scale) / 100;
  height = (Game.SpriteHeight[frame.Graphic] * scale) / 100;
}
int xx = cEgo.x - (width / 2);
int yy = cEgo.y - height;


That would give you the coordinates of the top-left corner of the character sprite, accounting for scaling. You could also make some extender methods for easy reuse.

SMF spam blocked by CleanTalk