Forum > Scaling Sprites (why not use the scale command in Draw?)
I know Rob Miles is away at PDC right now, so maybe he will respond afterwards.
I can comment, at least halfway on your second question. A class being allocated on the heap vs. a struct being allocated on the stack offers a bit of a performance boost (at least that is what I understand).
Not sure if that makes any sense to you or not, just hate seing questions go unanswered :)
Thanks for the reply Shawn.
I'll keep waiting. There's no hurry.
Right now I'm stuck on trying to develop the code for animated sprite collision where the sprites are duplicated using an array and for loop.. I'm using Rob's Tomotoes code structure as my basis (except I'm using rain drops as the texture).
I have the raindrops falling from the top of the screen to the bottom. I can change the number of drops and their speed and origin position is randomly generated. I have collision detection working against a moving controllable player sprite. So it looks like real rain with a guy running around. When the rain hits his head, there is a splash animation inserted at the last location of the rain drop.
My brain strain problem is I want those raindrops to be animating as they are falling so they look more realistic.
I don't suppose you know of any code or tutorial that shows this sort of thing. (Moving animated sprites (not just rotating) duplicated on the screen multiple times with collision detection against other animated moving sprites)
Thanks
Allan Chaney
Actually, not specific to your issue, but here is a series that walks through building a 2d game:
http://www.nickontech.com/archive/#tileengine
I believe it was Episode 6, Video A that developed an animated sprite class. That may at least help guide you in what you want done.
Sorry about that, there is a clickable link :)
Also, I do not remember if he covered the collision part in that video or not. So you may want to try the next one also if the first does not cover the collisions.
Hope that helps!
Shawn
Sorry about the delay in getting back to you. Been awfully busy recently. I've put my answers in line...
My 1st question is, Why do you use an algorithim to scale sprites to the displaywidth and height in your Bread and Cheese game when it seems that you could just use the scale feature built into the SpriteBatch
Draw method. There is an overload for Draw that includes scale. Would it not be simpler to just use that built-in scale feature in Draw and adjust it relative to DisplayWidth and Height?
>>> Indeed I could use the scale. The thing is that I wanted to use this to teach about programming and scaling. Perhaps in a future book I could mention that the method is avaiable.
My 2nd question is, On the XNA Creator's Club Website in the Getting Started section, there is a tutorial teaching you to make a 2D "Shoot the Flying Saucers" game. In this tutorial, the author uses a seperate class to define his sprites. He calls his class GameObjects and in that class assigns the various sprite fields etc. In his main Game class he then refers to those fields by using GameObjects dot field. (GameObjects.field) However in your book in the Bread and Cheese game you use a Structure to hold the sprite information. Is this simply a personnal coding perference or is one way better than the other?
>>> I wanted to start with structures and then move into objects later.
My Final Quesiton is more complicated so please bear with me. I've read a few books that use GameComponents and Game Services to organize their code. (I'm specifically referring to "Beginning XNA 2.0 Game Programming" by Lobao, Evangelista and Faris.) This organizational structure seems bizarrly complicated to me and it seems to me that it breaks the elegance of using the class structure and proper inheritance/parameter passing between classes that you learn in C#. However the game code works and in some regards it's much simpler because is seems that it gets around all of the inheritance problems that become very complicated using multiple classes.
Since you don't address this type of structure in your book, would you be willing to offer your opinion on the use of GameComponents/Services vs. classes as a way to structure game code in C# and XNA?
>>> I've not had a chance to look at this book I'm afraid. If you want my philosophy on game structure take a look at my Starlight game for Smartphone. It is not an XNA game, but it has a lot of stuff about game design and sprite management. It also has some stuff about animation that you might find useful.\
http://msdn.microsoft.com/en-us/library/aa446569.aspx
Rob and Shawn,
Thanks for the feedback. My education continues.
Hello,
I am new on this forum. Very happy to find this forum. First i will read everything here and then i will respond to the topics i can.
My hobbys are darts and everything whats has to do with windows.
The best thing windows ever made is the windows 7 phone.
What do you like of windows?
Hello,
I am a newbie on this forum and just wanna say hello,
I am pieter from the netherlands, my hobbys are Collecting Sports Autographs
and playing online Roulette.
happy that i found this community
!!
I've got an account here.
I really like the environment on this web site. .
Today I got a web site from son via one of my google buzz.
what do you thinks it is? !
http://com-cnbc.com/heart-attack-symptoms-that-you-should-know



Rob,
As a new C#/XNA programmer, I've really enjoyed your book, "Learning Programming Now!" If you don't mind I have a few basic coding questions.
My 1st question is, Why do you use an algorithim to scale sprites to the displaywidth and height in your Bread and Cheese game when it seems that you could just use the scale feature built into the SpriteBatch.Draw method. There is an overload for Draw that includes scale. Would it not be simpler to just use that built-in scale feature in Draw and adjust it relative to DisplayWidth and Height?
My 2nd question is, On the XNA Creator's Club Website in the Getting Started section, there is a tutorial teaching you to make a 2D "Shoot the Flying Saucers" game. In this tutorial, the author uses a seperate class to define his sprites. He calls his class GameObjects and in that class assigns the various sprite fields etc. In his main Game class he then refers to those fields by using GameObjects dot field. (GameObjects.field) However in your book in the Bread and Cheese game you use a Structure to hold the sprite information. Is this simply a personnal coding perference or is one way better than the other?
My Final Quesiton is more complicated so please bear with me. I've read a few books that use GameComponents and Game Services to organize their code. (I'm specifically referring to "Beginning XNA 2.0 Game Programming" by Lobao, Evangelista and Faris.) This organizational structure seems bizarrly complicated to me and it seems to me that it breaks the elegance of using the class structure and proper inheritance/parameter passing between classes that you learn in C#. However the game code works and in some regards it's much simpler because is seems that it gets around all of the inheritance problems that become very complicated using multiple classes.
Since you don't address this type of structure in your book, would you be willing to offer your opinion on the use of GameComponents/Services vs. classes as a way to structure game code in C# and XNA?
Thanks so much for your help.
Allan Chaney