1
package com.brackeen.javagamebook.graphics;
5
import com.brackeen.javagamebook.tilegame.sprites.Bullet;
9
protected Animation anim;
13
// velocity (pixels per millisecond)
17
public void setStartingFrame(int startingFrame) {
18
anim.setStartingFrame(startingFrame);
21
Creates a new Sprite object with the specified Animation.
23
public Sprite(Animation anim) {
28
Updates this Sprite's Animation and its position based
31
public void update(long elapsedTime) {
32
x += dx * elapsedTime;
33
y += dy * elapsedTime;
34
anim.update(elapsedTime);
38
Gets this Sprite's current x position.
45
Gets this Sprite's current y position.
52
Sets this Sprite's current x position.
54
public void setX(float x) {
59
Sets this Sprite's current y position.
61
public void setY(float y) {
66
Gets this Sprite's width, based on the size of the
69
public int getWidth() {
70
return anim.getImage().getWidth(null);
74
Gets this Sprite's height, based on the size of the
77
public int getHeight() {
78
return anim.getImage().getHeight(null);
82
Gets the horizontal velocity of this Sprite in pixels
85
public float getVelocityX() {
90
Gets the vertical velocity of this Sprite in pixels
93
public float getVelocityY() {
98
Sets the horizontal velocity of this Sprite in pixels
101
public void setVelocityX(float dx) {
106
Sets the vertical velocity of this Sprite in pixels
109
public void setVelocityY(float dy) {
114
Gets this Sprite's current image.
116
public Image getImage() {
117
return anim.getImage();
121
Clones this Sprite. Does not clone position or velocity
124
public Object clone() {
125
return new Sprite(anim);