• Advertisement
Sign in to follow this  

Basic XNA Question

This topic is 1453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I'm learning some XNA game programming in C#. I've learned a bit, but still have some basic questions about navigating the screen. When you make a Rectangle object the arguements are X,Y, Width, Height. When this is drawn to the screen X,Y coordinates are for the top left corner, and width and height are width and height of the rectangle. This basically tells you where the image will be drawn on the grid, but how? Must be something in the draw function that takes care of it?

 

I guess that's not my biggest question though. When you create a basic sprite with a Texture2D, a Vector2 marking Location, and Vector2 marking size this is basically making a Rectangle to graph in the same way, but what's going on in that sense? Lol...I'm quite confused about it, but think it's necissary to get a better understanding of the screen and system..

 

Oh yeah...

 

I can do basic box collision by setting two sprites values into a Rectangle object and using the intersect method on the objects corner point and dimensions but how can I recreate this using the sprite's own dimensions via data members?

 

wouldn't sprite1.Postion.X + sprite1Size.X be the upper edge?

 

I tried a few things like

 

sprite1.Postion.X + sprite1Size.X < sprite2.Postion.X + sprite2Size.X

 

and various other XY combinations and inequalities, but it didn't seem to be matching to the sprite's boxes, as they didn't have to collide to trigger a reaction, lol

 

Thanks in advance for any help.

Edited by JeremyB

Share this post


Link to post
Share on other sites
Advertisement

(x = 0, y = 0) is the top left of the screen. The values increase down and to the right. So...

 

 


wouldn't sprite1.Postion.X + sprite1Size.X be the upper edge?

 

That would be the right edge.

 

 


I tried a few things like
 
sprite1.Postion.X + sprite1Size.X < sprite2.Postion.X + sprite2Size.X
 
and various other XY combinations and inequalities, but it didn't seem to be matching to the sprite's boxes, as they didn't have to collide to trigger a reaction, lol

 

That should do it, assuming you are checking all 4 edges.

Share this post


Link to post
Share on other sites

Hey,

 

thanks Phil :) Still really confused though. I just realized I didn't understand this much at all...

 

I figured position.X + size.X would be the top edge because I figured

 

position.X meant the the top left corner of the image....

 

I figured the top corner plus width would give you the top edge....

 

What's position.X actually pertain to

 

and position.Y

 

"That should do it, assuming you are checking all 4 edges."

 

Lol, since I'm not sure how to even check for one edge properly I guess that's why I'm not getting this right...

 

Why is position.X + size.X the right edge?

 

also since there's only p.X p.Y and size.X and size.Y how do you get four edges out of that....

 

Can make this work with rectangles, but I guess I have a problem with not understanding the grid system fully and doing it myself...

 

thanks for any help...

Share this post


Link to post
Share on other sites

I noticed I'm visualizing this wrong too.... I'm in the way of thinking that position.X + size.X makes an edge like a line....but does it actually mark a point on the screen?

 

it's really weird in my mind right now.

 

(position.X + size.X) - that would equate to a single number.... but what is that number without and (x,y) it can't be a point on the screen can it?

Edited by JeremyB

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement