Which code is cleaner, faster, or more elegant/preferable? Is there a function that does this already?

If you know r. Width and r. Height are Remove that and it will be even faster, and simpler if (r.

Width Width; r. Width = -r. Width; } if (r.

Height Height = -r. Height; } IMHO the second way you've written of doing this is just plain ugly. You don't look at it and immediately realise what it's doing.

Remember KISS EDIT: I understand you like your code in the fewest lines possible so I re-engineered the above: if (r. Width Width; r. Width = -r.

Width; } if (r. Height Height = -r. Height; } Just as simple - and all in one line of code!

It's even less characters on the line than your alternative Line count is generally not a good measure of programming beauty - but of course it's your code so you've got to go with what brings you the most joy.

If you know r. Width and r. Height are Remove that and it will be even faster, and simpler.

If (r. Width X += r. Width; r.

Width = -r. Width; } if (r. Height Y += r.

Height; r. Height = -r. Height; } IMHO the second way you've written of doing this is just plain ugly.

You don't look at it and immediately realise what it's doing. Remember KISS. EDIT: I understand you like your code in the fewest lines possible so I re-engineered the above: if (r.

Width Width; r. Width = -r. Width; } if (r.

Height Y += Height; r. Height = -r. Height; } Just as simple - and all in one line of code!

It's even less characters on the line than your alternative.... Line count is generally not a good measure of programming beauty - but of course it's your code so you've got to go with what brings you the most joy.

I agree with you to an extent. Yes I think the above example is more clear and readable but this is an independent project that will never be seen by anyone else. Either way I understand the code and if I have it on one line I don't really have to look at it or think about it.It's kind of like encapsulating something to a class.

You get it out of sight and can forget about it and think about other things. Of course this behavior can be mimicked by just placing the above code in to a method and giving it a descriptive name and I'm not necessarily against that either. – John Smith Aug 6 at 16:20 Yeah, on second thought I think I'm going with your code at the top of your post and placing it in to a method.

Thanks! – John Smith Aug 6 at 16:29 Fair enough - I get the drive the make code as short as possible too - but I fight it as other people will see my code (I would count future me who's forgotten how the code works as another person in this respect too). – James Gaunt Aug 6 at 16:30.

The first one is more readable, and it should also be slightly faster as it does less if there is nothing to do. After checking if the values are negative, you know that they are negative, so you don't need any Math. Abs: if (r.

Width X -= r. Width; } if (r. Height Height = -r.

Height; r. Y -= r. Height; } Just for completeness, the second one can also be written will less Math.

Abs calls as you know the sign of what comes out of Math. Min when it's not zero: r. X += Math.

Min(0, r. Width); r. Width = Math.

Abs(r. Width); r. Y += Math.

Min(0, r. Height); r. Height = Math.

Abs(r. Height).

Thanks, I've settled with this: r = new Rectangle(r. X + Math. Min(0, r.

Width), r. Y + Math. Min(0, r.

Height), Math. Abs(r. Width), Math.

Abs(r. Height)); – John Smith Aug 6 at 16:04.

Polling usually is the way to go, since you already have a game loop much like an event loop. Either way, it would make more sense to just call Scrolling.Update() whenever you change the position of your Camera in the first place.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions