Jump to content


Photo

Need an easy method **NOT SOLVED***


  • Please log in to reply
12 replies to this topic

#1 Silvess

Silvess

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM8

Posted 27 June 2012 - 01:14 PM

So I've been looking in to ways of doing this and have tried a few things, but nothing has really worked out to well. I'd like to animate an image by starting from a certain number of a sub image in a sprite and ending/looping at the end of a selected sub image. For example, I have a walking animation with 4 sub images per animation, but in that same animation, I have his up, down, left and right sub images. Now for walking up the sub image starts at 4 and ends at 7. I'd like that animation to loop when walking up at a speed of something like 0.3. Any ideas of how to accomplish this? Any ideas are much appreciated. :-)

Edited by Silvess, 02 July 2012 - 11:00 PM.

  • 0

#2 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8

Posted 27 June 2012 - 01:22 PM

well i think your saying you have 1 sprite with sub images for the directions your player is walking(up,down,left,right) am i right? if so then first thing is
it would be easier to have 4 sprites. 1 for each direction. and then when vspeed is negative then have the sprite change to up. and so on.
this is the easy way to acomplish this but you might not want to take all the time converting it to 4 different sprites.
  • -1

#3 Silvess

Silvess

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM8

Posted 27 June 2012 - 01:33 PM

That is a simple method, but for this particular project, I'd like all directions to be in one sprite. Yea, it seems complicated, but my game is using external encrypted content and this would prevent more than one file being used for each player added.
  • 0

#4 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3070 posts
  • Version:Unknown

Posted 27 June 2012 - 01:43 PM

Make it into a sort of state machine
if (RunningForward == true) { image_index = (image_index mod 4 )+4 }
This makes it so the minium value of image_index is 4 while the maximum is 7. Mod takes the remainder of the division x/y (x mod y) the number you'd use as y would always be equal to the number of frames that specific animation while the number after (z) would always be equal to the image_index it starts on. You'll need a way to manage all the states though you can either use different variables like the example above or use a state holder and constants

State = RUNNINGFORWARD ; 
State = RUNNINGLEFT ;

Where you have declared RUNNINGFORWARD and all other constants in the constants tab. You can then use a switch statement to change

switch(State)
{
case RUNNINGFORWARD : { image_index = (image_index mod 4 )+4 } ;break;
case RUNNINGLEFT      	: { image_index = (image_index mod 4 )+8 } ;break;
}

  • 0

#5 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8

Posted 27 June 2012 - 01:56 PM

well if the above poster didnt answer your problem you can....

variables

Up = ""
Down = ""
Left = ""
Right = ""

then have code in step

if vspeed < 0

{Up = true}
else Up = false

*do that for all the direction*(you could incoperate it with you movement code all together)

then have it so that it loops the sprite
Sprite

index 1-3 = up 4-6 = down 7-9 = left 10-12 = right



if Up = true {image_index = 1 if image_index > 3 {

image_index = 1

}}


this would be the startings of me completing what your asking but i might be wrong since its not my project :D but i hope this helps accomplish what your going for
  • -1

#6 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 27 June 2012 - 02:01 PM

I would do what robinsblade said. Pretty simple to do actually
  • 0

#7 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8

Posted 27 June 2012 - 02:05 PM

I would do what robinsblade said. Pretty simple to do actually

it could get complicate tho if she plans on the player moving diagnoly because the sprite should have around 5 images each direction that adds up to 40 images not to mention if she adds animations to other things like if you attack or if you do other things in the game......i recommend a text file saying

index

1-10 - does yada yada yada

11-w/e - doess this


and so forth just so it does not get confusing as mutch :D
  • -1

#8 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 27 June 2012 - 02:07 PM


I would do what robinsblade said. Pretty simple to do actually

it could get complicate tho if she plans on the player moving diagnoly because the sprite should have around 5 images each direction that adds up to 40 images not to mention if she adds animations to other things like if you attack or if you do other things in the game......i recommend a text file saying

index

1-10 - does yada yada yada

11-w/e - doess this


and so forth just so it does not get confusing as mutch :D


Hehe propably a good idea, yeah! ;)
  • 0

#9 Silvess

Silvess

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM8

Posted 28 June 2012 - 07:36 PM

well if the above poster didnt answer your problem you can....

variables

Up = ""
Down = ""
Left = ""
Right = ""

then have code in step

if vspeed < 0

{Up = true}
else Up = false

*do that for all the direction*(you could incoperate it with you movement code all together)

then have it so that it loops the sprite
Sprite

index 1-3 = up 4-6 = down 7-9 = left 10-12 = right



if Up = true {image_index = 1 if image_index > 3 {

image_index = 1

}}


this would be the startings of me completing what your asking but i might be wrong since its not my project :D but i hope this helps accomplish what your going for


the problem with this method is that the image jumps right back to 1 after hitting 3. This means that 3 is pretty much skipped making for a very jumpy animation. I need a way of the game detecting that JUST before the image jumps to 4, it goes back to 3, keeping the image 3 running long enough to look like a smooth animation cycle. Any ideas?
  • 0

#10 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3070 posts
  • Version:Unknown

Posted 28 June 2012 - 08:21 PM

Did you read my previous post?
  • 0

#11 Silvess

Silvess

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM8

Posted 28 June 2012 - 08:30 PM

Did you read my previous post?


My code is very complicated do to draw function and I've had to work around using the "image_index" function. I'm not sure I know how to make your code work for animating a drawn sprite. See, right now, I have something like--

draw_sprite_ext(spr_head,img_in_speed,x,y,image_xscale,image_yscale,image_angle,color,image_alpha);

in the draw event and img_in_speed animates at 0.3 when the player is moving. In the step event, I have

img_in_speed+=0.3

and I'm trying to make it only animate a certain start to end image which has become very difficult. I've tried using something like this--

END STEP EVENT:
if speed>=1
{
if img_in_speed<anim_start img_in_speed+=anim_start;
if img_in_speed+0.3>anim_end { img_in_speed -= anim_end - anim_start; }
}

and I change the anim_start and anim_end variable depending on the key press for movement. Like, down would be 0-3 and up would be 4-7 and left/right (using image_xscale) would be 8-11. It's been very hard and I really need some help figuring out a good system for this game. Any solutions would be great.
  • 0

#12 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3070 posts
  • Version:Unknown

Posted 28 June 2012 - 08:35 PM

You realise the argument where you have put img_in_speed is the image_index argument (it'll round to an integer). You do what I outlined on this variable instead. I personally don't understand why you are using your own system to control speed rather than setting image_speed since you seem to be only drawing 1 sprite from the object and always at the same speed. Is there any particular reason you can't use image_speed to control the speed?
  • 0

#13 Silvess

Silvess

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM8

Posted 28 June 2012 - 08:59 PM

You realise the argument where you have put img_in_speed is the image_index argument (it'll round to an integer). You do what I outlined on this variable instead. I personally don't understand why you are using your own system to control speed rather than setting image_speed since you seem to be only drawing 1 sprite from the object and always at the same speed. Is there any particular reason you can't use image_speed to control the speed?



Here is an example file of what I'm doing. It seems simple but I get a small jitter in between the sprite transitions.

EXAMPLE FILE--
http://www.mediafire.com/?cvhogvfp8bccvu3


If you can help me out, it would be more than appreciated.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users