Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Basic XNA Question

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 JeremyB   Members   

240
Like
0Likes
Like

Posted 31 January 2014 - 10:48 AM

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, 31 January 2014 - 10:52 AM.

Fledgling game company: Terra Byte Studios.

Fallen: Currently working on script and RPG mechanics.

https://www.tumblr.com/blog/terrabytestudio


#2 phil_t   Members   

7999
Like
0Likes
Like

Posted 31 January 2014 - 11:00 AM

(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.



#3 JeremyB   Members   

240
Like
0Likes
Like

Posted 31 January 2014 - 12:07 PM

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...


Fledgling game company: Terra Byte Studios.

Fallen: Currently working on script and RPG mechanics.

https://www.tumblr.com/blog/terrabytestudio


#4 JeremyB   Members   

240
Like
0Likes
Like

Posted 31 January 2014 - 12:11 PM

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, 31 January 2014 - 12:13 PM.

Fledgling game company: Terra Byte Studios.

Fallen: Currently working on script and RPG mechanics.

https://www.tumblr.com/blog/terrabytestudio





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.