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.
For example, you might have a method on the model called “getVisual()” that returns a 3D model, a sprite, an animation, etc. The “controller” communicates with the model, and the view is supplied by the model, in contrast to having a controller that communicates explicitly with both the view and the model. Whether this is lazily created, loaded by a resource manager, accessed via a weak reference, etc., does not contradict the use of the MVP architectural pattern. The more I think about it (and this is my third post edit), I think what you’re describing could just as well be MVC as MVP. That is, it doesn’t contradict the use of MVP instead. For instance, one can still serialize a data object and pass it between clients and servers. Each client should be able to generate the view for the object. Technically, the server could too, but of course it wouldn’t.