In the game it is not always possible to allow a scene to go through all the way, which brings up the requirements of the scene change, based on the implementation of this requirement, we will have the following effect of Java code implementation.
Download Address Http://www.3adisk.com/?onlinezero[filename: Rpgchair0to6.rar]
or save the following x (GIF) files as rar
Since the amount of code has started to increase, starting from this back to give only a partial code implementation, detailed download:
In this example, I take the bitmap offset algorithm as follows:
The Mypanle is implemented as follows:
X Offset Position
int OffsetX = mypanel.width/2-Role.getx () * CS;
Calculate x Offset
OffsetX = math.min (OffsetX, 0);
OffsetX = Math.max (OffsetX, mypanel.width-gamemap.width);
Y offset position
int OffsetY = MYPANEL.HEIGHT/2-Role.gety () * CS;
Calculate y Offset
OffsetY = math.min (OffsetY, 0);
OffsetY = Math.max (OffsetY, mypanel.height-gamemap.height);
System.out.print (Role.getx () + ":" +role.gety ());
Draw a map that can be offset
Map.draw (g, OffsetX, OffsetY);
To draw the role of an offset position
Role.draw (g, OffsetX, OffsetY);
In both Gamehandle and Gamemap, the offsetx and offsety values should be injected to generate the corresponding images.
Gamehandle implementation:
Starting with the Example6, all algorithms are added to the offset value to achieve the background movement.
Public void Draw (Graphics g, int offsetX, int OffsetY) {
Takes count as the offset value of the image and adds direction to the Example4 to get the image block position
G.drawimage (image, X * cs + offsetX, Y * cs + offsetY, X * cs + OffsetX + cs, Y * cs + OffsetY + cs,
Count * cs, direction * CS, CS + count * cs, Direction * CS + cs, panel);
}
Gamemap implementation:
Correcting the plotting method in EXAMPLE6 and introducing map coordinate offset calculation
Public void Draw (Graphics g, int offsetX, int OffsetY) {
int Firsttilex = pixelstotiles (-OFFSETX);
Change x coordinates
int Lasttilex = Firsttilex + pixelstotiles (mypanel.width) + 1;
Returns the minimum x offset value
Lasttilex = Math.min (Lasttilex, COL);