Jump to content


Photo

Moving diagonally & Changing sprites.


  • Please log in to reply
18 replies to this topic

#1 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 05:14 PM

Hey guys, i'm kind of new to GML and i'm trying to get this code to work.

if keyboard_check(ord('A')) x-=2.8
if keyboard_check(ord('D')) x+=2.8
if keyboard_check(ord('W')) y-=2.8
if keyboard_check(ord('S')) y+=2.8

if (keyboard_check(ord('W')) && keyboard_check(ord('D')))
{
sprite_index = walksp_upright
}

else

if (keyboard_check(ord('W')))
{
sprite_index = walksp_up
}
if (keyboard_check(ord('A')))
{
sprite_index = walksp_left
}
if (keyboard_check(ord('D')))
{
sprite_index = walksp_right
}
if (keyboard_check(ord('S')))
{
sprite_index = walksp_down
}
etc.

My problem is that if both W and D are pressed it doesnt change to walksp_upright. How do I fix this?
Also, how do I make it so if the object isn't walking it changes the sprite back to standsp_1?

Thanks!
  • 0

#2 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 05:17 PM

can you post your file. so i can see the issue.
maybe i can solve it.
  • 0

#3 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 05:25 PM

http://www.upurload....086654ad83a.gmk

Here you go, don't steal the sprites please. :P
  • 0

#4 ChefDavid22

ChefDavid22

    No, YOU shut up!

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

Posted 01 May 2012 - 05:31 PM

Close your sytnax
sprite_index = walksp_upright

should be
sprite_index = walksp_upright;

etc

And just FYI you can accomplish this with the D&D method so you dont have to worry about making mistakes in code. D&D is your friend
  • 0

#5 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 05:35 PM

there you go.. Sorry you had it properly done, but in the wrong area :).
all better now

Step Event

if keyboard_check(ord('A')) x-=2.8
if keyboard_check(ord('D')) x+=2.8
if keyboard_check(ord('W')) y-=2.8
if keyboard_check(ord('S')) y+=2.8
else

if (keyboard_check(ord('W')))
{
sprite_index = walksp_up
}
if (keyboard_check(ord('A')))
{
sprite_index = walksp_left
}
if (keyboard_check(ord('D')))
{
sprite_index = walksp_right
}
if (keyboard_check(ord('S')))
{
sprite_index = walksp_down
}
else
if keyboard_check(ord('W')) && keyboard_check(ord('D'))
{
sprite_index = walksp_upright
}

  • 0

#6 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 05:36 PM

Close your sytnax
sprite_index = walksp_upright

should be
sprite_index = walksp_upright;

etc

And just FYI you can accomplish this with the D&D method so you dont have to worry about making mistakes in code. D&D is your friend


You donot need ; <-- in your syntax.. Just for your information.. D&D i dont like. i prefer code. And everyone else should go too..
:)...

Good luck. and your sprite is cute lol.
  • 0

#7 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 05:43 PM

Oh and i did a little more for you.. so your not constant walking.




if keyboard_check(ord('A')) x-=2.8
if keyboard_check(ord('D')) x+=2.8
if keyboard_check(ord('W')) y-=2.8
if keyboard_check(ord('S')) y+=2.8
else

if (keyboard_check(ord('W')))
{
sprite_index = walksp_up
}
if (keyboard_check(ord('A')))
{
sprite_index = walksp_left
}
if (keyboard_check(ord('D')))
{
sprite_index = walksp_right
}
if (keyboard_check(ord('S')))
{
sprite_index = walksp_down
}
else
if keyboard_check(ord('W')) && keyboard_check(ord('D'))
{
sprite_index = walksp_upright
}

else

if keyboard_check_released(ord('W'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('A'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('D'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('S'))
{
sprite_index = standsp_1
}



Enjoy
  • 0

#8 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 05:47 PM

Thanks so much, that fixed it!
  • 0

#9 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 05:49 PM

Your very welcome.

If you got any more questions don't threat to PM me.. i added you as a friend.

There things i can and cannot do, but i know people that can. :)..

so Glad its all better
  • 0

#10 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 05:56 PM

I kind of got another problem now.
My code is currently this:

if keyboard_check(ord('A')) x-=2.8
if keyboard_check(ord('D')) x+=2.8
if keyboard_check(ord('W')) y-=2.8
if keyboard_check(ord('S')) y+=2.8
else

if (keyboard_check(ord('W')))
{
sprite_index = walksp_up
}
if (keyboard_check(ord('A')))
{
sprite_index = walksp_left
}
if (keyboard_check(ord('D')))
{
sprite_index = walksp_right
}
if (keyboard_check(ord('S')))
{
sprite_index = walksp_down
}
else
if keyboard_check(ord('W')) && keyboard_check(ord('D'))
{
sprite_index = walksp_upright
}
else
if keyboard_check(ord('W')) && keyboard_check(ord('A'))
{
sprite_index = walksp_upleft
}
else
if keyboard_check(ord('S')) && keyboard_check(ord('A'))
{
sprite_index = walksp_downleft
}
else
if keyboard_check(ord('S')) && keyboard_check(ord('D'))
{
sprite_index = walksp_downright
}
else

if keyboard_check_released(ord('W'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('A'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('D'))
{
sprite_index = standsp_1
}
if keyboard_check_released(ord('S'))
{
sprite_index = standsp_1
}

Now the going up sprites work (walksp_upright and walksp_upleft) but the going down sprites don't work (walksp_downright and walksp_downleft).

Also, when going diagonally the object seems to go faster, how do I fix this?
  • 0

#11 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:00 PM

way to many elses. :)
one sec
  • 0

#12 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:01 PM

send me the new file with the sprites so i can fix it
  • 0

#13 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:03 PM

but you can try removing all these


else
if keyboard_check(ord('W')) && keyboard_check(ord('D'))
{
sprite_index = walksp_upright
}

if keyboard_check(ord('W')) && keyboard_check(ord('A'))
{
sprite_index = walksp_upleft
}

if keyboard_check(ord('S')) && keyboard_check(ord('A'))
{
sprite_index = walksp_downleft
}

if keyboard_check(ord('S')) && keyboard_check(ord('D'))
{
sprite_index = walksp_downright
}



You only need the else once above, to indicate that there can be more moves..
when you put to many its going to loop through to many else.. and cause a glitched
walking problem

Edited by talonstart, 01 May 2012 - 06:03 PM.

  • 0

#14 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 06:08 PM

Ah, that fixed it, thanks!
  • 0

#15 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:10 PM

:D great!...I'm kinda excited to see what your plan is with this lil bugger :)
  • 0

#16 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 06:18 PM

I'm not quite sure yet myself, I'm probably going to put some things in and based on what I put in put more things in. :)
  • 0

#17 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:27 PM

well we know it can be anything right now.. over head rpg old schoolin it :D .. . the char. is awesome..
Kinda wanna slap a sword on him lol see what happens rofl

Tho you did give me an idea, while i was doing this..
but not sure how the outcome will be.. (not going to use your sprites).. but if you dont mind, me testing something using it.

Im see if i can create a (changable armor on him). . . since he's in a simple design. it be cool to watch him pick up
a breast plate, and show it upon him.. mind if i try?

Edited by talonstart, 01 May 2012 - 06:28 PM.

  • 0

#18 Flygonair

Flygonair

    GMC Member

  • GMC Member
  • 129 posts

Posted 01 May 2012 - 06:33 PM

That'd be awesome. I'd like to try it myself but I don't know how to do it with moving sprites, mind uploading the finished project so I can see how you do it?

Here's a version with the other animations and stuff:
http://www.upurload....a93ecbdb4dd.gmk
  • 0

#19 talonstart

talonstart

    Artist

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

Posted 01 May 2012 - 06:40 PM

Sure.. Lets close this thread.. And talk to me through PM.. Ill see what i can do :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users