Hi, I cannot get the Mvc patern applied to the game i’m planning.
I got my game loop with active rendering. In the View class, How do I paint on the screen can I use a function like this?
paintCursor(Cursor cursor, Graphics g) ?
the Graphical representation of a cursor cursorGfx:
public class CursorGfx extends TileSprite {
private Animation anim;
private int cursorWidth, cursorHeight;
private int offsetX, offsetY;
public CursorGfx(int row, int col, int tileSize, LinkedList<BufferedImage> imgList) {
super(row, col, tileSize);
initAnimation(imgList);
try {
Image img = imgList.get(0);
cursorWidth = img.getWidth(null);
cursorHeight = img.getHeight(null);
} catch(Exception e) {
e.printStackTrace();
}
// The cursor can be smaller or bigger then the TileSize.
//offsetX = (cursorWidth - world.getMapTileSize()) / 2;
//offsetY = (cursorHeight - world.getMapTileSize()) / 2;
}
private void initAnimation(LinkedList<BufferedImage> imgList) {
anim = new Animation();
anim.addFrame(imgList.get(0), 250);
anim.addFrame(imgList.get(1), 500);
}
public void update(long elapsedTime, local.model.map.Cursor cursor) {
super.update(elapsedTime); // Update Animation
super.setPixelLocation(cursor.getX(),cursor.getY()); // Update Position
}
public void paint(Graphics g) {
super.paint(g);
paintPosition(g);
}
private void paintPosition(Graphics g) {
g.setColor( Color.GREEN);
g.drawString("posX:" + super.getLocX(), 5, 200);
g.drawString("posY:" + super.getLocY(), 5, 215);
}
Do I have to add a update Method that updates the position prior to the painting?
or can I not pass a Model object to the view so i would need to use paintCursor(int x, int y, boolean active , Graphics g) ?
in my Game loop I have:
cursor.setPixelLocation(input.getMouseX(), input.getMouseY());
screen.updateCursor(elapsedTime, cursor);
screen.paint(g)
or how do you paint your model to the screen.