Ya i tried Stack Overflow...they never answer my questions good, or they rage about how its already been asked then it gets closed -.-;
My first question is how do you set the window height/width? (Please explain where to put this in a games code also)
Second: Is there a better way to detect collision than: .intersects()? (Explain thoroughly please)
Also example code would help too
(Please don't link other discussions questions on the internet. I've been to a lot of them and I don't understand it half the time because the answerer usually doesn't give an explanation or the inquirer doesn't ask for an explanation. I want explanations not just a: "Oh here's your code")
Also another question, where do you set variables? I have a pong game I made for my first game and I want to make a 'score' variable to call on every time the ball leaves a certain side of the screen. If you'd like to see my code let me know please.
I set the resolution of the game in the Initialize() method in the Game1.cs. This could change depending on if you were to read from an outside file to get the resolution, but I have it initialized to this resolution and later on change it accordingly.
Are you having a problem using the Intersects() method or does it just not meet your needs?
I generally declare the variable where it is needed and pass it through as an argument. Depending on the needs of the projects I would have a section for it in the properties fields to get and set score.
Are you having a problem using the Intersects() method or does it just not meet your needs?
I generally declare the variable where it is needed and pass it through as an argument. Depending on the needs of the projects I would have a section for it in the properties fields to get and set score.
No not any problems just kind've buggy when some intersects happen. (i.e. when the ball hits the top of the paddle in my pong game it shoots through the bottom of the pong and out towards the other pong.)
Can you give me an example of setting the variable?
Then search StackOverflow, or click the link that is usually provided to the question you've duplicated.
It's been closed for a reason, in this case because you couldn't be bothered to search for it.
Be productive to the conversation please. I provided that as awareness not so you could pummel me for it. Be contributive or leave please. My questions on there were slightly different and I want the code EXPLAINED. Most StackOverflow answers use technical words I don't understand. Please don't reply to this unless you'd like to contribute to my question.
No not any problems just kind've buggy when some intersects happen. (i.e. when the ball hits the top of the paddle in my pong game it shoots through the bottom of the pong and out towards the other pong.)
Can you give me an example of setting the variable?
You mean something like this?
Paddle
| o|
| |
| |
| |
Then this happens?
Paddle
| |
| |
| |
| <--o|
With the integer score declared before this. You would reference the object of the class and make a call to this property to modify it.
public class ScoreKeeper
{
int score;
public int Score
{
get { return score; }
set { score = value; }
}
}
On the other hand you could declare score and keep track of it. Then when you need to update it you could say DisplayScore(score) and use it in an argument in this case.
But this would depend on the variable name for your graphic device manager...
You would call this in your game's constructor, and anywhere where it might make sense for your code... But if it's called outside of the Game-constructor you also have to call this function:
GraphicsDevice.ApplyChanges();
To explain.... The ".PreferredBackBufferHeight" refers to a variable stored in your graphics device manager class, which is part of XNA. A back buffer is basically the 'screen image' stored in memory that will be displayed next.
Buffers are used so that the graphics card has something to display when you're not sending it new screen images, or if your game is still processing.
By setting the preferred back buffer's height/width, you are changing the image that is sent to the screen... The Game's constructor automatically creates this object for you because it needs something to render, and if you set the height and width there it will automatically display one the size you set it as.
If you set the buffer size out of the game's constructor the back buffer object won't update to the new settings because it won't create the new back buffer object until you tell it to.... So calling ".ApplyChanges" tells it to create the new back buffer, and therefore apply all of your changes.
Second: Is there a better way to detect collision than: .intersects()? (Explain thoroughly please)
Short Answer: No.
Long Answer: Possibly... but that would likely require a huge understanding of the code and how the compiler works... and you wouldn't ever need this anyway.
If you're having problems with .intersects() it's your code, not the function.
The function uses simple collision detection algorithms which are known to work.
Also another question, where do you set variables?
I, uh.... don't really know how to answer this question in a way you will understand, really....
You need to take some basic tutorials on C# for this. This is the most basic thing in programming. You have to understand this to understand anything else.
But just so I can say I answered your question, here is the answer:
The short answer is: Anywhere
The long answer is: The place they will be the most appropriate and use the least amount of memory and still be effective.
I have a pong game I made for my first game and I want to make a 'score' variable to call on every time the ball leaves a certain side of the screen.
Just to help you out a bit... if you need your score to be accessed by all elements of the game, then you probably want to declare it in the game object itself. By doing this that means everything within the game object will be able to use it (like you want it to) and that the memory will be released once the game itself goes out of scope (aka: the game gets closed).
You could also create a 'score-keeper' game object and store it there and create a method to update and retrieve the score... but that requires a bit more knowledge about how to create your own classes.
Seems like after colliding with the paddle at the top, you're setting the location of it to some value. The issue seems with how your ball returns or bounces. Maybe your code could shed some light on how you're approaching this.
My first question is how do you set the window height/width? (Please explain where to put this in a games code also)
Second: Is there a better way to detect collision than: .intersects()? (Explain thoroughly please)
Also example code would help too
(Please don't link other discussions questions on the internet. I've been to a lot of them and I don't understand it half the time because the answerer usually doesn't give an explanation or the inquirer doesn't ask for an explanation. I want explanations not just a: "Oh here's your code")
Are you having a problem using the Intersects() method or does it just not meet your needs?
I generally declare the variable where it is needed and pass it through as an argument. Depending on the needs of the projects I would have a section for it in the properties fields to get and set score.
No not any problems just kind've buggy when some intersects happen. (i.e. when the ball hits the top of the paddle in my pong game it shoots through the bottom of the pong and out towards the other pong.)
Can you give me an example of setting the variable?
Be productive to the conversation please. I provided that as awareness not so you could pummel me for it. Be contributive or leave please. My questions on there were slightly different and I want the code EXPLAINED. Most StackOverflow answers use technical words I don't understand. Please don't reply to this unless you'd like to contribute to my question.
You mean something like this?
Paddle
| o|
| |
| |
| |
Then this happens?
Paddle
| |
| |
| |
| <--o|
With the integer score declared before this. You would reference the object of the class and make a call to this property to modify it.
On the other hand you could declare score and keep track of it. Then when you need to update it you could say DisplayScore(score) and use it in an argument in this case.
I got the score figured out
and it does something like:
0-\/
| |
| |
| |
| |
then
| |
| |
| 0<- |
| |
(paddles are messing up T.T they dont actually separate xD)
[youtube]][youtube]
this is what happens if you start and dont move either paddle at all. it gets stuck in this loop, a prime example of the glitch.
That all depends...
You have to set your Display Device buffer's Height / Width variables... It should look something like this:
But this would depend on the variable name for your graphic device manager...
You would call this in your game's constructor, and anywhere where it might make sense for your code... But if it's called outside of the Game-constructor you also have to call this function:
To explain.... The ".PreferredBackBufferHeight" refers to a variable stored in your graphics device manager class, which is part of XNA. A back buffer is basically the 'screen image' stored in memory that will be displayed next.
Buffers are used so that the graphics card has something to display when you're not sending it new screen images, or if your game is still processing.
By setting the preferred back buffer's height/width, you are changing the image that is sent to the screen... The Game's constructor automatically creates this object for you because it needs something to render, and if you set the height and width there it will automatically display one the size you set it as.
If you set the buffer size out of the game's constructor the back buffer object won't update to the new settings because it won't create the new back buffer object until you tell it to.... So calling ".ApplyChanges" tells it to create the new back buffer, and therefore apply all of your changes.
Short Answer: No.
Long Answer: Possibly... but that would likely require a huge understanding of the code and how the compiler works... and you wouldn't ever need this anyway.
If you're having problems with .intersects() it's your code, not the function.
The function uses simple collision detection algorithms which are known to work.
I, uh.... don't really know how to answer this question in a way you will understand, really....
You need to take some basic tutorials on C# for this. This is the most basic thing in programming. You have to understand this to understand anything else.
But just so I can say I answered your question, here is the answer:
The short answer is: Anywhere
The long answer is: The place they will be the most appropriate and use the least amount of memory and still be effective.
Just to help you out a bit... if you need your score to be accessed by all elements of the game, then you probably want to declare it in the game object itself. By doing this that means everything within the game object will be able to use it (like you want it to) and that the memory will be released once the game itself goes out of scope (aka: the game gets closed).
You could also create a 'score-keeper' game object and store it there and create a method to update and retrieve the score... but that requires a bit more knowledge about how to create your own classes.