im trying to get a picture in XNA at the bottom right edge of my screen.
i managed to get the game full screen.
my screen is 1920 by 1080, so i entered this code:
protected override void Initialize()
{
// TODO: Add your initialization logic here
bat1Position = new Vector2(0, 0);
bat2Position = new Vector2(1920-bat2.Width, 1080-bat2.Height);
this.IsMouseVisible = true;
base.Initialize();
}
but i get this error: (i get the same error whatever i insert after the ","
can anyone help?
Thanks
Rick
Rick van LeeuwenPosted Oct 26, 2011, 3:51 PM
I did it!
read below how i fixed it.
i still didn't manage to do it.
i dont understand what you are saying Vulpes
I changed some things in my code. So this is what i want now:
i want that when the Xbox360 controller is connected, there is a message that says how to control the pong bats with the controller
and when its not connected, there is message to show how to control them with the keyboard.
this is the code:
(some parts are Dutch, that's my language :P)
public void inputAangeven()
{
spriteBatch.Begin();
if (inputController.IsConnected)
{
spriteBatch.DrawString(tekst, "Besturing links: Dpad Up en Down, rechts: Y en A", new Vector2(300,300), Color.White);
}
else
{
spriteBatch.DrawString(tekst, "Besturing links L-shift en L-ctrl, rechts: pijltje omhoog en omlaag", new Vector2(500,500), Color.White);
}
spriteBatch.End();
}
i placed it directly above the update method.
and IN the update i call the method, this works, because i tested with playing a sound.
but with the text it doesn't work.
it shows non of the 2 lines.
But when the game exits i see the message for like 1/4 of a second. very weird.
So does anyone know how i can do this. I really need to know for further programming :P
it has to be possible :D
i did it:
i made a boolean: blnControllerConnected
now in the inputAangeven method(in english it would be declareInput method :P) i set the boolean true/false
public void inputAangeven()
{
if (inputController.IsConnected)
{
blnControllerConnected = true;
}
else
{
blnControllerConnected = false;
}
}
and in the draw method i made an if statement,
like this:
if (blnControllerConnected==true)
{
spriteBatch.DrawString(tekst, "Besturing links: Dpad Up en Down, rechts: Y en A", new Vector2(300,
300), Color.White);
}
else
{
spriteBatch.DrawString(tekst, "Besturing links L-shift en L-ctrl, rechts: pijltje omhoog en omlaag", new
Vector2(500, 500), Color.White);
}
VulpesPosted Oct 19, 2011, 5:18 PM
Rick van LeeuwenPosted Oct 19, 2011, 3:30 PM
i need it in the update method, when the bal hits the bat(just for test, should be when NOT hitting the bat). so i have:
if (balPosition.X<18 && balPosition.Y > bat1Position.Y)
{
if (balPosition.Y
spriteBatch.Begin();
spriteBatch.DrawString(gameOver, "Game over", Vector2.Zero, Color.White);
spriteBatch.End();
}
}
and nothinh happens
when i do
if (balPosition.X<18 && balPosition.Y > bat1Position.Y)
{
if (balPosition.Y
this.exit();
}
}
that works, so that part of the code is right
VulpesPosted Oct 19, 2011, 3:18 PM
Rick van LeeuwenPosted Oct 19, 2011, 2:54 PM
i want that when its game over, i get text with game over
i found out how to draw a text, but that's only a text in the draw method, so it is always visible. I want it only when it is game over, so in update method.
so i need it here:
if (balPosition.X<18 && balPosition.Y > bat1Position.Y)
{
if (balPosition.Y
HERE I WANT THE TEXT GAME OVER
}
}
i tried:
spriteBatch.DrawString(gameOver, "GAME OVER!", new Vector2(0.25f * MaxX, 50.0f), Color.Green);
with spriteBatch = new SpriteBatch(GraphicsDevice); in initialization
but than the game freezes when it is game over and nothing is shown
Rick van LeeuwenPosted Oct 19, 2011, 1:20 PM
but now i have a new problem :D
I am making a simple Pong game (my first XNA project)
What i currently have is:
- moving ball that bounces at all sides
- the "bats"(don't know if that is same in English :P i'm dutch) dat move up and down with buttons
- code that prevents the bats to 'leave the screen' when they are at the bottom/top of the screen.
now i need that when the bal hits the bat, it bounces BUT when it DOESN'T hit the bat, it is game over.
i know what i need to do, just when x= bat.width(17) and y is between bottom and top of bat, then bounce and otherwise, game over :P
but i dont know how to set the "between" command :D
EDIT: i figured it out, i did:
if (balPosition.X<18 && balPosition.Y > bat1Position.Y)
{
if (balPosition.Y
this.Exit();
}
}
And it worked
Javeed M ShaikhPosted Oct 19, 2011, 11:38 AM
Rick van LeeuwenPosted Oct 19, 2011, 11:35 AM
so the 1920-bat2.height should work
i don't understand what you mean. it's not a variable. it is just the height of the bat2 sprite
and when i do:
bat2position = new Vector2(1920-bat2.Width, 1080) it also doesnt work
it only works when i put in only numbers (1920, 1080) but than you dont see it, because it starts outside of my screen.
it works only when i just subtract the width and height myself and put it in then, like (1900,980) which is a guess. I think i'll do that :D
VulpesPosted Oct 19, 2011, 11:33 AM
Javeed M ShaikhPosted Oct 19, 2011, 11:31 AM
VulpesPosted Oct 19, 2011, 11:27 AM
Are you you sure that you've initialized it to an object somewhere?