daveangel:Hello first let me say this is the best XNA book I've read yet!
I actually got up and running with a minimum of fuss and your XNA 2.0 updates and website updates in general were one of the deciding factors that got me to purchase your book.
Thanks! I bet you say that to all the corny, friendless, socially-awkward game programming book authors, though.
![Big Smile [:D]](/cs/emoticons/emotion-2.gif)
daveangel:Anyways I got a quick question on Ch4 in regards to the tinting sprite code on page 57. How did you figure out to multiply m_TotalSeconds by 120 to get your degrees for your sin function? From a sin graph it goes from -1 to 1 in 180 degree so it seems that would make more sense?
Anyways I tried changing the values from 120 to 360 and it doesn't seem to matter except that higher values seem to make it change color faster?
You answered your own question. Bigger numbers make the cycle loop faster. The value of 120 is completely arbitrary. Here's an email response that I gave another reader on this same topic.
EMAIL FROM READER
Im currently in Chapter 4 of your book, and I stumbled upon a
problem Im having trouble figuring out. On page 55, in the 2nd to last
paragraph, it states the smiley background will scroll to the left 50
pixels/sec. It will also oscillate 200 pixels up/down in a cycle that
repeats every 11 seconds.
The problem is I
can't follow how you reached 33 degrees/sec as the resultant value, and
I was wondering how you got that answer?
MY RESPONSE
The specific values (50 pixels per second to the left, and a sine-based vertical offset of +/-200 pixels) are completely arbitrary. They were selected using trial and error. I played with the values until I found a pattern that I liked.
The 33 degrees per second is yet another arbitrary value. It was also selected by trial and error, based solely on my poor taste. The "roughly 11 seconds" is the time it takes to cover a full 360-degree circle if you're incrementing your angle by 33 degrees per second (360 / 33 = 11-ish).
My thought process went something like this:
"I want the background to constantly scroll to the left. I'll need a variable to drive that, so I can easily make changes to the speed at which it scrolls. Let me try -20. Too slow. -100? Too fast. -50? That looks good. But it's a little boring. ..."
Rather than scroll vertically, I decided to have the background oscillate up and down. An oscillation repeats indefinitely, so I needed to decide how long it should take for the background to move through one cycle. I ultimately picked 33 seconds, and decided that the motion of the background would be limited to 400 pixels (-200 to +200).
It's completely arbitrary, like I said. The key points here are that: you should settle on a basic idea of what you want to do, then drive your core logic with variables that you can tweak. Then play with the settings until you get something that you like.
This chapter's example game is very simple, but the same basic idea applies to more complex game logic. For instance, if you create a weapon in your game that inflicts damage, make the amount of damage variable. That way, you'll be able to make drastic changes to how your game plays by making minor changes to your code. (Or in the case where those values coming from a data file, no changes to your code).
If I misunderstood your question, or didn't answer it very well, please let me know. I'm not the sharpest knife in the drawer some times. :)
Programming involves a lot of reasoning, planning, and logic, but making games adds creative license to the mix. Some decisions are based mostly on aesthetics and playability -- like those pretty post-processing visual effects, cutting-edge AI systems, and true-to-life physics engines that eat up your per-frame time budget.
Hope that helps.
-- joe
P.S. Sorry for the delayed response. Work's been kicking my fanny this last month or so.
There are 10 kinds of people in this world -- Those that can count in binary, and those that can't.