wombatactor.java
来自「《J2ME Game Programming》随书光盘源代码」· Java 代码 · 共 50 行
JAVA
50 行
import javax.microedition.lcdui.Graphics;
/**
* The main player actor, the Wombat.
* @author Martin J. Wells
*/
public class WombatActor extends Actor
{
/**
* Constructs a new WombatActor object using the specified GameScreen and
* position.
* @param gsArg The GameScreen this Actor is associated with.
* @param xArg The x starting position.
* @param yArg The y starting position.
*/
public WombatActor(GameScreen gsArg, int xArg, int yArg)
{
super(gsArg, xArg, yArg);
}
/**
* Renders the actor to the screen by drawing a rectangle.
* @param graphics The graphics context to draw to.
*/
public void render(Graphics graphics)
{
graphics.setColor(0x0044FF44);
graphics.fillRect(getX(), getY(), getActorWidth(), getActorHeight());
}
/**
* An overridden version of the Actor setX method in order to stop the
* wrapping it does. You want the wombat to stop on the edge of the screen.
* @param newX The new x position.
*/
public void setX(int newX)
{
super.setX(newX);
// non-wrapping version for the wombat
if (getX() < 0)
setX(0);
if (getX() > gameScreen.getWidth()-getActorWidth()-2)
setX(gameScreen.getWidth() - getActorWidth()-2);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?