Jump to content

checking to see which direction a sprite faces

We are working with XNA/monogame right now and I've gotten to rotating the sprite to face the direction you press on the dpad/arrowkeys but all I could think of to track which direction is 4 bools or an int (0-3). Any suggestions on making that more efficient/better suited?? Brains dead right now thats all

Link to post
Share on other sites

You could use a single char to store the direction.

 

 

Edited by Tigerbomb8, Tommorow, 09:52 PM.

CPU: i7 4770k | GPU: Sapphire 290 Tri-X OC | RAM: Corsair Vengeance LP 2x8GB | MTB: GA-Z87X-UD5HCOOLER: Noctua NH-D14 | PSU: Corsair 760i | CASE: Corsair 550D | DISPLAY:  BenQ XL2420TE


Firestrike scores - Graphics: 10781 Physics: 9448 Combined: 4289


"Nvidia, Fuck you" - Linus Torvald

Link to post
Share on other sites

Unless you are doing full angular rotation an int will work for 4 way direction and single bool will work for 2.

AMD FX-4100(Temporary), MSI 990FXA-GD65, 8GB Dual-Channel DDR3, MSI 7950 Twin Frozr 3GD5/OC, MSI Radeon HD 5450, Asus Xonar DGX, M4 128GB SSD, 1TB Seagate Baracuda HDD, 250GB Hitachi HDD, CoolerMaster Silent Pro 700W PSU, CoolerMaster Storm Scout, Corsair H50

Link to post
Share on other sites

Unless you are doing full angular rotation an int will work for 4 way direction and single bool will work for 2.

No I think a char would be better. It makes it easier for others to read without have to remember what number belongs to which direction.

 

"spriteDirection = 'u';"  vs  "spriteDirection = 1;"

CPU: i7 4770k | GPU: Sapphire 290 Tri-X OC | RAM: Corsair Vengeance LP 2x8GB | MTB: GA-Z87X-UD5HCOOLER: Noctua NH-D14 | PSU: Corsair 760i | CASE: Corsair 550D | DISPLAY:  BenQ XL2420TE


Firestrike scores - Graphics: 10781 Physics: 9448 Combined: 4289


"Nvidia, Fuck you" - Linus Torvald

Link to post
Share on other sites

No I think a char would be better. It makes it easier for others to read without have to remember what number belongs to which direction.

 

"spriteDirection = 'u';"  vs  "spriteDirection = 1;"

Didn't say it would be better, said it would work. I've used it before for LHR movement. Easier to track and update the direction for AI. Both options would be on par with each other if they are using good coding practice and commenting their code.

AMD FX-4100(Temporary), MSI 990FXA-GD65, 8GB Dual-Channel DDR3, MSI 7950 Twin Frozr 3GD5/OC, MSI Radeon HD 5450, Asus Xonar DGX, M4 128GB SSD, 1TB Seagate Baracuda HDD, 250GB Hitachi HDD, CoolerMaster Silent Pro 700W PSU, CoolerMaster Storm Scout, Corsair H50

Link to post
Share on other sites

oh of course, I don't actually need 4 bools just 2 :S int/char or 2 bools thanks guys XD

Well a 1 bool if you are doing something like a platformer where you can only move left or right. 2 bools for 4 way would be a bit messy as far as trying to follow, so best go with an int/char.

AMD FX-4100(Temporary), MSI 990FXA-GD65, 8GB Dual-Channel DDR3, MSI 7950 Twin Frozr 3GD5/OC, MSI Radeon HD 5450, Asus Xonar DGX, M4 128GB SSD, 1TB Seagate Baracuda HDD, 250GB Hitachi HDD, CoolerMaster Silent Pro 700W PSU, CoolerMaster Storm Scout, Corsair H50

Link to post
Share on other sites

What I've learned from experience is that it saves a lot of headaches to have input modify a variable and reference that variable whenever you need to know what it means. Which I'm assuming would help because you make it sound like your movement isn't quite so elegant.

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×