aspose file tools*
The moose likes Beginning Java and the fly likes Java3D: using for loops to draw objects I can later delete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java3D: using for loops to draw objects I can later delete" Watch "Java3D: using for loops to draw objects I can later delete" New topic
Author

Java3D: using for loops to draw objects I can later delete

Kirk Gao
Greenhorn

Joined: Aug 30, 2007
Posts: 8
Hey folks, earlier I was asking about how to do lighting correctly but figured it out since. Now I've run into a new problem. I set out to a create a 12 row by 17 column mass of bricks in my game, with the intention of being able to delete bricks that the ball in my game hits. I tried several ways of using for loops to create said bricks, but couldn't figure out any other way besides what I did below here (the code I settled on using). The problem with this is that the variables are all local to the method this for loop sits within (createSceneGraph()). Even the Branchgroup object objRoot is local to that method and not the whole class. I tried making all these variables visible to the whole class but all I end up getting are NullPointerExceptions. Can anyone suggest an alternative loop structure that will allow me to access the objects drawn (in order to delete them) later on when I want to?

----------------------------------------------------------------------------

// Create bricks.
for (float f=-0.75f; f<=0.85f; f+=0.1f)
{
for (float g=0.0f; g<=0.5f; g+=0.05f)
{
TransformGroup bricksTrans = new TransformGroup();
bricksTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D pos3 = new Transform3D();
Box box = new Box(0.05f, 0.04f, 0.1f, new Appearance());
pos3.setTranslation(new Vector3f(f, g, 0.0f));
bricksTrans.setTransform(pos3);
bricksTrans.addChild(box);
objRoot.addChild(bricksTrans);
}
}
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
hmmm, just create a different class with methods to erase/add a brick.

hint: have the bricks just change to the background color, and if the ball touches that brick, check the color, if color.equals(bgcolor); then there is no boundary and let the balls x/y keep incrementing..

Justin


You down with OOP? Yeah you know me!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java3D: using for loops to draw objects I can later delete