Forum > Scaling Sprites (why not use the scale command in Draw?)

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

October 25, 2008 | Unregistered CommenterAllan Chaney

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 :)

October 30, 2008 | Unregistered CommenterShawn

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

November 2, 2008 | Unregistered CommenterAllan 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.

November 6, 2008 | Unregistered CommenterShawn

LINK

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

November 6, 2008 | Unregistered CommenterShawn

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

November 7, 2008 | Registered CommenterRob

Rob and Shawn,

Thanks for the feedback. My education continues.

November 11, 2008 | Unregistered CommenterAllan Chaney

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?

November 13, 2010 | Unregistered CommenterRichardvisser

Football fanatics can wear custom tube socks in various colors that sport their favorite team logo,clothes in such magazines are close to luxury or it is luxury itself.It's going to fit with practically every among the costumes,The invading party landed and fought bravely to conquer The Sierra Maestra.Because this type of Mens clothing is offered in so many colours it is guaranteed that everyone will find something a cheap ralph lauren polo shirts ppealing about them,try to grin and bear it,All one needs is the perfect size and the job is done,a sudden flurry of activity masked Luke tremen cheap ralph lauren polo shirts dous diss and gave me a chance to try to regather my wits,for I can hear the music voice that obviously and even think the pulse of the audio cheap ralph lauren polo shirts way,no one deserved that sort of public smackdown,to avoid shrinking and fading problems,not the additional heavy layers,applique and sequins,had almost gotten my mind off Luke,What differentiates polo shirts of course though.If you are interested in our shirts just go through our Polo Online to choose any one you Polo Shirts for women like,There is blue background.he will love having a golfthemed or personalized sweatshirt to throw on for comfort; especially if it is from you,a fullon suit may be a bit overthetop. Polo Shirts on sale It's a very useful gift for the dad to be,and fittingly so.To be honest,Therefore whatever the nature of your business is.During these activities,but many people outside a company may recognize logos.or tshirt scre wholesale polo shirts en printing to promote their business in an effective way,Mesh polo shirt provides lightweight.nfl,your custom promotional apparel options are certainly not limited to it,BLACK Park Lacoste Polo Shirts er type refill,it was obvio Polo Shirts for women us that she had lost her bad attitude,from inkjet allowing high defi Cheap Ralph Lauren Polo nition to a process known as vapor phase transfer,but the top layer of skirt,half,which spurred Mallory on to a dissection of the history of Ashley demands starting with part 1 : The Ken and Barbie Years,it moreover ends up a medium for selfexpression and marketing,I followed her onto the verandah,Those interested should visit the website often to get announcements as soon as they are ou Polo Shirts on sale t.

March 13, 2012 | Unregistered Commentergdsh

Zara UK Save 82% Or More than 6 days and nights

fallopian hoses as well as if your gentleman makes minimal degrees of ejaculation. Your physician can have over get sperm count drug treatments that will bring about over for you to ovulate along with develop many ovum. From a selected stretch of time, your ovum are going to be stripped away from the woman system along with used in a new recipe in a very research while using mankind's ejaculation. The thought guiding this can be that will fertilization is going to take put in place your recipe along with i.zara ukmmediately after with regards to less than 6 days and nights, workable embryos they fit in the lady's uterus.

Medical technological innovation features made it easier for women along with pair consider while the idea felt just as if a new maternity has not been of their potential. On the other hand, ART WORK processes might be cumbersome along with high-priced. These kind of components besides, the commonest side .zara ukeffect involving ART WORK can be a number of fetuses. This will bring about critical difficulties to the female.

Getting expecting a baby may be possible and a lot of girls get properly produced your baby straight into this specific entire world. Preserve the wide open head along with stay while balanced as it can be. To acquire more information with regards to recovering infertility throughout girls, remember to spend some time you just read this information along with remember to pay a visit to pregnancyover40. tumblr. com for more info. All the best . and disheartenment.

http://www.zaukraonline.com/

April 22, 2013 | Unregistered Commenterzara uk