-
October 18th, 2011, 08:00 PM
#1
If statement help
Hey,
i have a question about if statements. I am trying to write a code for movement of a sprite. I want to have different acceleration for the y direction and x direction. I believe I am very close in getting the kind of motion i need, there is just one problem i am having.
Here's an example of what I'm trying to do:
if (currentKeyboardState.IsKeyUp(Keys.A) (but not) (currentKeyboardState.IsKeyDown(Keys.D))
{
Do.Something
}
//Basically i need some kind of function to put where the (but not) is. So if the A key is up and the D key is down i don't want the "Do.Something" to run. If anyone could help that would be great.
-
October 18th, 2011, 10:06 PM
#2
Re: If statement help
Try this:
if ((currentKeyboardState.IsKeyUp(Keys.A)) && (!currentKeyboardState.IsKeyDown(Keys.D)))
Developing using:
.NET3.5 / VS 2010
-
October 19th, 2011, 02:01 PM
#3
Re: If statement help
^this.
using the and (&&) and or(||) operators in a conditional allows you to build in a lot of extra complexity.
Also, the bang(!) is the symbol for not. Since the assumption for the IsKeyDown method is that it returns a bool, the bang can be attached to the object method. In other cases you'll need to use it as part of an evaluation, like:
Code:
if(someVariable != null)
DoStuff();
HTH
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
-
October 21st, 2011, 03:55 AM
#4
Re: If statement help
Originally Posted by Jim_Auricman
Try this:
if ((currentKeyboardState.IsKeyUp(Keys.A)) && (!currentKeyboardState.IsKeyDown(Keys.D)))
Just to help you understand the syntax, the above is the same as:
Code:
if (currentKeyboardState.IsKeyUp(Keys.A) == true && currentKeyboardState.IsKeyDown(Keys.D) == false)
It's not a bug, it's a feature!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|