遊戲移動圖片的轉換

來源:互聯網
上載者:User

標籤:splay   rect   int   ext   void   extend   ase   direction   變化   

移動圖片的轉換:

          定義一個方向,在移動的時候判斷下一次移動是否為當前方向,如果不是則只改變圖片,不做移動。

 

 1 package com.itheima.bean; 2  3 public class Tank extends Element { 4     private int speed = 64; 5     Direction direction = Direction.UP;    //初始向上 6  7     public Tank(int x, int y) { 8         this.x = x; 9         this.y = y;10         this.imagePath = "res/img/tank_u.gif";11 12     }13 14     public void move(Direction dir) {15         if (direction != dir) { //如果傳進來的方向不等於當前方向16             direction = dir;    17             switch (dir) {    //根據方向轉換圖片18             case UP:19                 this.imagePath = "res/img/tank_u.gif";20                 break;21 22             case DOWN:23                 this.imagePath = "res/img/tank_d.gif";24                 break;25             case LEFT:26                 this.imagePath = "res/img/tank_l.gif";27                 break;28             case RIGHT:29                 this.imagePath = "res/img/tank_r.gif";30                 break;31             }32             return ;    //不繼續向下執行33         }34         switch (dir) {    //移動35         case UP:36             y -= speed;37             break;38 39         case DOWN:40             y += speed;41             break;42         case LEFT:43             x -= speed;44             break;45         case RIGHT:46             x += speed;47             break;48         }49     }50 }
View Code

 

 

隨筆說:

      遊戲移動原理就是圖片的座標的變化顯示。

遊戲移動圖片的轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.