Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:31:37+00:00 2026-05-18T08:31:37+00:00

I have come across a situation I have not encountered before using the IF

  • 0

I have come across a situation I have not encountered before using the IF control structure, with a further nested IF. Normally the nested IF would break down what I am checking in more fine grained detail, but in this instance it actually conflicts with the outer conditional – I am checking for a mouse click.

Here is the code –

if (mouseState.LeftButton == ButtonState.Pressed)
{
     if (mouseState.LeftButton == ButtonState.Released)
     {
          //move sprite to clicked position
          spritePos.X = mouseState.X;
          spritePos.Y = mouseState.Y;
     }
}

I have a couple of questions. I was taught that the conditional argument is only checked once, if it evaluates as true then the following statements are executed. Is this true, or is it actually checked before executing every statement within the block? – as the latter would obviously cause conflict with my nested if.

If this is true, then why does my button click method not work? The sprite never moves as though the mouse release never executes. Is it because the delay between performing a check on both conditionals is so small, that I can not physically have released the button within that time? Can I be slightly hackish about this and overcome it with a time delay which might be large enough to allow the release of the mouse button by the time of checking the nested conditional?

Methods for mouse click actions that I have seen, use properties of the mouse from the previous frame, and compare to the new frame to check for a mouse click. But this method must introduce a delay of at least one frame to actually process the action. This might not be noticeable with high framerates, but just for arguments sake say I had a game rendering 20fps. UpdateInput() would be called before rendering any frame, positions should update and then the frame should render last.

If the full mouse click operation could operate within less than 1/20th of a second, wouldn’t it be preferrable to process the action at once rather than store a variable upon the initial press, and compare states in the next frame? This would surely be better than introducing further delay on input.

I’m sure this must have been considered by others before though, and perhaps I’m not thinking correctly about the time delay operation actually pausing execution of the code. Can time delays pause processor execution of code, or only the result of those executions such as rendering and accepting input? They are not something which I have any experience in using, and I may be confusing how a delay would work.

Thank you,
Andrew.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:31:38+00:00Added an answer on May 18, 2026 at 8:31 am

    Andrew, your issue has nothing to do with the way if statements work. mouseState represents the state of the mouse when GetState() was called. It won’t change just because the mouse changes its state. For you code snippet to work like you are expecting it to, you would have to call GetState() before each if statement. The mouse state only changes when you poll it or manually set it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently come across a situation where code is dynamically loading some libraries,
I have come across a situation that conflicts with my current understanding of methods
I have come across a lot of optimization tips which say that you should
I have come across the following type of code many a times, and I
I have come across what must be a common problem. When I have an
I have come across a quirky feature in Visual Studio and I was interested
In my work I have come across syntax like global:: (C#) or G:Loading($value) in
One of the problems I have come across having complex tasks on the browser
I am a newbie to Python and have come across the following example in
I'm learning objective-C and Cocoa and have come across this statement: The Cocoa frameworks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.