Jump to content


Photo

Walking object only 1 subimage appearing


  • Please log in to reply
6 replies to this topic

#1 peter879

peter879

    GMC Member

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

Posted 03 May 2012 - 10:24 PM

I am using this code I found here to make a walking object:

STEP EVENT

if !place_free(x,y+1) then {
if x>xprevious then {image_speed = 1; sprite_index = spr_playerright_1}//moving right
if x<xprevious then {image_speed = 1; sprite_index = spr_playerleft_l}//moving left
if x=xprevious then {image_speed = 0; image_index = 0}}

else {
if x>xprevious then {
if y<yprevious then {image_speed = 1; sprite_index = spr_playerupa_1}//moving up
if y>yprevious then {image_speed = 1; sprite_index = spr_playerdowna_1}}//moving down
if x<xprevious then {
if y<yprevious then {image_speed = 1; sprite_index = spr_playerupb_1}//Moving up...
if y>yprevious then {image_speed = 1; sprite_index = spr_playerdownb_1}}//Moving down...
if x=xprevious then {image_speed = 0; image_index = 0}

LEFT ARROW KEY:

sprite_index=spr_playerleft_l

and drag and drop for speed of 2.

similar situation for the other arrow keys.

THE PROBLEM

to create the illusion of walking, each sprite has 6 subimages.

When I test the object movement with the arrow keys, only 1 subimage is showing per direction, so no walking at all, although its moving.

I can't figure out what is wrong, having no coding skills.

Thank you for taking your time to read this post.
  • 0

#2 Daddio

Daddio

    GMC Member

  • GMC Member
  • 266 posts

Posted 03 May 2012 - 10:35 PM

Did you try a subimage -1 and speed 1?

I think the "-1" for sprite subimage is the ticket...but I'm a newb, so what do I know?


PS

if x<xprevious then {image_speed = 1; sprite_index = spr_playerleft_l}//moving left

Is that playerleft_l ? as in, lowercase L...doesn't look like a 1

Edited by Daddio, 03 May 2012 - 10:37 PM.

  • 0

#3 peter879

peter879

    GMC Member

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

Posted 03 May 2012 - 11:09 PM

Did you try a subimage -1 and speed 1?

I think the "-1" for sprite subimage is the ticket...but I'm a newb, so what do I know?


PS

if x<xprevious then {image_speed = 1; sprite_index = spr_playerleft_l}//moving left

Is that playerleft_l ? as in, lowercase L...doesn't look like a 1


Thank you for the reply.

Yes, playerleft_l is for left, lowercase L.

Where exactly in the above code do I insert -1 for sprite subimage?
I am a real novice, unfortunately.
  • 0

#4 Daddio

Daddio

    GMC Member

  • GMC Member
  • 266 posts

Posted 03 May 2012 - 11:13 PM

EDIT

As Image_Index. And you want the speed to be 1, not 0 (that makes it stop)



When you have a keypress event, it just keeps starting again and again at sprite frame (subimage) 1.

Putting in -1 tells it to just go ahead. Hope that helps and gets it working for you.

Edited by Daddio, 03 May 2012 - 11:14 PM.

  • 1

#5 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1616 posts
  • Version:GM8

Posted 03 May 2012 - 11:14 PM

In the left arrow key event, remove the "sprite_index=spr_playerleft_l". That is not necessary since sprite indexes are calculated in your step event. Do the same for the rest of the keys.

Also, try reducing the image speed from 1 to 0.5.
  • 1

#6 peter879

peter879

    GMC Member

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

Posted 04 May 2012 - 01:20 AM

EDIT

As Image_Index. And you want the speed to be 1, not 0 (that makes it stop)



When you have a keypress event, it just keeps starting again and again at sprite frame (subimage) 1.

Putting in -1 tells it to just go ahead. Hope that helps and gets it working for you.

Thank you for your help. Object is now walking fine. I am planning to use drag and drop as much as I can. :biggrin:
  • 0

#7 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 04 May 2012 - 01:26 AM


EDIT

As Image_Index. And you want the speed to be 1, not 0 (that makes it stop)



When you have a keypress event, it just keeps starting again and again at sprite frame (subimage) 1.

Putting in -1 tells it to just go ahead. Hope that helps and gets it working for you.

Thank you for your help. Object is now walking fine. I am planning to use drag and drop as much as I can. :biggrin:

GML is your friend DnD is bad when it comes to specific stuff done!
I prefer GML, DnD is trouble some.
also GML is easy to learn!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users