Relative X and Y

Started by Glenjamin, Sat 01/08/2015 19:12:31

Previous topic - Next topic

Glenjamin

I'm trying to fix the animations in my game so the character doesn't jump around due to the varying sprite sizes. I know I can do this with the .move function, but how can I set the X and Y to be relative to the character?

Khris

You can't do this; you need to import pre-aligned sprites. For characters, the pivot is at the bottom center, so they don't even have to be the same size, as long as the character is centered at the bottom.

Glenjamin

Theres absolutely no way? I cant say something like cego.move(cegoX-12,cegoY-12,eanywhere,eblock)>

Grok

Quote from: Gfreezie on Mon 03/08/2015 03:00:50
Theres absolutely no way? I cant say something like cego.move(cegoX-12,cegoY-12,eanywhere,eblock)>

Most things are possible. You could even write your own "walk to"-function with offset possibilities for individual frames (provided that you have the know-how). Sometimes it is just more work than it is worth.

The easy obvious solution here seems to be to fix your sprites so that the character is centered in each sprite and that the bottom level of the sprite is where the characters feet touches the ground (or would have touched the ground if both feet are up in the air in some frames). Is there any reason why you wouldn't want to do that instead of making a more complicated solution in the script ??? 

If there is a problem with fixing the sprites, it's probably that problem you should try to solve.

Khris

You can indeed use something like player.Move(player.x - 12, player.y - 12, ...); or just
Code: ags
  player.x -= 12;
  player.y -= 12;
to make them jump there instantly; that makes sense if we're talking about the entire animation, but from your original question it sounded like frames within a single animation were misaligned.

ollj

Storing an offset vector for each frame of an animation, and then moving the character by the frames offset position, is possible, but it adds to used memory and it slows down runtime.

just having each sprite at least centered to the same x ynd y value before you import the sprite, saves you a lot of memory and processing time. you can still add an individual offset vector for each animation/character.

this doesnt solve how to offset a character or its sprite (and all the sife effects it causes)
but it shows how to store an array of offset coordinates in v3.3
make an int[3] or an int[2] to store a 2d or 3d integer vector in a struct.
make an array of that struct.

Code: ags

#define OFFSETS_NUM 100
struct offsets{
  int[3] offset3d;
}
import offsets OffsetArray[OFFSETS_NUM];

//end of header , start of body
offsets OffsetArray[OFFSETS_NUM];//should be on top of a body to use the same offsets- instance there
export offsets;//should be on bottom of a body to use the same offsets- instance there

Glenjamin

No I meant for different animations as in different views. My frames are fine, it's just that different views make the characters jump around a bit. It's okay, I got it tho.

Monsieur OUXX

I'm not sure but player.Z could be of some use here.
 

SMF spam blocked by CleanTalk