• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Arch@on

[java] Questions about scrolling engine

7 posts in this topic

Right now I have charachter who can walk on map image. I have limited the walking aea to 96 pixels from every edge and now I have been thinking about how to make it scroll. Because my game is turn based my character jumps from tile to tile. I used to have some scrolling but it was way too slow and I didn''t know way to optimize it up so I decided to post here. What should I do? Should I draw everything to one bigger map image and then show part of it or what. If so can you give me example or something? Time comes, time goes and I only am.
0

Share this post


Link to post
Share on other sites
Someone correct me if I''m wrong, but I think you are on the right track about saving a map image. I think you would get the best performance if you made the map once on a *large* surface and then just Blt the part that is visible at the moment. This isn''t really feasable on a decent sized map, so the next best thing is to save part of the map. The best way to go, i believe, is to save the map image from the last frame (before adding any of the characters or other non static overlays) and then use as much of this image for the next frame as possible. In the best case, the screen won''t scroll and you will have your map image already. In the worst case you will have to scroll it by a tile or so horizontaly and vertically so you will have to update a row and a collumn of tiles (but the rest can just be shifted.

You might even be able to skip a temp surface and just use the data in the backbuffer from 2 frames ago... clearing the stuff that has changed, etc. but this would be much more complicated to keep track of I think, so a temp surface is probably the way to go.
0

Share this post


Link to post
Share on other sites
If you''re using a tile engine, it''s not very hard to do scrolling. You just have to rewrite the whole scene decaling it from 2 or more pixels.
You''ll have a nice smooth scrolling.
You should make a ''free'' zone in which the character can move and there''s no scrolling. When the character comes close a side, the scrolling begin, speeding up as it''s closer to the side.
Of course, it must be a blocked area where the sprite can''t go.
After the character has moved, the screen recenter on it, with the same process.
(Fast when he is far from the center, slower when he get closer)

-* Sounds, music and story makes the difference between good and great games *-
0

Share this post


Link to post
Share on other sites
oups, sorry didn''t see it''s for turned based game.

You just have to redraw the scene (each tile) with Xpixels decaling.
Use tripple buffering to improve performance.
Tiling is most effective in term of speed and memory usage.
Big BMP/anything (just like in Baldur''s Gate) require very fast compiled code, or hardware acceleration.

You''re character might move during the time you''re redrawing the map, such everything will be in movement.

Optimizing is as said by chippydip to save the previous image, compute the changes, redraw what''s required, blit it with Xbits decals and then redraw ''objet'' & ''character'' layers, if you have such.

Hopes it help, if you feel I''ve not well explain, just mail me, I''ll to try again :o)

-* Sounds, music and story makes the difference between good and great games *-
0

Share this post


Link to post
Share on other sites
This is just the way I do it. I have a linked list of all the tiles on my map. I make sublists that represent horizontal rows of the map each being two tiles longer than the map. I also make two more rows than necassary. This gives me a one tile cushion around the whole outside. So only the data from the sublist rows gets painted each cycle. The problem I have is deciding when to redefine those sublists, but that''s because my game is not turn based, it''s free flowing. Right now I calculate the sublists every draw cycle and it seems to run fine on my 300MHz machine. I think I will keep a running tab of how many pixels the player has scrolled, and if it''s greater than the size of one of my tiles, reload the sublists.
0

Share this post


Link to post
Share on other sites
Ok I barely got the main idea so what modifications should be done to this example from JDGC:

/*
MapTest.java
a demo of a simple tile map
the red focus is arrow key controllable
*/
//**************************************************
// COPYRIGHT & LEGAL NOTICE
// This source code copyright 1998 Grey Creations, Ltd.
// Non-commercial, personal use is permitted.
//
// This file is not to be posted in a public space or distributed
// in any form without prior consent.
//
// The Author and Grey Creations, Ltd. make no warranty of any kind, expressed or implied,
// with regard to this program. The Author and Grey Creations, Ltd. shall not
// be liable in any event for incidental or consequential damages in
// connection with, or arising out of, the furnishing, performance, or
// use of this program.
//
// If you find this useful please let me know: grey@panix.com
// Thanks for helping to make the Java Game Development Center great!!!
//**************************************************

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

public class MapTest extends Applet {

MapView map;

CellImage testImage; // the multi-cell image with the terrain pics in it

public void init() {
setLayout(null);
//setBackground(new Color(0,0,0));

// specify your image info here
testImage = new CellImage(this, "grass1.gif", // put your filename here
new Dimension(32, 32), // cellSize in pixels
new Dimension(1, 6), // cellLayout -- how many cells across and down
6); // how many actual cells there are (in case you don''t fill the image)

// this holds the terrain data to pass to the map
// we''ll make an 8x6 map
// the numbers correspond to cells in the testImage
int[][] tArray = {{0, 1, 0, 1, 0, 1, 0, 1,0},
{4, 5, 4, 5, 4, 5, 4, 5,0},
{0, 1, 0, 1, 0, 1, 0, 1,0},
{2, 1, 4, 5, 4, 5, 4, 5,0},
{4, 5, 2, 3, 1, 0, 1, 0,0},
{2, 3, 2, 3, 3, 2, 3, 2,0},
{2, 3, 2, 3, 3, 2, 3, 2,0}
{2, 3, 2, 3, 3, 2, 3, 2,0}};

// create the map
map = new MapView(tArray, testImage);
add(map);

addKeyListener(map);
//repaint();
Button au= new Button("Au");
au.setBounds(50,50,300,200);
add(au);
}

public void start() {
map.requestFocus();
}

public void update(Graphics g) {
paint(g);
}

public void paint(Graphics g) {
map.paint(g);

}


} // end of applet


class MapView extends Canvas implements KeyListener {
Dimension mapSize = new Dimension(); // the actual size in pixels of the map component
Dimension mapLayout = new Dimension(); // how many cells across and down to display
Dimension cellSize; // width / height of a map tile
CellImage mapTiles; // the terrain tiles

public int focusX = 0; // which tile gets the hilite
public int focusY = 0;

Point viewOrigin = new Point(0, 0); // which map space corresponds to the upper left tile of the view

int terrainArray[][]; // integer representation of map

Point paintXY = new Point(); // where to paint each terrain tile

public MapView(int aTerrainArray[][], CellImage aMapTiles) {
super();
terrainArray = aTerrainArray;
mapLayout.width = terrainArray[0].length;
mapLayout.height = terrainArray.length;
mapTiles = aMapTiles;
cellSize = mapTiles.getCellSize();
mapSize.setSize(mapLayout.width * (mapTiles.getCellSize().width),
mapLayout.height * (mapTiles.getCellSize().height));

addKeyListener(this);
requestFocus();
}

// override necessary functions for Canvas class
public Dimension getSize() { return mapSize; }
public Dimension getPreferredSize() { return mapSize; }



public void setFocusTile(Point p) {
focusX = p.x;
focusY = p.y;
}



// draw the entire map
public void paint(Graphics g) {
g.setColor(Color.red);
for(int y = 0; y < mapLayout.height; y++)
for(int x = 0; x < mapLayout.width; x++) {
paintXY.setLocation(x * cellSize.width, y * cellSize.height);


// notice that x, y are reversed here because
// that is how the arrays are specified
mapTiles.paint(g, paintXY, terrainArray[y][x]);
}
// reset the clip rectangle from the map draw operation
g.setClip(0, 0, mapSize.width, mapSize.height);
// draw the focus
g.drawRect(focusX * cellSize.width, focusY * cellSize.height,
cellSize.width-1, cellSize.height-1);
}


public void keyPressed(KeyEvent ke) {
switch(ke.getKeyCode()) {
case KeyEvent.VK_RIGHT: focusX++;
break;
case KeyEvent.VK_LEFT: focusX--;
break;
case KeyEvent.VK_UP: focusY--;
break;
case KeyEvent.VK_DOWN: focusY++;
break;
}
// check bounds
if(focusX < 0) focusX = 0;
if(focusY < 0) focusY = 0;
if(focusX > mapLayout.width - 1) focusX = mapLayout.width - 1;
if(focusY > mapLayout.height - 1) focusY = mapLayout.height - 1;
getParent().repaint();
}

public void keyReleased(KeyEvent ke) { }
public void keyTyped(KeyEvent ke) { }

}


class CellImage {
// parent applet
Applet mom;

// how many cells across and down (col/row) in layout
Dimension cellLayout;

// the dimensions of a single cell
Dimension cellSize;

int numCells; // The number of cells in the image

Image image; // the master image that holds all the cells

int curCellNum = 0; // which cell to paint on request

// pass Applet context, Image filename, width/height of a cell,
// how many cells fit across and down the image,
// and how many actual cells there are to display
public CellImage(Applet aMom, String imgName, Dimension aCellSize, Dimension aCellLayout, int aNumCells) {
mom = aMom;
cellSize = aCellSize;
cellLayout = aCellLayout;
numCells = aNumCells;

image = mom.getImage(mom.getCodeBase(), imgName);
}

public Dimension getCellSize() { return cellSize; }
public int getNumCells() { return numCells; }


public void paint(Graphics g, Point p, int cellNum) {
curCellNum = cellNum;

// paint which cell #?
int iNum = cellNum;

// check for overflow
if(iNum > numCells - 1) {
curCellNum = 0;
// paint gray
g.setColor(Color.darkGray);
g.fillRect(p.x, p.y, cellSize.width-1, cellSize.height-1);
} else {

// where to paint cell
int userX = p.x;
int userY = p.y;

// locate the cell to paint
int col = iNum % cellLayout.width;
int row = iNum / cellLayout.height; // width?

// this is the amount to shift the entire source image
int offsetX = - (col * cellSize.width);
int offsetY = - (row * cellSize.height);

// set clipping rect to cell size at specified location
g.setClip(userX, userY, cellSize.width, cellSize.height);

// paint into graphics context
if (image != null)
g.drawImage(image, userX + offsetX, userY + offsetY, mom);
}
}
} // end cellImage

Ok first I should of course make the screen let''s say 96x96 area which is rather easy but what then? I''m completely out of ideas...
0

Share this post


Link to post
Share on other sites
I''ll start with the beginning.
Load your map.
Init the game, and draw the complete image.
You must know where you stand in the world map, and knowing where the edges lies (because you know the screen size) you know to which tiles it is corresponding.
When the player moves, copy the front to the back, with X pixels decals, and then read the borders tiles and draw them where they must.
repeat this step as required.
When you change map, you have to re init and draw it a first time.

I''m busy and tired, that''s why I''m not giving code solution.

-* Sounds, music and story makes the difference between good and great games *-
0

Share this post


Link to post
Share on other sites
I''ll start with the beginning.
Load your map.
Init the game, and draw the complete image.
You must know where you stand in the world map, and knowing where the edges lies (because you know the screen size) you know to which tiles it is corresponding.
When the player moves, copy the front to the back, with X pixels decals, and then read the borders tiles and draw them where they must.
repeat this step as required.
When you change map, you have to re init and draw it a first time.

I''m busy and tired, that''s why I''m not giving code solution.

-* Sounds, music and story makes the difference between good and great games *-
0

Share this post


Link to post
Share on other sites