To move a picture's transformation:
Defines a direction that, when moved, determines whether the next move is the current direction, and if not, only changes the picture and does not move.
1 PackageCom.itheima.bean;2 3 Public classTankextendsElement {4 Private intSpeed = 64;5Direction Direction = direction.up;//Initial up6 7 PublicTank (intXinty) {8 This. x =x;9 This. y =y;Ten This. ImagePath = "Res/img/tank_u.gif"; One A } - - Public voidMove (Direction dir) { the if(Direction! = Dir) {//if the direction passed in is not equal to the current direction -Direction =dir; - Switch(dir) {//convert pictures by direction - CaseUp : + This. ImagePath = "Res/img/tank_u.gif"; - Break; + A CaseDown : at This. ImagePath = "Res/img/tank_d.gif"; - Break; - CaseLeft : - This. ImagePath = "Res/img/tank_l.gif"; - Break; - CaseRight : in This. ImagePath = "Res/img/tank_r.gif"; - Break; to } + return;//do not continue down execution - } the Switch(dir) {//Moving * CaseUp : $Y-=Speed ;Panax Notoginseng Break; - the CaseDown : +Y + =Speed ; A Break; the CaseLeft : +X-=Speed ; - Break; $ CaseRight : $X + =Speed ; - Break; - } the } -}View Code
Essay says:
The game movement principle is the picture coordinates change displays.
Conversion of game Moving pictures