XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Collision detection - real basics

Last post 11/14/2009 12:26 PM by Sadjow. 1 replies.
  • 11/14/2009 12:09 PM

    Collision detection - real basics

    Hi,
    I am learnig XNA and I have a little problem. I am programming a little arcanoid game and I have little problem with collision detection.

    in update method I have somethnig like that:
                if (platforma.Collide(pilka.obramowanie)) 
                { 
                    pilka.speedFactor.Y *= -1; 
                } 

    Next in class platform (object of this class is called platforma) I have method collide:
            public bool Collide(Rectangle przedmiot) 
            { 
                Rectangle rectPlatform = new Rectangle((int)position.X, (int)position.Y, teksture.Width, teksture.Height); 
                return rectPlatform.Intersects(przedmiot); 
            } 


    when I run the game the collision isn't detected and I don't know what is wrong. :/ Any suggestions ?
  • 11/14/2009 12:26 PM In reply to

    Re: Collision detection - real basics

    Hi neosantan,

    Modify your Collide method  write this:
    public bool Collide(Rectangle przedmiot)  
    {  
                Rectangle rectPlatform = new Rectangle((int)position.X, (int)position.Y, teksture.Width, teksture.Height); 
                Console.WriteLine(przedmiot.ToString()); 
                Console.WriteLine(rectPlatform.ToString()); 
                return rectPlatform.Intersects(przedmiot);  

    Posts results in output window here.
Page 1 of 1 (2 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG