This site requires JavaScript, please enable it in your browser!
Greenfoot back
Paul12345
Paul12345 wrote ...

2020/12/14

How to achieve slow transitions ?

Paul12345 Paul12345

2020/12/14

#
I'm trying to move an object slowly through the world. I tried to achieve this by having a counter and only moving the object 1 pixel when the counter hits a specific value (then reseting the counter and so on), for some reason it doesn't work at all, no matter how high I set the counter limit. If I also print the counter value in console, then the method works as intended (slowing down), but if not the method works like nothing is slowing it down. Greenfoot delay seems like an alternative, but that halts the entire program whereas I only want to slow that that specific method.
danpost danpost

2020/12/14

#
Please provide entire class with attempt. No one can fix your codes without first seeing it.
Paul12345 Paul12345

2020/12/14

#
danpost wrote...
Please provide entire class with attempt. No one can fix your codes without first seeing it.
This is my class.
public class NodePointer extends Actor
{
    /**
     * Act - do whatever the NodePointer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void setLocationTransition(int x,int y,int t)
    {
        long i=0;
        while(i<10000000)
        {
            i++;
           // System.out.println(i);
        }
    }
}
I call the setLocationTransition method from another one. In this format, my program runs as if the while doesn't exist. It's only when I uncomment the print that it actually slows down the execution.
danpost danpost

2020/12/14

#
Looks like you are trying to hog the CPU to slow down the execution. Well, if successful, you would only achieve what using delay would do -- slow everything down. Remove the method and post class that called it.
You need to login to post a reply.