Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

XNA: How to create a timer using GameTime?

Name: Anonymous 2010-06-16 8:15

[/code]
/--------------------------------------------------------------
/--------------------------DISCLAIMER--------------------------
/This code is in C# using the XNA Framework, if you have no /clue what im talking about, please take your SICP to other /threads, theres a reason im using a greasemonkey scripts to /block the word SICP
/--------------------------------------------------------------
[/code]

So in my pong remake, i want to make a timer to show when to reset the ball after the player scores.

Using GameTime, how would i go about making a timer readable by other code

for example:

Here is when the ball will be reset


while (resetTimer <= 0)
            {
                ballVelocity = new Vector2(10, 10);
            }


This is saying whenever the "resetTimer" reaches 0 seconds, the ball will begin to move again.


I understand that ElapsedGameTime means the amount of time between frames, but is there any way for my "resetTimer" to be subtracted by one every second? (in this case, "resetTimer" is declared an int with the value of 3)

Name: Anonymous 2010-06-16 8:16

Also, yeah i know, i did a fail job in my post, disregard it

Name: Anonymous 2010-06-16 8:20

NO EXCEPTIONS

Name: Anonymous 2010-06-16 8:22

>>3
lines 1-6

Name: Anonymous 2010-06-16 8:49

>>1
Read HTDP
I mean SICP

Name: Anonymous 2010-06-16 9:15

>>1
If reading the reference poses a challenge, you should buy a hard copy, lodge it deep in your ass and absorb the answer via osmosis.

Name: Anonymous 2010-06-16 10:47

>>1,2
Perhaps you are too thick to realise that the pronoun "I" in English is capitalised.

Name: Anonymous 2010-06-16 11:28

>>1,2,4
The best way to get help is always to antagonise people who are more competent than you.
Take your bullshit back to /code/ and go play with the rest of the morons sanctimonious about their poor decisions.

Name: Anonymous 2010-06-16 11:58

Well here's one way of doing it

//set this variable somewhere to initialize and start the timer
double mark = gameTime.ElapsedGameTime.TotalMilliseconds;

//for each frame you check if a second have passed
if (gameTime.ElapsedGameTime.TotalMilliseconds - mark >= 1000)
{
    //if it has we change mark to reflect this
    mark += 1000;
    //and decrement the resetTimer
    resetTimer--;
}

Modify to suit your needs, I hope you get the general idea.

Name: Anonymous 2010-06-16 16:09

>>8
>>7
>>6
>>5
this is why i hate /prog/ sometimes

>>9
this guy is the only one helpful, thank you >>9 - san

Name: Anonymous 2010-06-16 16:15

>>10
/prog/ hates you more than you hate it. And I don't mean that in a ``/prog/ hates everyone'' sense; I mean you, specifically: the kind of idiot who can't even figure out how to read the documentation and who puffs himself up with self-righteous indignation when it's pointed out to him that he's made some terrible decisions in life.
The posts you denounced are the best advice you can get; not just on /prog/, but in general. The one you liked, quite apart from the risible quality of the code, will only perpetuate your cycle as a copy/paste ``programmer'' incapable of even the slightest bit of independent thought. You aren't capable of recognising genuine helpfulness, because you're an ignorant fool, too self-absorbed to improve.

People like you are a disease, and you're not just contaminating /prog/ with your bullshit; you're killing the whole industry.

Name: Anonymous 2010-06-16 16:18

>>10
You should also learn to multi-quote, faggot.

Name: Anonymous 2010-06-16 16:24

>>11
+5 Insightful

Name: Anonymous 2010-06-16 16:29

>>1
theres a reason im using a greasemonkey scripts to /block the word SICP
>>10
>>8
>>7
>>6
>>5
This is why I hate retards sometimes.

Name: Anonymous 2010-06-16 16:51

>>1
If you don't want to read "The Structure and Interpretation of Computer Programs", that's fine, but your lack of motivation to better yourself is part of the reason why you are asking /prog/ for help on the XNA framework instead of reading the fucking docs.

Name: Anonymous 2010-06-16 17:14

Read SIXNA

Name: Anonymous 2010-06-16 21:16

Can we make a tiny little exception to the ``no imageboard talk'' rule to say that ``OP IS A FAG''?

Name: Anonymous 2010-06-16 21:50

>>17
fine, but just this once

Name: Anonymous 2010-06-16 22:26

>>17
You could translate it to ``>>1 IS A MORON''.

Name: Anonymous 2010-06-17 0:30

XARN: How to create a timer using GameTime?

Name: Anonymous 2010-06-17 2:25

>>15
No it's not fine if he doesn't want to read it.

Name: Anonymous 2010-06-17 7:56

SICP

Name: Anonymous 2011-02-03 5:09

Name: Anonymous 2011-02-04 18:23


Don't change these.
Name: Email:
Entire Thread Thread List