Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMr Purple

Posted 26 December 2012 - 10:34 AM

Okay, so I have a method called moveToY() what it does is move an object to a Y point, so if your at (0, 200) and you do

 

moveToY(myObject, 0, 5, myAction); // Object, Y, Speed, AbstracAction

 

The object will move to point 0. in my library what I currently have is this:

 

    public void moveToY(GameObject obj, int y, int amount, AbstractAction complete){
        this.obj = obj;
        this.endY = y;
        this.moveAmount = amount;
        this.complete = complete;
        thread = new Thread(this);
        thread.start();
    }

    public void run(){
        try{
            boolean run = true;
            while(run){
                int objY = obj.getY();
                if(objY > this.endY){
                    obj.setY(obj.getY() - 1);
                }else if(objY < this.endY){
                    obj.setY(obj.getY() + 1);
                }else{
                    run = false;
                    this.actionComplete();
                }
                thread.sleep(moveAmount);
            }
        }catch(Exception e){
        }
    }

 

I have been told doing that is a bad idea, but I am not really sure how to take that and move it into my main game's thread.


#2Mr Purple

Posted 26 December 2012 - 10:34 AM

Okay, so I have a method called moveToY() what it does is move an object to a Y point, so if your at (0, 200) and you do

 

moveToY(myObject, 0, 5, myAction); // Object, Y, Speed

 

The object will move to point 0. in my library what I currently have is this:

 

    public void moveToY(GameObject obj, int y, int amount, AbstractAction complete){
        this.obj = obj;
        this.endY = y;
        this.moveAmount = amount;
        this.complete = complete;
        thread = new Thread(this);
        thread.start();
    }

    public void run(){
        try{
            boolean run = true;
            while(run){
                int objY = obj.getY();
                if(objY > this.endY){
                    obj.setY(obj.getY() - 1);
                }else if(objY < this.endY){
                    obj.setY(obj.getY() + 1);
                }else{
                    run = false;
                    this.actionComplete();
                }
                thread.sleep(moveAmount);
            }
        }catch(Exception e){
        }
    }

 

I have been told doing that is a bad idea, but I am not really sure how to take that and move it into my main game's thread.


#1Mr Purple

Posted 26 December 2012 - 10:33 AM

Okay, so I have a method called moveToY() what it does is move an object to a Y point, so if your at (0, 200) and you do

 

moveToY(myObject, 0, 5); // Object, Y, Speed

 

The object will move to point 0. in my library what I currently have is this:

 

    public void moveToY(GameObject obj, int y, int amount, AbstractAction complete){
        this.obj = obj;
        this.endY = y;
        this.moveAmount = amount;
        this.complete = complete;
        thread = new Thread(this);
        thread.start();
    }

    public void run(){
        try{
            boolean run = true;
            while(run){
                int objY = obj.getY();
                if(objY > this.endY){
                    obj.setY(obj.getY() - 1);
                }else if(objY < this.endY){
                    obj.setY(obj.getY() + 1);
                }else{
                    run = false;
                    this.actionComplete();
                }
                thread.sleep(moveAmount);
            }
        }catch(Exception e){
        }
    }

 

I have been told doing that is a bad idea, but I am not really sure how to take that and move it into my main game's thread.


PARTNERS