File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kirk Gao
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic