2017-04-14 37 views
0

我嘗試在一個JFrame移動標籤從一個地方通過擺動使用 定時器的動畫的地方,我總是得到該定時器發送 例如動畫的上一個:我該怎麼辦幾動畫1後1

一個cetrian標籤具有可變的「地方」持有標籤的地方每一刻 地方是一個變量,0 <地方< 101和它的第一個值是1 我也有一個枚舉列表顯示了所有100點x和y 所以如果例如那個標籤的地方是52 那麼:

label.setposition(pointslist.place.getx(),pointslist.place.gety()); 
這樣

它設置上進行標籤的位置52

public void move_player1{ 

    timer = new Timer(20, new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent e){ 
      //Move 1 px everytime 
      if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x+1, player1.getLocation().y); 
      if(player1.getLocation().x==pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x, player1.getLocation().y-1); 
      if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x-1, player1.getLocation().y); 
      if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x-1, player1.getLocation().y-1); 
      if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y<pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x+1, player1.getLocation().y+1); 
      if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x-1, player1.getLocation().y-1); 
      if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y<pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x-1, player1.getLocation().y+1); 
      if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
      player1.setLocation(player1.getLocation().x+1, player1.getLocation().y-1); 
      if(player1.getLocation().x==pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()){ 
       timer.stop(); 
      } 
     }    
    }); 
    timer.start(); 
} 

現在可以說,在其他功能我得到一個隨機數x ,使標籤穿過所有的點一個接一個x次這樣的:

int x=*random* (for example 6); 
for(int i=0;i<x;i++) 
      { 
       place++; 
       move_player1(); 
      } 

如果玩家站在點52我想在GUI 看到玩家通過點移動點,直到它到達58 但它不工作 我在gui中看到球員直接從第52點移動到第58點,當我希望它只能移動第1點時 我該如何解決?如何在第一次結束之前停止第二個定時器的運行?

--------編輯: 這裏是一個可運行的例子

主機:

import java.awt.BorderLayout; 
import java.awt.Dimension; 
import java.awt.Font; 
import java.awt.Rectangle; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.ImageIcon; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.Timer; 

public class mainframe extends JFrame{ 


    private JPanel gamepanel; 
    private JPanel DicePanel; 
    private Die Dice; 

    private final int WIDTH=850; 
    private final int HEIGHT=610; 
    private final String BACKGROUNDPATH=".\\images\\lns.png"; 

    public JButton button; 
    public int place; 
    JLabel player1; 
    Timer timer; 

    public mainframe(){ 


     this.setSize(WIDTH,HEIGHT);  
     this.setVisible(true); 
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     this.setResizable(false); 

     gamepanel=new JPanel(); 
     gamepanel.setBounds(new Rectangle(570,HEIGHT)); 
     gamepanel.setLayout(new BorderLayout()); 

     JLabel backgroundimg=new JLabel(new ImageIcon(BACKGROUNDPATH)); 
     gamepanel.add(backgroundimg); 

     player1=new JLabel(new ImageIcon(".\\images\\player1.png"));  
     player1.setBounds(pointslist.POINT1.getx(),pointslist.POINT1.gety(),59,29); 
     backgroundimg.add(player1); 
     place=1;  


     DicePanel=new JPanel(); 
     DicePanel.setLayout(new BorderLayout()); 
     DicePanel.setPreferredSize(new Dimension(WIDTH-gamepanel.getWidth()-15,HEIGHT)); 
     Dice=new Die(); 






     //Button 
     button = new JButton("ROLL THE DICE !"); 
     button.setFont(new Font("Arial",Font.BOLD,20)); 
     button.setPreferredSize(new Dimension(200,100)); 
     DicePanel.add(button,BorderLayout.SOUTH); 
     this.setLayout(new BorderLayout()); 
     this.add(gamepanel,BorderLayout.CENTER); 
     this.add(DicePanel,BorderLayout.LINE_END); 


     button.addActionListener(new ActionListener(){ 

      @Override 
      public void actionPerformed(ActionEvent e) { 
       // TODO Auto-generated method stub 
       Dice.roll(); 
       int dienum=Dice.getFaceValue(); 
       System.out.println(dienum); 
       for(int i=0;i<dienum;i++) 
       { 
        place++; 
        move_player1(); 
       } 
    } 

    public void move_player1() 
    { 

      timer = new Timer(50, new ActionListener(){ 
       @Override 
       public void actionPerformed(ActionEvent e){ 
        //Move 1 px everytime 

        if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x+1, player1.getLocation().y); 
        if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x-1, player1.getLocation().y); 
        if(player1.getLocation().x==pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x, player1.getLocation().y-1); 
        if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x-1, player1.getLocation().y-1); 
        if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y<pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x+1, player1.getLocation().y+1); 
        if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x-1, player1.getLocation().y-1); 
        if(player1.getLocation().x>pointslist.values()[place].getx()&&player1.getLocation().y<pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x-1, player1.getLocation().y+1); 
        if(player1.getLocation().x<pointslist.values()[place].getx()&&player1.getLocation().y>pointslist.values()[place].gety()) 
         player1.setLocation(player1.getLocation().x+1, player1.getLocation().y-1); 



        if(player1.getLocation().x==pointslist.values()[place].getx()&&player1.getLocation().y==pointslist.values()[place].gety()) 
         { 
         timer.stop(); 
         } 

        } 



      }); 
      timer.start(); 
    } 
}); 
} 

    public static void main(String[] args) { 

      mainframe frame = new mainframe(); 
      frame.setVisible(true); 
    } 
    } 

骰子類:

class Die{ 

// Note: If we changed the class definition to "public class Die" 
// then we would put this class definition in a separate file Die.java 

// Represents one die (singular of dice) with faces showing values 
// between 1 and 6. 

    private final int MAX = 6; // maximum face value 

    private int faceValue; // current value showing on the die 

    //----------------------------------------------------------------- 
    // Constructor: Sets the initial face value. 
    //----------------------------------------------------------------- 
    public Die() 
    { 
     faceValue = 1; 
    } 

    // Alternate Constructor 

    public Die(int value) 
    { 
     faceValue = value; 
    } 

    //----------------------------------------------------------------- 
    // Rolls the die and returns the result. 
    //----------------------------------------------------------------- 
    public int roll() 
    { 
     faceValue = (int)(Math.random() * MAX) + 1; 

     return faceValue; 
    } 

    //----------------------------------------------------------------- 
    // Face value mutator. 
    //----------------------------------------------------------------- 
    public void setFaceValue (int value) 
    { 
     faceValue = value; 
    } 

    //----------------------------------------------------------------- 
    // Face value accessor. 
    //----------------------------------------------------------------- 
    public int getFaceValue() 
    { 
     return faceValue; 
    } 

// Returns a string representation of this die. 
     public String toString() 
     { 
      String result = Integer.toString(faceValue); 
      return result; 
     } 

} 

和所有的枚舉職位:

public enum pointslist { 


NOPOINT(-10,-10), 
POINT1(15,500), 
POINT2(70,500), 
POINT3(125,500), 
POINT4(180,500), 
POINT5(230,500), 
POINT6(285,500), 
POINT7(338,500), 
POINT8(390,500), 
POINT9(445,500), 
POINT10(500,500), 

POINT11(500,450), 
POINT12(445,450), 
POINT13(390,450), 
POINT14(338,450), 
POINT15(285,450), 
POINT16(230,450), 
POINT17(180,450), 
POINT18(125,450), 
POINT19(70,450), 
POINT20(15,450), 

POINT21(15,395), 
POINT22(70,395), 
POINT23(125,395), 
POINT24(180,395), 
POINT25(230,395), 
POINT26(285,395), 
POINT27(338,395), 
POINT28(390,395), 
POINT29(445,395), 
POINT30(500,395), 

POINT31(500,342), 
POINT32(445,342), 
POINT33(390,342), 
POINT34(338,342), 
POINT35(285,342), 
POINT36(230,342), 
POINT37(180,342), 
POINT38(125,342), 
POINT39(70,342), 
POINT40(15,342), 

POINT41(15,290), 
POINT42(70,290), 
POINT43(125,290), 
POINT44(180,290), 
POINT45(230,290), 
POINT46(285,290), 
POINT47(338,290), 
POINT48(390,290), 
POINT49(445,290), 
POINT50(500,290), 

POINT51(500,235), 
POINT52(445,235), 
POINT53(390,235), 
POINT54(338,235), 
POINT55(285,235), 
POINT56(230,235), 
POINT57(180,235), 
POINT58(125,235), 
POINT59(70,235), 
POINT60(15,235), 

POINT61(15,180), 
POINT62(70,180), 
POINT63(125,180), 
POINT64(180,180), 
POINT65(230,180), 
POINT66(285,180), 
POINT67(338,180), 
POINT68(390,180), 
POINT69(445,180), 
POINT70(500,180), 

POINT71(500,130), 
POINT72(445,130), 
POINT73(390,130), 
POINT74(338,130), 
POINT75(285,130), 
POINT76(230,130), 
POINT77(180,130), 
POINT78(125,130), 
POINT79(70,130), 
POINT80(15,130), 

POINT81(15,75), 
POINT82(70,75), 
POINT83(125,75), 
POINT84(180,75), 
POINT85(230,75), 
POINT86(285,75), 
POINT87(338,75), 
POINT88(390,75), 
POINT89(445,75), 
POINT90(500,75), 

POINT91(500,20), 
POINT92(445,20), 
POINT93(390,20), 
POINT94(338,20), 
POINT95(285,20), 
POINT96(230,20), 
POINT97(180,20), 
POINT98(125,20), 
POINT99(70,20), 
POINT100(15,20); 



private final int x; 
private final int y; 

pointslist(int x,int y) 
{ 
    this.x=x; 
    this.y=y; 
} 
public int getx(){return x;}; 
public int gety(){return y;}; 

} 

the game board : lns.png

the player icon : player1.png

請注意,例如,如果玩家需要從廣場8移動 到廣場14所花費的一小段路 ,而不是通過所有9 10 11 12 13 去我不想它,我希望它一路做出一個certian方

+1

一個'定時器'充當一個僞循環,所以每次它滴答時,都是這個循環的一個迭代,所以你的'for-loop'不是去幫助你 – MadProgrammer

+2

這個概念相對簡單(沒有攻勢),並且有幾十個如果沒有幾百個例子顯示基本原理。你有一個起點,你有一個終點,你有一個矢量(速度),你只需要通過矢量量更新位置,直到它達到或超過目標點 – MadProgrammer

+0

我沒有矢量速度並且我看不到速度矢量如何幫助我我不想改變標籤的速度只有它移動的方式我在問題的一半問題中出現了問題半隱藏請再次閱讀請 –

回答

0

開始通過從for-loopmove_player1()通話...

@Override 
public void actionPerformed(ActionEvent e) { 
    // TODO Auto-generated method stub 
    Dice.roll(); 
    int dienum = Dice.getFaceValue(); 
    System.out.println(dienum); 
    for (int i = 0; i < dienum; i++) { 
     place++; 
    } 
    move_player1(); 
} 

這是創建n次數只會混淆你將來再次做的任何事情。

接下來,在TimerActionListener添加調用repaint引發新的油漆週期

timer = new Timer(50, new ActionListener() { 
    @Override 
    public void actionPerformed(ActionEvent e) { 
     //... 
     player1.getParent().repaint(); 
    } 

}); 

它不解決我的問題,我說,這名球員穿過線時的事實它並不需要注意,當標籤需要到達上方的一個方格時,它不會採取「漫長的路」,它只是跳到那裏,我想要的是玩家要廣場去廣場,直到它到達目的地。

你得到了我想要做的事情嗎?我只是不想讓玩家直接走到某一點,我希望它能通過之前的所有方塊。例如,如果您可以從骰子中獲得數字99,則該地點將在第一次嘗試100上,然後標籤動畫將直接從1到100(通過1,20,21,40,41,60,61,80 ,81100),我不希望它是這樣的,我想它之前

所以在所有的99個廣場經過,基本上你真正想要的是某種時間線/關鍵幀動畫

請參閱:

支付額外的概念,你也可以看看Can't move JLabel on JPanel

香港專業教育學院看着他們都和我沒有看到它如何能幫助我,我不這樣做螺旋形或方形運動我的運動更接近蛇的運動我也沒有問題,從屏幕上的標籤蒼蠅我只是試圖瞭解它是如何工作的,我沒有得到時間線類的作用

好的,你還有一個時間表。每個點都是關鍵幀。基本上,你想從棋盤上的一個索引點移動到另一個索引點,每個索引點都有一個關聯點。

所以,我有一個簡單的Mover類,它需要一個from索引和一個to索引。然後我有一個模型,給出一個index點將返回相關的Point。這意味着我的Mover類只需增加索引點(直到達到目標點),它向觀察者報告位置已更新,然後更新屏幕上播放器的位置......

import java.awt.Dimension; 
import java.awt.EventQueue; 
import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.awt.Point; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.MouseAdapter; 
import java.awt.event.MouseEvent; 
import java.awt.image.BufferedImage; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
import javax.imageio.ImageIO; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.Timer; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

public class Test1 { 

    public static void main(String[] args) { 
     new Test1(); 
    } 

    public Test1() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        try { 
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
         ex.printStackTrace(); 
        } 

        JFrame frame = new JFrame("Testing"); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        frame.add(new TestPane()); 
        frame.pack(); 
        frame.setLocationRelativeTo(null); 
        frame.setVisible(true); 
       } catch (IOException ex) { 
        ex.printStackTrace(); 
       } 
      } 
     }); 
    } 

    public interface Positioner { 

     public void movePlayerTo(int to); 

     public void playerStoppedAt(int at); 
    } 

    public class TestPane extends JPanel implements Positioner { 

     private BufferedImage background; 
     private Player player; 
     private PointList pointList = new PointList(); 

     private int currentPoint = 0; 

     public TestPane() throws IOException { 
      background = ImageIO.read(getClass().getResource("/Board.png")); 
      setLayout(null); 
      player = new Player(); 
      add(player); 

      movePlayerTo(currentPoint); 
      addMouseListener(new MouseAdapter() { 
       @Override 
       public void mouseClicked(MouseEvent e) { 
        int roll = (int) ((Math.random() * 6) + 1); 
        System.out.println(currentPoint + " + " + roll); 
        Mover mover = new Mover(currentPoint, currentPoint + roll, TestPane.this); 
        mover.start(); 
       } 
      }); 
     } 

     @Override 
     public void playerStoppedAt(int at) { 
      // Does the player need to move directly to a new 
      // location, ie slide down or climb up 
      Integer next = pointList.nextPoint(at); 
      if (next != null) { 
       // Move direclty to next position 
      } 
     } 

     @Override 
     public void movePlayerTo(int to) { 
      currentPoint = to; 
      player.setLocation(pointList.pointAt(currentPoint)); 
      repaint(); 
     } 

     @Override 
     public Dimension getPreferredSize() { 
      return background == null ? new Dimension(200, 200) : new Dimension(background.getWidth(), background.getHeight()); 
     } 

     @Override 
     protected void paintComponent(Graphics g) { 
      super.paintComponent(g); 
      if (background != null) { 
       Graphics2D g2d = (Graphics2D) g.create(); 
       g2d.drawImage(background, 0, 0, this); 
       g2d.dispose(); 
      } 
     } 

    } 

    public class Mover { 

     private int point; 
     private int from; 
     private int to; 
     private Positioner positioner; 
     private Timer timer; 

     public Mover(int from, int to, Positioner positioner) { 
      this.from = from; 
      this.to = to; 
      this.positioner = positioner; 
     } 

     public void start() { 
      point = from; 
      timer = new Timer(500, new ActionListener() { 
       @Override 
       public void actionPerformed(ActionEvent e) { 
        point++; 
        if (point >= to) { 
         point = to; 
         timer.stop(); 
         positioner.playerStoppedAt(point); 
        } else { 
         positioner.movePlayerTo(point); 
        } 
       } 
      }); 
      timer.start(); 
     } 

    } 

    public class Player extends JPanel { 

     private BufferedImage background; 

     public Player() throws IOException { 
      setOpaque(false); 
      background = ImageIO.read(getClass().getResource("/Player.png")); 
      setSize(getPreferredSize()); 
     } 

     @Override 
     public Dimension getPreferredSize() { 
      return background == null ? new Dimension(200, 200) : new Dimension(background.getWidth(), background.getHeight()); 
     } 

     @Override 
     protected void paintComponent(Graphics g) { 
      super.paintComponent(g); 
      if (background != null) { 
       Graphics2D g2d = (Graphics2D) g.create(); 
       g2d.drawImage(background, 0, 0, this); 
       g2d.dispose(); 
      } 
     } 

    } 

    public class PointList { 

     private List<Point> points = new ArrayList<>(100); 
     private Map<Integer, Integer> nextPoint = new HashMap<>(); 

     public PointList() { 
      points.add(new Point(15, 500)); 
      points.add(new Point(70, 500)); 
      points.add(new Point(125, 500)); 
      points.add(new Point(180, 500)); 
      points.add(new Point(230, 500)); 
      points.add(new Point(285, 500)); 
      points.add(new Point(338, 500)); 
      points.add(new Point(390, 500)); 
      points.add(new Point(445, 500)); 
      points.add(new Point(500, 500)); 
      points.add(new Point(500, 450)); 
      points.add(new Point(445, 450)); 
      points.add(new Point(390, 450)); 
      points.add(new Point(338, 450)); 
      points.add(new Point(285, 450)); 
      points.add(new Point(230, 450)); 
      points.add(new Point(180, 450)); 
      points.add(new Point(125, 450)); 
      points.add(new Point(70, 450)); 
      points.add(new Point(15, 450)); 
      points.add(new Point(15, 395)); 
      points.add(new Point(70, 395)); 
      points.add(new Point(125, 395)); 
      points.add(new Point(180, 395)); 
      points.add(new Point(230, 395)); 
      points.add(new Point(285, 395)); 
      points.add(new Point(338, 395)); 
      points.add(new Point(390, 395)); 
      points.add(new Point(445, 395)); 
      points.add(new Point(500, 395)); 
      points.add(new Point(500, 342)); 
      points.add(new Point(445, 342)); 
      points.add(new Point(390, 342)); 
      points.add(new Point(338, 342)); 
      points.add(new Point(285, 342)); 
      points.add(new Point(230, 342)); 
      points.add(new Point(180, 342)); 
      points.add(new Point(125, 342)); 
      points.add(new Point(70, 342)); 
      points.add(new Point(15, 342)); 
      points.add(new Point(15, 290)); 
      points.add(new Point(70, 290)); 
      points.add(new Point(125, 290)); 
      points.add(new Point(180, 290)); 
      points.add(new Point(230, 290)); 
      points.add(new Point(285, 290)); 
      points.add(new Point(338, 290)); 
      points.add(new Point(390, 290)); 
      points.add(new Point(445, 290)); 
      points.add(new Point(500, 290)); 
      points.add(new Point(500, 235)); 
      points.add(new Point(445, 235)); 
      points.add(new Point(390, 235)); 
      points.add(new Point(338, 235)); 
      points.add(new Point(285, 235)); 
      points.add(new Point(230, 235)); 
      points.add(new Point(180, 235)); 
      points.add(new Point(125, 235)); 
      points.add(new Point(70, 235)); 
      points.add(new Point(15, 235)); 
      points.add(new Point(15, 180)); 
      points.add(new Point(70, 180)); 
      points.add(new Point(125, 180)); 
      points.add(new Point(180, 180)); 
      points.add(new Point(230, 180)); 
      points.add(new Point(285, 180)); 
      points.add(new Point(338, 180)); 
      points.add(new Point(390, 180)); 
      points.add(new Point(445, 180)); 
      points.add(new Point(500, 180)); 
      points.add(new Point(500, 130)); 
      points.add(new Point(445, 130)); 
      points.add(new Point(390, 130)); 
      points.add(new Point(338, 130)); 
      points.add(new Point(285, 130)); 
      points.add(new Point(230, 130)); 
      points.add(new Point(180, 130)); 
      points.add(new Point(125, 130)); 
      points.add(new Point(70, 130)); 
      points.add(new Point(15, 130)); 
      points.add(new Point(15, 75)); 
      points.add(new Point(70, 75)); 
      points.add(new Point(125, 75)); 
      points.add(new Point(180, 75)); 
      points.add(new Point(230, 75)); 
      points.add(new Point(285, 75)); 
      points.add(new Point(338, 75)); 
      points.add(new Point(390, 75)); 
      points.add(new Point(445, 75)); 
      points.add(new Point(500, 75)); 
      points.add(new Point(500, 20)); 
      points.add(new Point(445, 20)); 
      points.add(new Point(390, 20)); 
      points.add(new Point(338, 20)); 
      points.add(new Point(285, 20)); 
      points.add(new Point(230, 20)); 
      points.add(new Point(180, 20)); 
      points.add(new Point(125, 20)); 
      points.add(new Point(70, 20)); 
      points.add(new Point(15, 20)); 

      nextPoint.put(38, 4); 
      nextPoint.put(33, 10); 
      nextPoint.put(16, 36); 
      nextPoint.put(40, 80); 
      nextPoint.put(46, 74); 
      nextPoint.put(31, 69); 
      nextPoint.put(56, 24); 
      nextPoint.put(65, 96); 
      nextPoint.put(99, 77); 
      nextPoint.put(91, 68); 
     } 

     public Point pointAt(int index) { 
      index = Math.abs(index % points.size()); 
      return points.get(index); 
     } 

     public Integer nextPoint(int index) { 
      return nextPoint.get(index); 
     } 

    } 
} 

現在,我確實設置了一個檢查,以確定玩家是否應該從新位置向上/向下移動,但我沒有設置移動代碼,這將從開始時移動對象PointPoint結束,而不是通過索引點移動;)

+0

的幫助,它不能解決我的問題正如我所說的那樣,當玩家不需要注意,當標籤需要到達上方的一個方格時,玩家會穿過線條,這並不需要跳過「漫長的路線」到那裏,我想要的是玩家去廣場,直到它到達目的地 –

+0

你得到了我想做的事情?我只是不想讓玩家直接走到某一點,我希望它能通過之前的所有方塊。例如,如果您可以從骰子中獲得數字99,則該地點將是第一次嘗試100,然後標籤動畫將直接從1到100(通過1,20,21,40,41,60,61,80 ,81,100),我不希望它是像我希望它通過所有99個方塊之前 –

+0

ive看着他們所有,我沒有看到它如何可以幫助我我不做螺旋或方形運動我的運動更多接近蛇的運動我也沒有問題,從屏幕上飛出來的標籤我只是試圖瞭解它是如何工作的,我沒有得到時間線班級所需的角色 –