Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Code Help - Pong


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
9 replies to this topic

#1 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 03:56 PM

I think my errors have to do with with several of my SpriteManager (Which is a GameComponent) Fields

Vector2 position;
		Vector2 speed;
		Rectangle screenRectangle;
		Vector2 direction;

all have the same error, "is never assigned to and will always have its default value". But I do think I am assigning them each in my classes.

//This is My Computer Class Constructor  Which Inherits from the BasePaddle Class
	   public ComputerPaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 position, SpriteManager spriteManager)
			: base(texture, screenBounds, direction, position)
			{
this.texture = texture;
		    this.screenBounds = screenBounds;
			 this.direction = direction;
   	 	 this.position = position;
   	 	 this.spriteManager = spriteManager;
			}

//This is my Player Paddle Class  Constructor Which Inherits from the BasePaddle Class
		 public PlayerPaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 position)
			: base(texture, screenBounds, direction, position)
			{
	         this.texture = texture;
			 this.screenBounds = screenBounds;
   	 	 this.direction = direction;
   	 	 this.position = position;
			}


So what I am i doing wrong? I don't know why my SpriteManager has null fields when I (I think) i am assigning them, I am sorry that I am asking so many questions, I don't have anyone other than you to ask.

So my question is why are my SpriteManager fields null? I don't understand what I am doing wrong/ I don't know what I didn't do.

Edited by mistervirtue, 25 October 2012 - 04:20 PM.


Sponsor:

#2 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
1Likes
Like

Posted 25 October 2012 - 04:12 PM

First question. Why are the private variables for the cpupaddle and the playerpaddle different? Secondly, we'll have to see how you are calling the two constructors to know why they are showing up null.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#3 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 04:19 PM

First Answer. The Only diffrence is that CPUpaddle uses the spriteManager to find the ball position.

protected override void LoadContent()
   {
   spriteBatch = new SpriteBatch(Game.GraphicsDevice);

   Texture2D playerPaddleTexture = Game.Content.Load<Texture2D>("JongPaddle");
   playerPaddle = new PlayerPaddle(playerPaddleTexture, screenRectangle, direction, position);

   Texture2D computerPaddleTexture = Game.Content.Load<Texture2D>("JongPaddle");
   computerPaddle = new ComputerPaddle(computerPaddleTexture, screenRectangle, direction, position, this);

   Texture2D ballTexture = Game.Content.Load<Texture2D>("ball");
   ball = new Ball(ballTexture, screenRectangle);

    StartGame();
   base.LoadContent();
   }

And that is how I call all of my classes.

Edited by mistervirtue, 25 October 2012 - 04:19 PM.


#4 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 25 October 2012 - 05:42 PM

Are the JongPaddle images actually being found? IE. playerPaddleTexture != null? Also, where are you assigning or initializing screenRectangle, direction, and position?
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#5 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 05:49 PM

The JongPaddles are being found, but nothing else is. So I don't know what the issue there is. Also to answer your other question I think I am doing the assigning or intializing in the basePaddle Class.

namespace JONG_PongClone_
{
public abstract class BasePaddle
  {
  //Texture For the Block
  protected Texture2D texture;
  //position of the Block
  protected Vector2 position;
  //Directoin of the Block
  protected Vector2 direction;
  //Collision Rectangle for the block
  protected Rectangle screenBounds;


#6 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
1Likes
Like

Posted 25 October 2012 - 06:58 PM

All I see there are variable declarations. No initializations or assignments.

Show the code where you are actually setting the values for screenRectangle, position, and direction.

Edited by Alpha_ProgDes, 25 October 2012 - 07:00 PM.

Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#7 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 07:09 PM

That is my problem right there. I just realized I never assigned any value to my variables. That is problem I think. Thanks for kind of walking me through this.

#8 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
1Likes
Like

Posted 25 October 2012 - 07:14 PM

Feel free to hit the Up arrow on all my posts :).

That's how we show thanks around here now :)
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#9 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 07:42 PM

We are not done quite yet. I still need to try it out.

#10 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 October 2012 - 08:15 PM

All I see there are variable declarations. No initializations or assignments.

Show the code where you are actually setting the values for screenRectangle, position, and direction.


Okay I can't declare these values right. My screenRectangle is supposed to be my Window diminsions, my positions is supposed to keep track of the paddle location.




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.



PARTNERS