Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: twentyfour on Mon 04/05/2009 01:14:57

Title: Sprite centre issue
Post by: twentyfour on Mon 04/05/2009 01:14:57
Egads, another Character importing issue!

I have my main character all set up to walk around, no issues there(so far) and now that I've added in a profile talking anim I find the talking anim is cropped nice and snug against the characters ass end where the walking anim isn't cropped as tightly so when it's time to talk my lil buddy shifts back a few pixels, says his piece and pops back from whence he came.

This cropping of each frame of anim is getting a bit frustrating for me right now, is there an easier way of doing this than using a mouse with a steady STEADY hand. I want to have nice broad gestures with my characters so I won't always have the option of reusing a form fitting crop mask from the previous frame... it just feels so tedious and clunky compared to everything else I've been slowly learnin this past month or so.

Sorry if this has been answered a couple hundred times. I did a quick forum search earlier today and another a few minutes ago. Nothing seems to answer my problem that I've seen.

So, is this gonna be a "Sorry kid, them's the breaks" or "[link] try searching HARDER next time 24!"?
Title: Re: Sprite centre issue
Post by: GarageGothic on Mon 04/05/2009 01:29:16
For incidental animations, you can use Character.LockViewAligned and Character.LockViewOffset to position the sprite. However if you want to use AGS' own handling of talking and idle views instead of writing new functions (that call LockViewOffset first), the only way to go around it is adding some transparent pixels on the side of the character so that the character stays at the center of the sprite. For instance, if he stretches out his left arm (from our point of view) you would have to add the same extra width to the right side of the sprite.
Title: Re: Sprite centre issue
Post by: twentyfour on Mon 04/05/2009 20:30:31
Okay so 4 or 5 attempts later and I have the talking character lined up well enough that when the talk anim starts he doesn't shift... UNLESS he's facing left! Then the flipped anim shifts him backwards. So now I need to jigger with a left facing anim and import it separately so he doesn't shift when he talks?

I'm assuming this whole process is much easier when using simpler characters. I'm doing cleanup and animation in Flash so adjusting pixel by pixel blindly hasn't been fun.

Can anyone direct me to a tutorial that covers this sort of issue? I think I might have figured some of it out based on what GG said but I wanna make sure I'm not digging a bigger hole for myself down the road.
Title: Re: Sprite centre issue
Post by: Khris on Mon 04/05/2009 22:00:37
If a flipped character sprite makes the character shift, the pixels that make up the character weren't in the sprite's center to begin width.

You have to fix that before anything else. It'll screw up walkable areas and probably all kinds of other stuff.
The technical position of a character is at the bottom center of the sprite, so that's were their feet have to be.
Title: Re: Sprite centre issue
Post by: Trent R on Tue 05/05/2009 00:55:07
Couldn't the onion skins help you center it?

~Trent
Title: Re: Sprite centre issue
Post by: twentyfour on Tue 05/05/2009 15:51:42
I'm using the exact same start pose as the walking anim but the size of the stage has changed because the walk is quite broad while the talk is just a slight lean and nodding head. The character is a snake I posted earlier in the critique forum so defining "feet" is a bit of an issue.

I just popped on the 1x1 pixel grid in Flash and have snap to grid set on as well. Hopefully I can figure this out but if anyone wants to see the flas I can email em to ya.

Also, I tried using the "crop sprite edges" in AGS... still tinkering to see if it's helpful or not so far

Title: Re: Sprite centre issue
Post by: Khris on Tue 05/05/2009 17:24:59
Seeing the sprites would be a big help for us. Unfortunately, the server seems to be down. I can't see the sprites or your avatar.
Title: Re: Sprite centre issue
Post by: twentyfour on Tue 05/05/2009 19:35:23
(http://www.daverigley.com/nonamegamepics/MOEwalk2.gif)

(http://www.daverigley.com/nonamegamepics/MOEtalk.gif)

Forgive the colours, its a quick gif export from Flash while I'm workin on paid stuff.

I can see problems right away just comparing them like this. But I used the crop edges to shave the walk down to it's minimum and crop edges symmetric on the talky. As you can see I actually tried measuring out the talker. With the walk I thought invisible pixels meant non-existant so the program would auto crop to the character since the pink pixels "don't exist" 

I have flash files where I'm re-measuring with the pixel grid right now but if you can tell me what went wrong here maybe it'll save me some time later tonight
Title: Re: Sprite centre issue
Post by: Vince Twelve on Tue 05/05/2009 22:02:21
AGS uses the exact center of the sprite to decide where to draw the character.  For example, if the character is standing on the spot x=100 y=150, and the sprite is 40 pixels wide, then it will draw the sprite centered on x=100 with the bottom of it at y=150.  This means that the left of the sprite will be drawn at x=100-(40/2)=80.

If you then change to an animation that is 150 pixels wide, those frames are going to be drawn with their lefts at x=100-(150/2)=25.  So if the character wasn't centered in the same way in the two different-width animations, then he will appear to jump around.

Here's your characters with lines drawn down the center of the sprites.  This center line will determine where the character is "drawn" on the screen.  So if we overlay them, you'll see how they will look if you switch between them.  Obviously, they're going to jump around.

This is easy to see if we center the images you've shown us on the screen:



The center point of your walking animation's standing frame is on his head.
(http://www.xiigames.com/misc/snake1.png)

But the center point of the talking animation is on the middle of his body.  (which is probably where it should be)
(http://www.xiigames.com/misc/snake2.png)

Laying them on top of each other, aligning the center points shows how they would jump around if you switch between the views.
(http://www.xiigames.com/misc/snake3.png)

In my opinion, you need to add a bunch of pixels to the left side of that walking animation to move that center point over to the left to match the talking animation.

To avoid this, figure out what you want the center (pivot point) of the standing frames should be (such that if you switch between them it looks like the character is turning around).  Then for all other animations keep the character centered in the same way (if the head is in the middle, it should always be in the middle, if the middle of the snakes back is in the middle of the frame, it should always be in the middle). 

The easiest way is just to center your standing pose how you want it and then draw all the character's animations off of the same standing pose, making sure that if you add pixels to one side of any frame, that you add the same number of pixels to the other side, even if they're blank pixels.  This is necessary to make sure that the center point remains the same.

Side Note: With really wide characters like this, you're going to have to be careful with walkable areas, since he's going to reach way beyond the walkable area.  The center point will go all the way to the edge of a walkable area, the rest of his body will stretch beyond it.  So, if he's the playable char, you'll need to adjust the walkable areas accordingly by making them reach not quite all the way to the edge of the room.  Otherwise, it'll look like he's walking through a wall.
Title: Re: Sprite centre issue
Post by: twentyfour on Wed 06/05/2009 00:08:54
I don't know why this has been so tough for me to grasp. Everyone's pretty much repeating the same answer, so obvious that's the right one :D

The only thing I'd changed beyond what you've seen already to what I'm dealing with in AGS is the right-click 'crop edges' after importing them, I think that may be my failing(Aside from, y'know, planning properly)

Okay, I'll re-work the walking anim. My only concern there now is if I need extra pixels to counter any stretching out he does in his walk... how do I import him without ending up with nearly triple the pixels used in his first pose before the big stretch? Import it frame by frame managing the pink area by hand beforehand?

Thanks for the advice guys, I appreciate it. And sorry if I'm coming across thick-headed here, I think I've been lookin at the problem from the wrong angle.
Title: Re: Sprite centre issue
Post by: RickJ on Wed 06/05/2009 00:28:08
You may find Graphics Gale helpful in adjusting your sprites.  It's free and I find it invaluable in creating animations for AGS.   

http://www.humanbalance.net/gale/us/
Title: Re: Sprite centre issue
Post by: Khris on Wed 06/05/2009 00:57:03
The Crop sprite edges feature is pretty useful, although it can screw up things pretty good if it isn't handled right.

Say you've got the animation frames for an object, and say you want to crop all the frames to save some HD space. It's very important that you do select all frames, then crop them in one go, so AGS can check which sprite extends the most to each of the four sides and cuts that amount of pixels off all other frames, too.

(Only if the amount of transparent columns/rows is the same for all left sides/bottoms, you can safely crop the sprites individually to save even more memory, since objects are positioned using the lower left corner.)

Cropping the edges symmetrically essentially does the same but keeps the sprites' horizontal center.
So ideally you'd select all the frames of any loop of a character, then crop them symmetrically.
The sprites won't all have the same width afterwards but their bottom centers will still be aligned properly.