probably a very basic question, hope somebody can give me the panda-quick solution.
I am using Panda with c++, and 'm not considering to change to python.
I have drawn a button on the screen, and I can get the input once it is pressed.
Once pressed I need it to move the button on the screen, ex: once pressed I need the button to move some pixels to the left…
Any hints? I’ve looked into “Roaming Ralph example by Ryan Myers” a very helpful example by the way, thou I cannot get it working with my Panda version, it says:
:util:bam(error): Bam file is version 6.12.
:util:bam(error): This program can only load version 6.14 through 6.19 bams.
As far as i understand, in this example the character is moved on a separate thread, by invoking the Move(time) method of the World class. Is this the only way movement can be done, even for a simple button?! I mean, I know this is the way a game engine should work, but in the button’s case I hope to have something like button.move(x,y,t), thus the button would move from the current position to (x,y) in time “t”. This is also present in some game engines i’ve seen.
Please clear me out what is the Panda way to do it, and what classes or examples should i consider.
Thank you so much.
It sounds like you want an interval. Something like:
PT(CLerpNodePathInterval) ival = new CLerpInterval("move", t, CLerpInterval::BT_no_blend, false, false, button, NodePath());
ival->set_end_pos(x, 0, y);
thank you for the tip, this seems to be what i need.
I did as below:
PT(CLerpNodePathInterval) ival = new CLerpNodePathInterval(“move”, 1000, CLerpInterval::BT_no_blend, false, false, myNodePath, NodePath());
ival>set_end_pos( LVecBase3f(fColumn, 0, fRow));
My intention was to do a 1000 ms (1sec) movement, from the current position to the (fColumn, fRow) position.
The code works in terms of moving the object, but I would like to see the animation itself. So the code above is like in terms of animation the equivalent of:
myNodePath.set_pos(fColumn, 0.0, fRow);
I’ve also tried inserting in the main the following:
Thread *current_thread = Thread::get_current_thread();
move(clock->get_real_time()); // Call the move function of the world
while in move(double time), i do:
ival->priv_step( time-prevtime );
and still the same result: no animation.
Where do i go wrong?
The time is in seconds, not milliseconds, so “1000” means 1000 seconds.
Also, you shouldn’t call any of the priv_*() methods directly. They are intended to be private, hence the names. (They can’t actually be private because they have to be callable to Python as well.)
this is the first thing i’ve tried:
ival = new CLerpNodePathInterval(buf, 2, CLerpInterval::BT_no_blend, false, false, myNodePath, NodePath());
ival->set_end_pos( LVecBase3f(fColumn, 0, fRow));
Thus it should move the button from the current pos to (fColumn, fRow) in 2 seconds, if i understood correctly.
It doesn’t do any animation at all, so i presume the update animation function is not called. Is window->loop_animations() the one responsible for calling these animations?
In this case, shouldn’t i link the animation to the window somehow?
No, loop_animations won’t work for intervals. You should add this in a task (or in your main loop):
Note that this page (hit the C++ button at the top) also explains how to do intervals in C++:
panda3d.org/manual/index.php/U … _the_Panda
Hey rdb and David
thank you for helping with this one.
As rdb was saying, I was not updating in the main loop.
Now it is just fine.