|
OK - slap me round the head with a wet kipper. I'm just plain wrong here. I've just had a quick look and the TimeSpan class does indeed allow you to use a greater range. So - saying this, I'd go with the TimeSpan object.
Thanks for making me go and have a look again. Worth a 5 for making me look an idiot.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: OK - slap me round the head with a wet kipper. I'm just plain wrong here. I've just had a quick look and the TimeSpan class does indeed allow you to use a greater range. So - saying this, I'd go with the TimeSpan object.
Thanks for making me go and have a look again. Worth a 5 for making me look an idiot.
That's why I love codeproject. Bouncing around ideas with other developers really is great!
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Justin Perez wrote: That's why I love codeproject.
It certainly is. It's the cut and thrust of the intellectual debate that goes on here.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
No kipper around, sorry.
A wet rain cheque will have to do for now.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You may want to consider using Stopwatch [^] instead. (Requires .NET 3.0).
/ravi
|
|
|
|
|
I understand how to draw, for say a rectangle, but where do I draw it at, as in is there some event? Or...? Thanks to the same 4 or so people that help out. And anyone else, in advance.
|
|
|
|
|
All drawing should occur in your paint event. The reason is, Windows tells your form when to draw itself, for example if it was obscured by another window and then shown again. That's what the Paint event is for.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yeah, thanks, I just found this good article that explains it well... In the paint event, you set up graphics, ad then (whatever your variable is).DrawWhatever (blah, blah, blah)
Thanks again!
|
|
|
|
|
Exactly. The other piece of the puzzle is, if you change something and want to force a redraw, you call Invalidate() to force a paint event.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Can I suggest that you look at abstracting your drawing so that you don't end up with a huge paint routine? For instance, you want to draw a rectangle - then why not create a class that is responsible for managing the rectangle? The reason that I suggest this, is that it makes it easier to manage the drawing process if the components themselves are responsible for drawing themselves.
Typically, you would have a shape that inherits from some common class (call it ShapeBase for instance). Then you would add the shapes to a shape collection. When you call paint in your form, you would simply need to cycle through each shape in the collection and tell them to paint themself.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I've been reading this Dummies book for starters, (that's to the same people, they KNOW who they are...), but anyways, I'm trying to figure out some simple kind of collision detection for 2 squares, not per pixel. I've got some to work, but I need to know the correct way to do this, so if anyone would teach me a little on collision, I'd be very happy. Thanks in advance.
|
|
|
|
|
Collision of squares is easy. I believe the Rectangle class has a PtInRect method, just pass that the four corners of your other rectangle and see if any of them return true. A rectangle is easy because if any of the corners are inside the other rectange, then they have collided. Irregular shapes are more complex, I present one solution ( although I don't believe it's overly efficient ) in my series of articles on writing a game in C#.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I see what you are getting at, but could you give me a look at the code, just a simple snippet?
|
|
|
|
|
It's even easier than I thought:
Rectangle rc1 = new Rectangle(0, 0, 20, 20);
Rectangle rc2 = new Rectangle(19, 21, 5, 5);
if (rc2.IntersectsWith(rc1))
{
// match
}
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Are you serious?
|
|
|
|
|
Wait, but when I run the program, you can't see the rectangles. It's probably supposed to do that, but how do you use both collision and drawing? I get them seperate, but... Thnks for the help so far though.
|
|
|
|
|
Please see my response to your other post to get an idea on how to do this.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Like I said, Invalidate() forces a paint. And what Pete said, I was gong to say, too. You should have a collection of objects that know how to draw themselves. Your paint event should step over that collection, and pass the drawing to them. This lets you easily add as many rectangles as you like, and your paint event stays clean, no matter how many shapes you add in the future.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I only said it because you are busy racking up about 1000 posts a day now (at least that's how it seems to us mortals).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
LOL - either way, I thought to say it and didn't, so it was a fair addition to what I posted, I should have mentioned it.
It's nice to see MasterSharp both taking my advice to read some books, and starting to ask more complex questions ( which I assume means he's learning something from the books he's reading ). I feel pretty happy to think that someone actually came here wanting to learn and not just to be given code.
BTW, Nish pointed out to me that I've gone over the 40,000 post mark. That's got to be a sign that I need to get a life.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: It's nice to see MasterSharp both taking my advice to read some books, and starting to ask more complex questions ( which I assume means he's learning something from the books he's reading ). I feel pretty happy to think that someone actually came here wanting to learn and not just to be given code.
I know - it's always nice to see them grow up. BTW - I haven't forgotten your CD, it's just that we're stuck in the middle of a damn postal strike here in the UK. I don't want it to "get lost" in the post.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
OK, cool. LMK when that resolves itself.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
What are you talking about 100 posts a day. I know I'm VERY questioning, but not that many even for exagerations (probably killed that), and I've calmed down a bit and took to a book!
|
|
|
|