Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Help needed.  (Read 1662 times)

0 Members and 1 Guest are viewing this topic.

~DuckPond~

Help needed.
« on: July 16, 2007, 04:45:49 pm »
I have made my own Movement script, and i need a little help on my Sprite correction.

This is my code.
Code: [Select]
//Sprite Correction
if (keyboard_check(vk_down) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_up) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_left) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Left;}
if (keyboard_check(vk_right) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Right;}
   
if (keyboard_check(vk_up) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_up) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_down) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_down) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}

It works fine for the Up and down poses, but when i try to do the left and right poses, it Intercepts with the up and down ones.
Is there a way to get around this?

Thanks in advance.
Logged
Re: Help needed.
« Reply #1 on: July 16, 2007, 05:09:18 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1645
I have made my own Movement script, and i need a little help on my Sprite correction.

This is my code.
Code: [Select]
//Sprite Correction
if (keyboard_check(vk_down) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_up) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_left) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Left;}
if (keyboard_check(vk_right) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Right;}
   
if (keyboard_check(vk_up) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_up) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_down) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_down) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}

It works fine for the Up and down poses, but when i try to do the left and right poses, it Intercepts with the up and down ones.
Is there a way to get around this?

Thanks in advance.
It's a pretty confusing code since you used the !keyboard_check(vk_left) && !keyboard_check(vk_right) for 4 directions and just !keyboard_check(vk_right) for up and down.

Quote from: Just a Guess...
//Sprite Correction
if (keyboard_check(vk_down) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_up) && !keyboard_check(vk_left) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_left) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Left;}
if (keyboard_check(vk_right) && !keyboard_check(vk_up) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Right;}
   
if (keyboard_check(vk_up) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_up) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Up;}
if (keyboard_check(vk_down) && !keyboard_check(vk_left)){
    sprite_index = Sakura_Walking_Down;}
if (keyboard_check(vk_down) && !keyboard_check(vk_right)){
    sprite_index = Sakura_Walking_Down;}

if (keyboard_check(vk_left) && !keyboard_check(vk_up)){
    sprite_index = Sakura_Walking_Left;}
if (keyboard_check(vk_left) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Left;}
if (keyboard_check(vk_right) && !keyboard_check(vk_up)){
    sprite_index = Sakura_Walking_Right;}
if (keyboard_check(vk_right) && !keyboard_check(vk_down)){
    sprite_index = Sakura_Walking_Right;}


Logically the && !'s you use for the if's doesn't seems to be right, the half of them lacks the && ! of prohibited key.
Check back your code and you'll see.

I'm sorry for bad explaining, I just try to help.
Logged
  • Virtual Security

~DuckPond~

Re: Help needed.
« Reply #2 on: July 16, 2007, 05:20:27 pm »
I already tried doing that, It now stops the up and down ones from working. :(
« Last Edit: July 16, 2007, 05:22:05 pm by ~DuckPond~ »
Logged

Antidote

>.>
Re: Help needed.
« Reply #3 on: July 19, 2007, 06:29:13 pm »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
start commenting out portions until you've found what is causing it to fail then  try to fix the problem.
Logged
  • Axiomatic Data Laboratories
Re: Help needed.
« Reply #4 on: July 24, 2007, 12:37:18 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
Try this code:

if (hspeed<0)sprite_index=Sakura_Walking_Left;
if (hspeed>0)sprite_index=Sakura_Walking_Right;
if (vspeed<0)sprite_index=Sakura_Walking_Up;
if (vspeed>0)sprite_index=Sakura_Walking_Down;
Logged

~DuckPond~

Re: Help needed.
« Reply #5 on: July 26, 2007, 07:22:06 pm »
It still does the same thing :(
Logged
Re: Help needed.
« Reply #6 on: July 26, 2007, 11:11:40 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
I think the error might be in somewhere else then...
Logged
Re: Help needed.
« Reply #7 on: July 27, 2007, 12:05:41 am »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
Why does everyone have to over-complicate finding which way you're facing...  You don't need half a dozen possibly conflicting if statements to do it if you don't mind setting your sprite separately.  I actually prefer doing it separately, so I can use the same facing direction finding code for every animation, instead of having to duplicate it for each one.

Prioritized movement is as easy as:
Code: [Select]
dir_difference=abs(dir_moving-dir_facing)
if dir_difference>45 and dir_difference<315
 dir_facing=round(dir_moving/90)*90

First we find the difference between the direction you're facing and the direction you're moving.
Next check if the difference is greater than 45 and less than 315 (Remembering that directions wrap around 360, and 360-45 = 315, so basically if the difference is greater than 45 in the other direction)
If so, update our facing direction to the direction we're moving rounded to the nearest 90 degrees (360 degrees total divided by 4 possible directions = 90 degrees per direction)
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Re: Help needed.
« Reply #8 on: July 27, 2007, 01:04:43 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
Code: [Select]
dir_difference=abs(dir_moving-dir_facing)
if dir_difference>45 and dir_difference<315
 dir_facing=round(dir_moving/90)*90
Don't forget that you'd have to add 4 more lines to associate the object to the image.

I usually use an engine simmilar to that one, but it seems that DuckPond's movement engine only allows the player to move in 4 or 8 directions (the engine I use in my games uses the mouse to move, so there are infinite directions), so calculating "dir_facing=round(dir_moving/90)*90" doesn't make much difference to DuckPond's engine.
Logged
Re: Help needed.
« Reply #9 on: July 27, 2007, 02:42:21 am »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
For setting the sprite of the player, using this system and another for figuring out what they're doing I've gotten it down to a single line of code:

sprite_index=animations[action,dir_facing/90]

Using an array has the added benefit of being able to change the sprite indexes contained in it at any time, for example if you wanted to change the clothing the player was wearing all you would need is a block of code to update the values in the array that only needs run once as opposed to a mountain of new if statements in the player running almost every frame.


Besides that though, dir_facing is a variable you'd want a lot of the time anyway.  Any time the player wants to interact with something in front of him, or use an item normally you'd have to figure out what way they're facing first, but it's so much easier to just have a variable like dir_facing lying around instead.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Re: Help needed.
« Reply #10 on: July 27, 2007, 02:55:53 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
For setting the sprite of the player, using this system and another for figuring out what they're doing I've gotten it down to a single line of code:

sprite_index=animations[action,dir_facing/90]

Using an array has the added benefit of being able to change the sprite indexes contained in it at any time, for example if you wanted to change the clothing the player was wearing all you would need is a block of code to update the values in the array that only needs run once as opposed to a mountain of new if statements in the player running almost every frame.
hmm... Using an array is a nice idea. In an RPG I was making some time ago, I used a function sprite_set(character,status,action,facing) but it'd be required having the program read the whole script whenever you associate the object to an image... An array would be a lot faster. The only problem is that in GM you can only have one-dimensional and two-dimensional arrays, which makes things more difficult...
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.284 seconds with 75 queries.

anything