Hi guys,
I’m using label on my project and ihave to change the text in it a few times, but when i do that it’s writing on the previous text, it’s not replacing it.
Do you know why?
Rafael
Hi guys,
I’m using label on my project and ihave to change the text in it a few times, but when i do that it’s writing on the previous text, it’s not replacing it.
Do you know why?
Rafael
Do you mean it writes the new text on top (depth-wise) of the old text or the text doesn’t change at all.
In HUD3DTest, there is the Button labled “Click me to add dots…”, which consists of an Image Widget and a Label Widget. When you click on it, the consited Label gets the new text and it works. Could you please give me an example?
Marvin
I’m working like this
if (timeCounter > 0){
if (timeCounter == totalTime){
tipLabel.setText(" ");
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText1() );
}
else if (timeCounter == (int) (0.8 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText2() );
}
else if (timeCounter == (int) (0.6 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText3() );
}
else if (timeCounter == (int) (0.4 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText4() );
}
else if (timeCounter == (int) (0.2 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText5() );
}
those methodes returns a string like “Text1 \n”
but the problem is it only clears the text in the first line, not in the other lines and it’s writing the text up when it should write it down.
like
Text2
Text1
I assume, totalTime is the time, your render-loop is running. And you select for a specific value of this time. Never do this. You won’t certainly hit this exact point in time, since a frame can take 50ms, 35ms, 12ms,… to be rendered. You can ask for >= and handle some flags to keep it from repeated execution or you can have it much easier…
Why don’t you use ExtRenderLoop? It handles the main loop, the gameTime and much more… and is e.g. able to schedule operations. Consider this:
public class myMainClass extends ExtRenderLoop
{
...
protected void onIntervalHit(Interval interval, long gameTime, long frameTime)
{
if (interval.getName().equals( "SET_TEXT1" ))
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText1() );
else if (interval.getName().equals( "SET_TEXT2" ))
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText2() );
...
}
public myMainClass()
{
...
this.addInterval( new Interval(3000L, "SET_TEXT1") );
this.addInterval( new Interval(4000L, "SET_TEXT2") );
this.addInterval( new Interval(3000L, "SET_TEXT3") );
this.addInterval( new Interval(7500L, "SET_TEXT4") );
this.addInterval( new Interval(300L, "SET_TEXT5") );
this.begin();
}
}
Isn’t this much easier? And it will work, if I understood correctly, what you’re planning to do. (Ext)RenderLoop will help you in many situations. Just override the method loopIteration(long gameTime, long frameTime), if you want to do something each frame (don’t forget the super call). execute this.getGameTime(), if you want to know the current game-time and you’re not in a method like loopIteration() or onIntervalHit(), that gets it as a parameter.
Marvin
EDIT: Please doublecheck, if the order of the text isn’t wrong in you coding. In HUD3DTest the order of a Label’s lines is correct.
I forgot to say
totalTime and timeCounter are integer variables, this part of the code is already in a interval
timeCounter counts the second that it is and totalTime is the maximum time.
I don’t think that is the problem but something with “\n” cuz the line is going up, not down and i don’t know why its not cleaning the role sentence but only the first line when i call
tipLabel.setText(" ");
What do you mean by “counts the second that it is”? Is this the current game-time? So why don’t take it from ExtRenderLoop? Maybe you should consider spreading the code over more than one Interval. This would ease and safe the if selections.
I’ll check later, if a “cleared” Label will be corretly cleared, ok?
It’s a chronometer
the totalTime is a integer variable that keeps the second that it started like 60 (for 60 seconds)
the timeCounter is a variable that starts with the same value of totalTime and each time the intervals hit one second it’s decreased
public void onIntervalHit(Interval interval,long gameTime,long framTme)
{
if (interval.getName().equals("cronometro"))
{
if (timeCounter > 0){
if (timeCounter == totalTime){
tipLabel.setText(" ");
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText1() );
}
else if (timeCounter == (int) (0.8 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText2() );
}
else if (timeCounter == (int) (0.6 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText3() );
}
else if (timeCounter == (int) (0.4 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText4() );
}
else if (timeCounter == (int) (0.2 * totalTime) ){
tipLabel.setText( tipLabel.getText() + elementos[elCounter].getText5() );
}
timeCounter--;
cronometro.setText(String.format("%02d:%02d", (int) timeCounter / 60, timeCounter % 60));
}
else
interval.kill();
}
}
Wait a minute. I’ll try something…
There was a bug in Text2D. I fixed it. Please checkout xith-tk CVS.
I tried to reproduce your scenario. Please see the attachment. It works fine now.
Marvin
Marvin i’m getting an error when downloading xith3d cvs
cvs server: Updating xith3d
cvs server: Updating xith3d/classes
cvs server: Updating xith3d/demo
cvs server: Updating xith3d/demo/data
cvs server: Updating xith3d/docs
cvs server: Updating xith3d/junit
cvs server: Updating xith3d/junit/com
cvs server: Updating xith3d/junit/com/xith3d
cvs server: Updating xith3d/junit/com/xith3d/scenegraph
cvs server: Updating xith3d/junit/com/xith3d/sound
cvs server: Updating xith3d/junit/com/xith3d/sound/drivers
cvs server: Updating xith3d/junit/com/xith3d/sound/drivers/joal
cvs server: Updating xith3d/junit/com/xith3d/sound/drivers/joal/test
cvs server: Updating xith3d/junit/com/xith3d/sound/loaders
cvs server: Updating xith3d/junit/com/xith3d/sound/loaders/test
cvs server: Updating xith3d/junit/com/xith3d/spatial
cvs server: Updating xith3d/junit/com/xith3d/spatial/bounds
cvs server: Updating xith3d/junit/com/xith3d/spatial/clipping
cvs server: Updating xith3d/junit/com/xith3d/spatial/clipping/test
cvs server: Updating xith3d/junit/com/xith3d/terrain
cvs server: Updating xith3d/libs
cvs server: Updating xith3d/nbproject
cvs server: Updating xith3d/reference
cvs server: Updating xith3d/src
cvs server: Updating xith3d/src/com
cvs server: Updating xith3d/src/com/sun
cvs server: Updating xith3d/src/com/sun/j3d
cvs server: Updating xith3d/src/com/sun/j3d/utils
cvs server: Updating xith3d/src/com/sun/j3d/utils/geometry
cvs server: Updating xith3d/src/com/xith3d
cvs server: Updating xith3d/src/com/xith3d/collider
cvs server: Updating xith3d/src/com/xith3d/collider/forces
cvs server: Updating xith3d/src/com/xith3d/common
cvs server: Updating xith3d/src/com/xith3d/comparator
cvs server: Updating xith3d/src/com/xith3d/datatypes
cvs server: Updating xith3d/src/com/xith3d/gui
cvs server: Updating xith3d/src/com/xith3d/gui/images
cvs server: Updating xith3d/src/com/xith3d/image
cvs server: Updating xith3d/src/com/xith3d/imaging
cvs server: Updating xith3d/src/com/xith3d/io
cvs server: Updating xith3d/src/com/xith3d/loaders
cvs server: Updating xith3d/src/com/xith3d/loaders/ase
cvs server: Updating xith3d/src/com/xith3d/loaders/objectfile
cvs server: Updating xith3d/src/com/xith3d/loaders/scene
cvs server: Updating xith3d/src/com/xith3d/loaders/texture
cvs server: Updating xith3d/src/com/xith3d/occluder
cvs server: Updating xith3d/src/com/xith3d/picking
cvs server: Updating xith3d/src/com/xith3d/render
cvs server: Updating xith3d/src/com/xith3d/render/jogl
cvs server: Updating xith3d/src/com/xith3d/render/jsr231
Terminated with fatal signal 10
Core dumped; preserving /tmp/cvs-serv9350 on server.
CVS locks may need cleaning up.
U xith3d/src/com/xith3d/render/jsr231/RenderingShaderPeer.java
U xith3d/src/com/xith3d/render/jsr231/ShapeAtomPeer.java
Terminated with fatal signal 10
Core dumped; preserving /tmp/cvs-serv9350 on server.
CVS locks may need cleaning up.
Maybe you should simply try it again later. But note, that the changes I made are solely in xith-tk. Unfortunately I cannot test it now, since I have some big changes in xith3d core and so I cannot update the core.
when i try to compile xith-tk i’m getting those errors
C:\xith3d\CVS2\xith-tk\src\org\xith3d\loaders\bsp\BSPConverter.java:475: cannot find symbol
symbol : method setTextureUnitStates(com.xith3d.scenegraph.TextureUnitState[])
location: class com.xith3d.scenegraph.Appearance
a.setTextureUnitStates( new TextureUnitState[] {base, light} );
C:\xith3d\CVS2\xith-tk\src\org\xith3d\shaders\CelShadingFactory.java:398: cannot find symbol
symbol : method setTextureUnitStates(com.xith3d.scenegraph.TextureUnitState[])
location: class com.xith3d.scenegraph.Appearance
texturedAppearance.setTextureUnitStates(us);
C:\xith3d\CVS2\xith-tk\src\org\xith3d\util\input\EgoInputAdapter.java:353: cannot find symbol
symbol : method getEuler(javax.vecmath.Tuple3f)
location: class com.xith3d.scenegraph.Transform3D
view.getTransform().getEuler( viewEuler );
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\etc\SharedGroupTest.java:156: cannot find symbol
symbol : constructor Transform3D(float,int,int)
location: class com.xith3d.scenegraph.Transform3D
TransformGroup tg = new TransformGroup( new Transform3D(-1.0f, 0, -1) );
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\etc\SharedGroupTest.java:168: cannot find symbol
symbol : constructor Transform3D(float,int,int)
location: class com.xith3d.scenegraph.Transform3D
TransformGroup tg = new TransformGroup( new Transform3D(1.0f, 0, -1) );
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\loaders\BSPLoaderTest.java:189: cannot find symbol
symbol : method pickAll(int,int)
location: class com.xith3d.render.Canvas3D
List<PickResult> pickResults = ((Canvas3D)shotEngine).pickAll(400, 300);
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\loaders\BSPLoaderTest.java:200: cannot find symbol
symbol : method pickNearest(int,int)
location: class com.xith3d.render.Canvas3D
PickResult pickResult = ((Canvas3D)shotEngine).pickNearest(400, 300);
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\loaders\OBJTest.java:109: cannot find symbol
symbol : constructor PointLight(float,float,float,float,float,float,float)
location: class com.xith3d.scenegraph.PointLight
env.addChild(new PointLight(1f, .8f, .2f, 2f, 2f, 15f, .001f));
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\texture\BumpMappingTest.java:224: cannot find symbol
symbol : method setTextureUnitStates(com.xith3d.scenegraph.TextureUnitState[])
location: class com.xith3d.scenegraph.Appearance
ap.setTextureUnitStates(tu);
C:\xith3d\CVS2\xith-tk\src\org\xith3d\test\texture\MultitextureTest.java:334: cannot find symbol
symbol : method setTextureUnitStates(com.xith3d.scenegraph.TextureUnitState[])
location: class com.xith3d.scenegraph.Appearance
a.setTextureUnitStates( new TextureUnitState [] {tu0,tu1} );
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
10 errors
C:\xith3d\CVS2\xith-tk\build.xml:98: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 13 seconds)
Are you using an IDE (like Eclipse)? I’ve never faced such problems. I’ve just checked out the current CVS yesterday and it runs and compiles fine. This error must be due to local problems with you CVS client.
Marvin
I’m using netbeans 5
Even if it is a little time investment, please try it with Eclipse. It works fine with Ecplipse. Or maybe you could ask someone with some experiance with Netbeans. Sorry if I can’t help you. And sorry if the mistake is in xith’s area. But as I sayd, it runs fine for me with a fresh CVS checkout.
Marvin
@rafa_es : this problem (won’t compile error) is no surprise to me : you cannot update CVS completely and so some methods/classes are missing and the code won’t build… try again to update, if it doesn’t work, try to make a fresh checkout.
I have tried to download the cvs using TortoiseCVS and it worked fine, and the compilation of xith3d and xith-tk worked fine too
But now something weird is happening with egoInputAdapter, the game is loading fine but when i move the mouse, the scenegraph is disappearing, but only the scenegraph cuz the hud still apears
The view is updated using scheduledOperation
private class updateView implements ScheduledOperation
{
private boolean isAlive = true;
public boolean isAlive()
{
return(isAlive);
}
public boolean isPersistent()
{
return(true);
}
public void setAlive(boolean alive)
{
this.isAlive = alive;
}
public void executeOperation(long gameTime, long frameTime)
{
// Atualiza a movimentação da camera
egoAdapter.updateView(gameTime, frameTime);
}
}
And it’s started as follows
egoAdapter = new EgoInputAdapter(env.getView(), canvas, 1.0f, 1.0f, 5.0f);
egoAdapter.createDefaultKeyBindings( true );
this.registerInputListener( egoAdapter );
....
this.scheduleOperation(new updateView());
PS: the ego works fine with my previous version of xith, so i don’t that there’s something wrong with the code
It is simpler to update the view in the overridden loopIteration() method or updateInputDevices() from RenderLoop.
In BSPLoaderTest and Q§FlightBenchmark the EgoInputAdapter works wine. Please look if you used it the same way.
Marvin
The BSPLoaderTest is working fine here, but in my code it’s bugging when i move the mouse, anyway i’m adding my code if you want to take a look
I’ll be trying to find what could be the problem
By the way, the label is working fine now, thanks
I had a look at your source. But I can’t see the problem, if I cannot compile it. Please provide me a downstriped version, which is executable without any further data.
Some tips anyway:
don’t do
hud.addWidget(cronometro, env.getCanvas().getWidth()/2, 15);
but better
hud.addWidget( cronometro, hud.getResolution().x / 2f, 15f );
or you’ll maybe have misplaced Widgets.
Please try to use english comments in your code. It is better for situations like this one. I cannot understand any of your comments.
Marvin