Thread: Question about SuperMario

  1. #1
    Registered User
    Join Date
    Oct 2012

    Question about SuperMario

    hi dear guys !
    i have a problem in supermario xna ! could u plz help me??

    Look ! i have defined struct (rect) with this code in public class Game1:

    public struct rect
                public Texture2D texture;
                public Rectangle posSize;
                public void draw(SpriteBatch s)
                    s.Draw(texture, posSize, Color.White);
    public rect bigRect1,bigRect2;
    public rect[] bigRectangles = new rect[2]; //define an array
    then i initialize them in public Game1:
    bigRect1.posSize = new Rectangle(0, 450, 500, 150);
                bigRect2.posSize = new Rectangle(0, 0, 1450, 100);
    now i want to put them in an array (named bigRectangles) and then i wanna draw them ... so how can i draw them ? (actually i wanna draw them with a for loop and array)


  2. #2
    Registered User cstryx's Avatar
    Join Date
    Jan 2013
    Create a Texture2D and use the SpriteBatch's Draw() method to draw the Rectangle. Don't forget Begin() and End() for when you start and finish making the updates for the overridden Draw method...

    foreach (Rectangle rect in bigRectangles)
    	spriteBatch.Draw(texture, rect, color);
    A rectangle is a structure that should have it's location defined, so there's no need to define a set location for it unless you want to change it. Then I would use an index based loop, and multiply by a constant value for where you want the output rectangle to be drawn to, as well as padding, if any.
    Last edited by cstryx; 02-01-2013 at 09:58 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Backgrounds And some questions about SuperMario
    By Seniorija in forum Game Programming
    Replies: 4
    Last Post: 01-27-2013, 03:27 PM
  2. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  3. *szString = things question/memory question
    By Jang in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 04:59 AM
  4. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  5. Self regiserting DLLs question and libraries question.
    By ApocalypticTime in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2003, 02:02 PM