Rich
Rich

Reputation: 15

XNA C# Find max number in an integer

I currently have an integer that changes according to where an object is on the screen. After the object has moved I would like to find what the max number in the integer was. (In essence, after making my character jump, I want to find the max height of that jump). How would I go about doing this? Could I use something like Math.Max ??

Thanks

Upvotes: 0

Views: 125

Answers (1)

Jeroen Vannevel
Jeroen Vannevel

Reputation: 44449

If the integer gets overwritten every time, you'll have to intercept the event in some way. I assume an event gets fired when his position changes?

In that case you can just hold a temporary field private int highest; Whenever the position change event is fired, check if the current height is more or less than the value of highest. If it is more, change the value of highest to the current height.

In the end you will remain with the highest value.

Upvotes: 3

Related Questions