Jump to content


Photo

sprite image angle animation issue


  • Please log in to reply
14 replies to this topic

#1 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 27 February 2012 - 12:38 AM

Hi I am trying to get my farmer to follow a path and walk along it facing the appropriate way. I got him doing it except I can't get him to do it and play his animation.
here is my step code.
image_index = direction * 8/360;
image_speed =1;

draw_sprite_ext(spr_farmer,(8*image_index)+(image_angle/360),x,y,image_xscale,image_yscale,image_angle,c_white,0)

thanks so much for your time.
  • 0

#2 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1407 posts
  • Version:GM:Studio

Posted 27 February 2012 - 12:47 AM

To do his animation, wouldn't you remove the whole equation and just make it image_index for the second argument?
draw_sprite_ext(spr_farmer,image_index,x,y,image_xscale,image_yscale,image_angle,c_white,0);
  • 0

#3 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 27 February 2012 - 01:25 AM

To do his animation, wouldn't you remove the whole equation and just make it image_index for the second argument?
draw_sprite_ext(spr_farmer,image_index,x,y,image_xscale,image_yscale,image_angle,c_white,0);

he is still sliding in the correct direction but the walking animation is still not playing.
  • 0

#4 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1407 posts
  • Version:GM:Studio

Posted 27 February 2012 - 01:46 AM

OH, is your image_speed set somewhere to 0? You have to set that to something like 0.4 when you start walking, then 0 again when you aren't...
  • 0

#5 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 27 February 2012 - 02:11 AM

OH, is your image_speed set somewhere to 0? You have to set that to something like 0.4 when you start walking, then 0 again when you aren't...

it is set to 1. i had all the code in the step event. i tried this:
create event
depth = -y;
        image_index = direction * 8/360;
        image_speed =0.4;
step event
draw_sprite_ext(spr_wheat_farmer,image_index,x,y,image_xscale,image_yscale,image_angle,c_white,0);
but now he just spins in a circle following the path :/

Edited by fylith, 27 February 2012 - 02:18 AM.

  • 0

#6 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 27 February 2012 - 02:24 AM

Since you're using image_angle, you don't have to use direction to calculate image_index either.

here is my step code.

Also, draw_sprite_ext doesn't work in the step event (all drawing codes need to be in the draw event)... but you don't need it either, as Game Maker automatically draws it according to image_index and image angle.

All you need was this in the step event and leave image_index as is (so it is automatically updated according to image_speed.)
image_angle = direction;

Edited by torigara, 27 February 2012 - 02:25 AM.

  • 0

#7 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 27 February 2012 - 02:36 AM

Since you're using image_angle, you don't have to use direction to calculate image_index either.

here is my step code.

Also, draw_sprite_ext doesn't work in the step event (all drawing codes need to be in the draw event)... but you don't need it either, as Game Maker automatically draws it according to image_index and image angle.

All you need was this in the step event and leave image_index as is (so it is automatically updated according to image_speed.)
image_angle = direction;

when I do that he still spins but now he is flatened not iso. here is my game can you look at it and see what i screwed up on :) the one i am working on is obj_wheat_farmer. thanks
  • 0

#8 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 27 February 2012 - 08:39 AM

Well, your sprite seem to have neither a sequence of animation nor a sequence of rotated images. They're some sort of combination of animation and rotation that I can't figure out how they're organized. Can you explain which sub-images are supposed to be used in which direction?

Edited by torigara, 27 February 2012 - 08:45 AM.

  • 0

#9 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 27 February 2012 - 11:24 AM

Well, your sprite seem to have neither a sequence of animation nor a sequence of rotated images. They're some sort of combination of animation and rotation that I can't figure out how they're organized. Can you explain which sub-images are supposed to be used in which direction?

spr_wheat_farmer i moved the sequences to have them match every 8th IE his walk down animation is 8 pics away. but the spr_farmer is un_manipulated it has the animations in the correct order but when i changed obj_wheat_farmer to have the sprite spr_farmer it is still doing the same spinning and flattened image.
thanks for your time i appreciate your help.
  • 0

#10 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 28 February 2012 - 03:30 AM

spr_wheat_farmer i moved the sequences to have them match every 8th IE his walk down animation is 8 pics away.

So, they're supposed to be used as follows, right?
Direction   Sub-images used
------------------------------------------
East         0,  8, 16, 24, 32, 40, 48, 56
North-East   1,  9, 17, 25, 33, 41, 49, 57
North        2, 10, 18, 26, 34, 42, 50, 58
...
South        6, 14, 22, 30, 38, 46, 54, 62
South-East   7, 15, 23, 31, 39, 47, 55, 63
I'm afraid your sequence if broken somewhere, because the last sub-image 63 doesn't look to face south-east (315) but south-west (225.) But let's go along with this assumption.

The thing could be easier if the column and row were swapped (i.e. sub-images 0 to 7 were used for east, 8 to 15 were north-east and so on.) Unfortunately, sub-image numbers are discontinuous within an animation with the current setup, so we need our own variable to keep track of the animation.
// Create event
frame_no = 0; // A variable to keep track of animation
image_speed = 0; // We don't (and can't) use the in-built speed

To calculate the image index, we first calculate the row number in the above table from the direction (east=0, north-east=1 and so on.)

row_no = round(direction / 45);
if (row_no == 8) row_no = 0; // for direction between 337.5 and 360

Since each animation sequence consists of 8 sub-images, we update the frame number keeping it between 0 (inclusive) and 8 (exclusive).

frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed

Turn the frame number into a column number in the above table (0 to 7.)

col_no = floor(frame_no);

Multiplying the column number by 8 and adding the row number yields the desired sub-image index.

image_index = col_no * 8 + row_no;


Now add those expressions together, making a bit of simplification.
// Step event
frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed
image_index = floor(frame_no) * 8 + round(direction / 45) mod 8;

Edited by torigara, 28 February 2012 - 06:10 AM.

  • 0

#11 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 28 February 2012 - 12:30 PM

So, they're supposed to be used as follows, right?

Direction   Sub-images used
------------------------------------------
East         0,  8, 16, 24, 32, 40, 48, 56
North-East   1,  9, 17, 25, 33, 41, 49, 57
North        2, 10, 18, 26, 34, 42, 50, 58
...
South        6, 14, 22, 30, 38, 46, 54, 62
South-East   7, 15, 23, 31, 39, 47, 55, 63
I'm afraid your sequence if broken somewhere, because the last sub-image 63 doesn't look to face south-east (315) but south-west (225.) But let's go along with this assumption.

The thing could be easier if the column and row were swapped (i.e. sub-images 0 to 7 were used for east, 8 to 15 were north-east and so on.) Unfortunately, sub-image numbers are discontinuous within an animation with the current setup, so we need our own variable to keep track of the animation.
// Create event
frame_no = 0; // A variable to keep track of animation
image_speed = 0; // We don't (and can't) use the in-built speed

To calculate the image index, we first calculate the row number in the above table from the direction (east=0, north-east=1 and so on.)

row_no = round(direction / 45);
if (row_no == 8) row_no = 0; // for direction between 337.5 and 360

Since each animation sequence consists of 8 sub-images, we update the frame number keeping it between 0 (inclusive) and 8 (exclusive).

frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed

Turn the frame number into a column number in the above table (0 to 7.)

col_no = floor(frame_no);

Multiplying the column number by 8 and adding the row number yields the desired sub-image index.

image_index = col_no * 8 + row_no;


Now add those expressions together, making a bit of simplification.
// Step event
frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed
image_index = floor(frame_no) * 8 + round(direction / 45) mod 8;

i have a sprite with the sequence east = 0-7 and so on. what is the easier version you talked about? the one above got his animations going but he is not facing the correct directions now :(
I am sorry I am being such a pain. my game is progressing but my NPCs' animations not working bothers me :)
  • 0

#12 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 29 February 2012 - 01:43 AM

I've explained how the code is derived step by step. If you arrange sub-images so that it advances in the column order first, you could just swap col_no and row_no in the expression, say:

image_index = row_no * 8 + col_no;

What have you tried so far?

Edited by torigara, 29 February 2012 - 04:57 AM.

  • 0

#13 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 29 February 2012 - 05:13 AM

I've explained how the code is derived step by step. If you arrange sub-images so that it advances in the column order first, you could just swap col_no and row_no in the expression, say:

image_index = row_no * 8 + col_no;

What have you tried so far?

create code:
frame_no = 0; // A variable to keep track of animation
image_speed = 0; // We don't (and can't) use the in-built speed

step code:
//this one was the one that i think i changed the col_num with row_num
frame_no = (frame_no + 0.4) //mod 8; // Change 0.4 to your desired image speed
image_index = floor(frame_no) + round(direction / 45) //mod 8;
//
frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed
image_index = round(direction / 45)+ floor(frame_no) mod 8;
// and i have tried
frame_no = (frame_no + 0.4) //mod 8; // Change 0.4 to your desired image speed
image_index = floor(frame_no) + round(direction / 45) //mod 8;
//and
frame_no = (frame_no + 0.4) //mod 8; // Change 0.4 to your desired image speed
image_index = floor(frame_no) * round(direction / 45) //mod 8;
//and
frame_no = (frame_no + 0.4) mod 4; // Change 0.4 to your desired image speed
image_index = floor(frame_no) + round(direction / 45) mod 4;

  • 0

#14 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 01 March 2012 - 01:19 AM

You seem to have missed "* 8" part altogether. Well, let's recall...

row_no = round(direction / 45) mod 8; // A simplified expression
col_no = floor(frame_no);

Substitute these two for the third expression:

image_index = row_no * 8 + col_no
= (round(direction / 45) mod 8) * 8 + floor(frame_no)

Sub-images are now continous within an animation, so we no longer have to make col_no a whole number. But it still has to be kept between 0 (inclusive) and 8 (exclusive). You were not supposed to change the first line.
frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed
image_index = (round(direction / 45) mod 8) * 8 + frame_no;
And make sure that ALL of your sub-images are correctly arranged as indicated below, with no exception.
Direction   Sub-images used
---------------------------
East         0 to  7
North-East   8 to 15
North       16 to 23
North-West  24 to 31
West        32 to 39
South-West  40 to 47
South       48 to 55
South-East  56 to 63

  • 1

#15 fylith

fylith

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 01 March 2012 - 02:03 AM

You seem to have missed "* 8" part altogether. Well, let's recall...

row_no = round(direction / 45) mod 8; // A simplified expression
col_no = floor(frame_no);

Substitute these two for the third expression:

image_index = row_no * 8 + col_no
= (round(direction / 45) mod 8) * 8 + floor(frame_no)

Sub-images are now continous within an animation, so we no longer have to make col_no a whole number. But it still has to be kept between 0 (inclusive) and 8 (exclusive). You were not supposed to change the first line.
frame_no = (frame_no + 0.4) mod 8; // Change 0.4 to your desired image speed
image_index = (round(direction / 45) mod 8) * 8 + frame_no;
And make sure that ALL of your sub-images are correctly arranged as indicated below, with no exception.
Direction   Sub-images used
---------------------------
East         0 to  7
North-East   8 to 15
North       16 to 23
North-West  24 to 31
West        32 to 39
South-West  40 to 47
South       48 to 55
South-East  56 to 63

wow i am so sorry i don't know how i missed that i will try it right now.
woot! thank you so much ! it works finally. I wished i had not miss read your posts. thanks for your patience with me.

Edited by fylith, 01 March 2012 - 02:21 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users