Інсталювати Steam
увійти
|
мова
简体中文 (спрощена китайська)
繁體中文 (традиційна китайська)
日本語 (японська)
한국어 (корейська)
ไทย (тайська)
Български (болгарська)
Čeština (чеська)
Dansk (данська)
Deutsch (німецька)
English (англійська)
Español - España (іспанська — Іспанія)
Español - Latinoamérica (іспанська — Латинська Америка)
Ελληνικά (грецька)
Français (французька)
Italiano (італійська)
Bahasa Indonesia (індонезійська)
Magyar (угорська)
Nederlands (нідерландська)
Norsk (норвезька)
Polski (польська)
Português (португальська — Португалія)
Português - Brasil (португальська — Бразилія)
Română (румунська)
Русский (російська)
Suomi (фінська)
Svenska (шведська)
Türkçe (турецька)
Tiếng Việt (в’єтнамська)
Повідомити про проблему з перекладом
You should instead do something like...
"direction + 22.5" is to offset the whole check by 22.5 degrees, so that it can move slightly off-centre but still get the proper sprite applied. (So that anywhere from -22.5 to +22.5 degrees becomes 0 later, instead of anywhere from 0 to +45 degrees.)
"... % 360" means that any value above 360 is reduced by 360, so that 460 or 820 both become 100 and stuff like that.
"... + 360" adds 360 to it. The first "%" doesn't turn negative values into positive values (e.g. -460 and -820 become -100, not +260), so we must do so ourselves.
"... % 360" again wraps it down under 360. Doing "%, +, %" with the same number will result in negative values being wrapped around into positive ones (so that -100 becomes +260).
"... div 45" then divides it by 45, rounded down. As we've made the value be between 0 and 360, this results in an integer value from 0 to and including 8.
All of the parentheses are to ensure a proper order of events, taking the entire previous calculation into account rather than just one number of it or such.
You should then add these cases after that switch:
There may well be a more efficient way to do this, but this is the best way that I know of, I'm afraid.
EDIT: if the direction value is not one of the main cardinal values you'll have to reduce it to match
EDIT #2: I like Zappy's idea of offsetting the direction a little so that the sprite lines up more with what you visually want.
Update: I just tried the code below and it only worked when my player was running Right, Left, Down, Up. The other 4 directions didn't work.
switch (direction)
{
case 0: sprite_index = sprite_RB_Run_Right; break;
case 45: sprite_index = sprite_RB_Run_Up_Right; break;
case 90: sprite_index = sprite_RB_Run_Up; break;
case 135: sprite_index = sprite_RB_Run_Up_Left; break;
case 180: sprite_index = sprite_RB_Run_Left; break;
case 225: sprite_index = sprite_RB_Run_Down_Left; break;
case 270: sprite_index = sprite_RB_Run_Down; break;
case 315: sprite_index = sprite_RB_Run_Down_Right; break;
}
I also tried the code below as well and the only facing position my player did was face right.
switch (((((direction + 22.5) % 360) + 360) % 360) div 45)
{
case 0: case 8: sprite_index=sprite_Thunder_Viking_Running_Right; break; //Change these sprite names to the ones in your game!!!
case 1: sprite_index=sprite_Thunder_Viking_Running_Up_Right; break;
case 2: sprite_index=sprite_Thunder_Viking_Running_Up; break;
case 3: sprite_index=sprite_Thunder_Viking_Running_Up_Left; break;
case 4: sprite_index=sprite_Thunder_Viking_Running_Left; break;
case 5: sprite_index=sprite_Thunder_Viking_Running_Down_Left; break;
case 6: sprite_index=sprite_Thunder_Viking_Running_Down; break;
case 7: sprite_index=sprite_Thunder_Viking_Running_Down_Right; break;
}
It might not be working because my player is following a path for it's movement. Do you think that would be a cause for the problem?
EDIT:
the main issue with just asking if direction equals a value is you are asking the direction if it is a specific value without any leeway. By doing integer division on the direction you are giving direction a little leeway and its more like asking if direction is with in 45 degrees of any of the directions you supplied.
So for instance. By doing integer division:
the first case statement would be asking
is direction between 0 and 45.
the second case statement is asking
is direction between 46 and 90
and so on