EDIT: OK looks like calling super.animate() is causing the issue (but it is
what is given as example in the
documentation: https://www.codenameone.com/manual/animations.html) . If I
remove the super.animate() and only return true or false, it works...
On Wednesday, May 2, 2018 at 6:13:37 AM UTC+2, Thomas wrote:
>
> I am trying to create a custom component that animates. But it looks like
> the animate() method of my component is only called once (instead of beeing
> called at each EDT cycle) and I don't understand why.
>
> Here are the relevant methods of my custom component:
>
> ```
> /**
> * {@inheritDoc}
> */
> public void initComponent() {
> if(infinite) {
> System.out.println("Animate");
> getComponentForm().registerAnimatedInternal(this);
> }
> }
>
> /**
> * {@inheritDoc}
> */
> public void deinitialize() {
> if(infinite) {
> Form f = getComponentForm();
> if(f != null) {
> System.out.println("UnAnimate");
> f.deregisterAnimatedInternal(this);
> }
> }
> }
>
> /**
> * {@inheritDoc}
> */
> public boolean animate() {
> System.out.println("Anim called");
> if(infinite) {
> float f = (infiniteSpeed * (reverseDirection?(-1):(1)) *
> ((float)maxValue));
> if(((int)f) == 0) {
> if(f < 0) {
> f = -1;
> } else {
> f = 1;
> }
> }
> value += ((int)f);
> if(value >= maxValue) {
> if (reverseAtEnd) {
> value = maxValue;
> reverseDirection = true;
> }
> else {
> value = (int)0;
> }
> }
> if(value <= 0) {
> if (reverseAtEnd) {
> value = (int)0;
> reverseDirection = false;
> }
> else {
> value = maxValue;
> }
> }
> System.out.println("New value: "+value);
> super.animate();
> return true;
> }
> return super.animate();
> }
>
>
> public void setInfinite(boolean i) {
> if(infinite != i) {
> infinite = i;
> if(isInitialized()) {
> if(i) {
> System.out.println("Animate");
> getComponentForm().registerAnimatedInternal(this);
> } else {
> System.out.println("UnAnimate");
> getComponentForm().deregisterAnimatedInternal(this);
> }
> }
> else {
> System.out.println("Not initialized");
> }
> }
> }
>
> ```
>
> and the output I have in my console with the simulator:
>
> ```
> Animate
> paintComponentBackground finished
> Anim called
> New value: 3
> paintComponentBackground finished
> ```
>
> As you can see the animate() function is called (so my component seems
> correctly registered as animated at the parent level). But after that,
> nothing. The animate() function is not called anymore and my value variable
> do not change....
> I looked at the animated ClockDemo and it looks like pretty similar so I
> don't understand what is wrong with my code...
>
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/2fc31616-599a-44fd-a068-f2e43c0d611f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.