Xna Xbox player joined and player left
Posted: Sun Feb 05, 2012 3:29 pm
this is another thing i made 100% by my self this time it tells the person on screen when player 2 joins the game and when he/she leaves the game.
so to start off with you will need to make 2 images one for player2 has joined and one for player 2 has left.
next you will have to add them to the content by right clicking it and pressing add existing item.
next we will need to make some variables
so like before under public class Game1 : Microsoft.Xna.Framework.Game
{
add the following
these are what we will use later on
next we will need to load the content for the game so under
protected override void LoadContent()
{
so under
protected override void Update(GameTime gameTime)
{
so under protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
i hope this helped you please give me a like if it did as they always help =]
so to start off with you will need to make 2 images one for player2 has joined and one for player 2 has left.
next you will have to add them to the content by right clicking it and pressing add existing item.
next we will need to make some variables
so like before under public class Game1 : Microsoft.Xna.Framework.Game
{
add the following
Code: Select all
int jointime, leavetime, shownjoin, shownleave;
Texture2D join, leave;
Rectangle joinrec, leaverec;
these are what we will use later on
next we will need to load the content for the game so under
protected override void LoadContent()
{
Code: Select all
now that we have loaded all our content we will need to do the logic's of what will happenjoin = Content.Load<Texture2D>("join");
joinrec = new Rectangle(0,graphics.PreferredBackBufferHeight - the hight of your image,Width of yourimage, hightof your image);
leave = Content.Load<Texture2D>("leave");
leaverec = new Rectangle(0,graphics.PreferredBackBufferHeight - the hight of your image,Width of yourimage, hightof your image);
jointime = 0;
leavetime = 0;
shownjoin = 0;
shownleave = 1;
so under
protected override void Update(GameTime gameTime)
{
Code: Select all
now what we will need to do is go and make this show up the in draw method.// first we will do the count down
if(jointime > 0)
jointime -= 1;
if (leavetime > 0)
leavetime -= 1;
// this says if the join time is grater then 0 then - 1 when it gets to 0 do not take any more away
//now what we will do is make it so that when you put the controller in it will be set to 500 or what ever time you want this is counted in frames so a 30fps so 500 / 30 will give you the time that it will stay on screen and so on.
if (GamePad.GetState(PlayerIndex.Two).IsConnected && shownjoin == 0)
{
jointime = 500;
shownjoin = 1;
shownleave = 0;
};
// this is saying if they pad is connected and it has not shown you the join sign already show the join sign and set the shown leave sign to 0 and the shown join sign to 1.
if (GamePad.GetState(PlayerIndex.Two).IsConnected == false && shownleave == 0)
{
leavetime = 500;
shownleave = 1;
shownjoin = 0;
};
// this is doing the same but for the leave time and resetting the joinsign.
so under protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
Code: Select all
// right remember to add this at the very bottom so that it will show up on top of every thing else
if (jointime > 0)
{
spriteBatch.Draw(join, joinrec, Color.White);
};
if (leavetime > 0)
{
spriteBatch.Draw(leave, leaverec, Color.White);
}
// this is saying if the time for join or leave is over 1 then show for note they will never be on at the same time as we stopped that from happening in the update method.
i hope this helped you please give me a like if it did as they always help =]