Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualAldacron

Posted 02 September 2012 - 07:42 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

for(int i = 0; i < BRICKS.size(); i++)
{
	 // Get a reference to the Brick instance at index i in the array list.
	 Brick b = BRICKS.get(i);

	 // Use the Brick reference to get the values for the rectangle.
     BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}

The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

public ArrayList<Rectangle> getBrickBounds()
{
	for(int i = 0; i < BRICKS.size(); i++)
	{
        // Get a reference to the Brick instance at index i in the array list.
        Brick b = BRICKS.get(i);
	
        // Use the Brick reference to get the values for the rectangle.
        BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
	}
	return BRICKBOUNDS;
}

And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

ArrayList<Rectangle> getBrickBounds()
{
	return BRICKBOUNDS;
}

#5Aldacron

Posted 02 September 2012 - 07:42 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

for(int i = 0; i < BRICKS.size(); i++)
{
	 // Get a reference to the Brick instance at index i in the array list.
	 Brick b = BRICKS.get(i);

	 // Use the Brick reference to get the values for the rectangle.
	  BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}

The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

public ArrayList<Rectangle> getBrickBounds()
{
	for(int i = 0; i < BRICKS.size(); i++)
	{
		// Get a reference to the Brick instance at index i in the array list.
        Brick b = BRICKS.get(i);
	
        // Use the Brick reference to get the values for the rectangle.
        BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
	}
	return BRICKBOUNDS;
}

And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

ArrayList<Rectangle> getBrickBounds()
{
	return BRICKBOUNDS;
}

#4Aldacron

Posted 02 September 2012 - 07:41 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

for(int i = 0; i < BRICKS.size(); i++)
{
	 // Get a reference to the Brick instance at index i in the array list.
	 Brick b = BRICKS.get(i);

	 // Use the Brick reference to get the values for the rectangle.
	  BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}

The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

public ArrayList<Rectangle> getBrickBounds()
{
	for(int i = 0; i < BRICKS.size(); i++)
	{
		// Get a reference to the Brick instance at index i in the array list.
			Brick b = BRICKS.get(i);
	
			// Use the Brick reference to get the values for the rectangle.
			BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
	}
	return BRICKBOUNDS;
}

And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

ArrayList<Rectangle> getBrickBounds()
{
	return BRICKBOUNDS;
}

#3Aldacron

Posted 02 September 2012 - 07:40 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

[code lang = "java"]
for(int i = 0; i < BRICKS.size(); i++)
{
// Get a reference to the Brick instance at index i in the array list.
Brick b = BRICKS.get(i);

// Use the Brick reference to get the values for the rectangle.
  BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}
[/code]

The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

[code lang = "java"]
public ArrayList<Rectangle> getBrickBounds()
{
for(int i = 0; i < BRICKS.size(); i++)
{
// Get a reference to the Brick instance at index i in the array list.
Brick b = BRICKS.get(i);

// Use the Brick reference to get the values for the rectangle.
BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}
return BRICKBOUNDS;
}
[/code]

And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

[code lang = "java"]
ArrayList<Rectangle> getBrickBounds()
{
return BRICKBOUNDS;
}
[/code]

#2Aldacron

Posted 02 September 2012 - 07:38 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

for(int i = 0; i < BRICKS.size(); i++)
 {
     // Get a reference to the Brick instance at index i in the array list.
     Brick b = BRICKS.get(i);

     // Use the Brick reference to get the values for the rectangle.
      BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
}


The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

[source lang = "java"]public ArrayList<Rectangle> getBrickBounds(){ for(int i = 0; i < BRICKS.size(); i++) { // Get a reference to the Brick instance at index i in the array list. Brick b = BRICKS.get(i); // Use the Brick reference to get the values for the rectangle. BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick)); } return BRICKBOUNDS;}[/source]

And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

[source lang = "java"]ArrayList<Rectangle> getBrickBounds(){ return BRICKBOUNDS;}[/source]

#1Aldacron

Posted 02 September 2012 - 07:36 PM

another issue...

[source lang="java"] public Rectangle getBrickBounds() { for(int i = 0; i < BRICKS.size(); i++) { BRICKBOUNDS.add(new Rectangle(Brick.xbrick, Brick.ybrick, Brick.widthbrick, Brick.heightbrick)); } }[/source]

im trying to return a rectangle for each Brick in my BRICKS array for collision, but for each variable it says that it cannot make a static reference to a non static variable. i have no idea what that means Posted Image


You aren't accessing variables. You're trying to access members using the Brick class itself, rather than any instances of it.

for(int i = 0; i < BRICKS.size(); i++)
	    {
            // Get a reference to the Brick instance at index i in the array list.
            Brick b = BRICKS.get(i);

            // Use the Brick reference to get the values for the rectangle.
		    BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
	    }


The other issue is your return value. You declare the method to return a single Rectangle, but you say you want to return a Rectangle for each brick. And then you aren't returning anything at all. If this method is being called externally, then you probably want to be returning BRICKBOUNDS. Meaning, you need to declare the function to return ArrayList<Rectangle> (or List<Rectangle>) rather than just Rectangle. Then the function becomes:

public ArrayList<Rectangle> getBrickBounds()
{
    for(int i = 0; i < BRICKS.size(); i++)
    {
        // Get a reference to the Brick instance at index i in the array list.
		    Brick b = BRICKS.get(i);
	 
		    // Use the Brick reference to get the values for the rectangle.
		    BRICKBOUNDS.add(new Rectangle(b.xbrick, b.ybrick, b.widthbrick, b.heightbrick));
    }
    return BRICKBOUNDS;
}


And a piece of advice: if you call this method a lot, it can be really inefficient to create a new Rectangle for each brick every time you call it. It might be a better strategy to replace the xbrick, ybrick, widthbrick and heightbrick members of the Brick class with a Rectangle called bounds. Then you can add methods, if you need them, like getX, getY, getWidth, getHeight, and getBounds that return the appropriate values. You can add each Rectangle to BRICKBOUNDS when a new Brick is created. Then, the only time you need to modify the list is when a brick is destroyed -- just remove its rectangle from the list. At that point, getBrickBounds becomes a single line:

ArrayList<Rectangle> getBrickBounds()
{
    return BRICKBOUNDS;
}

PARTNERS