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

2013/2/11

a soother setLocation()

tylers tylers

2013/2/11

#
i have this code and i would like the object to slow down smoothly in the invisible box (coded box) but the object slows down to quickly, so how could i make it slow down smoothly:?
if(obj==objective.right)

        {   
            if((getX()>=(title.getWidth()/2)-60)&&(getX()<=(title.getWidth()/2)+30)){
                if((speed>1)){
                    speed=speed-1;
                    //System.out.print(speed);

                }
            }else{
                if(ti1==1){
                    speed= speed +1;
                    ti1=0;
                }else{
                    ti1++;
                }

            }     

        }else
        {
            //System.out.print("error: "+obj);
        }       
        mov= mov+speed;
        if(obj==objective.right){
            setLocation(0+mov,title.getHeight()/2);
        }else if(obj==objective.left){
            setLocation(title.getWidth()-mov,title.getHeight()/2);            
        }else
        {
            System.out.print("error: "+obj);
        }
Gevater_Tod4711 Gevater_Tod4711

2013/2/11

#
You could use double value for speed to make it more smooth. You just have to cast it to an integer if you want to use it in the setLocation method.
You need to login to post a reply.