import
java.awt.Image;
public
class
Sprite {
private
Animation ani;
private
float
x;
private
float
y;
private
float
vx;
→ 速度
private
float
vy;
→
速度
public
Sprite(Animation ani){
this.ani
= ani;
}
//改變動畫移動位置
public
void
update(long
timePassed){
x
+= vx
* timePassed;
y
+= vy
* timePassed;
ani.update(timePassed);
}
//得到x位置
public
float
getX(){
return
x;
}
//得到y位置
public
float
getY(){
return
y;
}
//設置動畫x位置
public
void
setX(float
x){
this.x
= x;
}
//設置動畫y位置
public
void
setY(float
y){
this.y
= y;
}
//得到動畫的寬度
public
int
getWidth(){
return
ani.getImage().getWidth(null);
}
//得到動畫的高度
public
int
getHeight(){
return
ani.getImage().getHeight(null);
}
//獲得的水平速度
public
float
getVelocityX(){
return
vx;
}
//獲得垂直速度
public
float
getVelocityY(){
return
vy;
}
//設置水平速度
public
void
setVelocityX(float
vx){
this.vx
= vx;
}
//垂直速度設置
public
void
setVelocityY(float
vy){
this.vy
= vy;
}
//獲得動畫或圖像
public
Image getImage(){
return
ani.getImage();
}
}
沒有留言:
張貼留言