Tile maps and scrolling

There seem to be a number of questions on how to

1> get smooth scrolling
2> use tile maps
3> use full screen
4> etc…

So I thought this example code might help in all of these areas.

http://www.scottshaver2000.com/files/scrollerexample.zip

You need to unzip it and then cd into the scroller directory and type:

java -cp . com.sas.planetation.examples.MapDisplayExample

Use the cursor keys to scroll around the map and the ‘Q’ key to exit the program.

Update: I just tried this at work with an NIVIDIA RIVA TNT2 Model 64 and the scrolling isn’t very smooth, in fact it is awful. Strange given that I had it perfectly smooth on my home machine with the same card before I upgraded to a GeForce4. Must be a driver issue.

I didn’t look at the code(I don’t have time), but it works as advertised and looks good. nice job. I will definitely look into it further later. :smiley:

Ray

woa :o

80fps smoothnes @ 1024x768, now I need to read the code!!

Don’t be too impressed. ;D On some older versions of the NVIDIA drivers, it sucks. However the newer drivers work excellent.

It sucked for me :slight_smile:

1024x768x32bit @ 70Hz I got from 11-21 fps… and the movement was very jerky. Oh, and it only took up the upper right corner of the screen.

Java 1.4.1-b21
Dual 667MHz P-III
nVidia GeForce DDR
driver version 6.13.10.2312

Tried again on another system

Java 1.4.1_01
Dual 1GHz P-III
nVidia GeForce2 MX/MX 400
driver version 6.13.10.4072

1024x768x32bit @ 70Hz - got nothing but a black screen
tried again at:
640x480x16bit @ 60Hz - got 60 fps, cool!
800x600x32bit @ 75Hz - got 75 fps (but only in the upper right corner)

went back to 1024x768x32bit @ 70Hz and it was working… doh! (70 fps)

So the code is cool… but something with fullscreen mode is flakey

Disturbing, I can max the frame rate (to the refresh rate) with any mode.

Java 1.4.0
1.2MHz P-IV (640meg ram, dual displays)
nVidia GeForce Ti 4600 (128megs ram)
driver version 6.13.10.3082

There seem to be a lot of issues with the nVidia drivers. Everytime I’ve changed versions it messed something up. So I’m sticking with the ones I have.

The map is intentionally only displayed in the upper right of the screen. The MapDisplay class allows you to place it anywhere on screen at any size. This way you don’t have to use the entire screen for the map. Like adding other components around it, score, meters, etc.

Edit: I wonder if I should upgrade to 1.4.1 and recompile everything. Perhaps this would help the systems that are having trouble.

[quote]1.2MHz P-IV (640meg ram, dual displays)
[/quote]
That would be really impressive if you could max the frame rate with a 1.2 MHz machine, I think you meant GHz ;D

If you make any changes/recompile and would like me to test again on that machine that was only getting 11-21 fps, just email me (scott dot palmer at 2connected dot org)

How did you make the .map, and .pal files?

And thank you. I’m going to try and take different parts of that out to figure out the absolute basics.

The .map and .pal files are created with a map editor I have built. (note that the code has changed slightly since this zip was put together and I haven’t updated the zip. it still works but the map and pal file formats have changed. I needed to add version numbers, exception handling and some other info to the data files. Use the MapDisplayExample in the files refered to by the link below for the latest and greatest) See the following thread for more info:

http://www.java-gaming.org/cgi-bin/JGOForums/YaBB.cgi?board=volunteer;action=display;num=1038158514

swpalmer: Opps, I did mean Ghz not Mhz. ;D Also there is a new tile map scrolling demo included in the code. See the thread mentioned above for details.

Hi, I have a laptop that supports up to 1400x1050@32 and all the resolutions gave me 60fps (max based on the refresh rate) except running at 1400x1050@32 and 1280x 1024@32 which gave me 6fps. (however, 10400x1050@16 gave me 60fps and 1024x768@32 gave me 60fps). I have a 1.8ghz P4 with NVIDIA GF4 Go video. Very smoothe animation except for the very high resolutions…I don’t know if it’s a geometry problem, driver problem, or what, but to get max frames at 1024x768@32 is nice. (even 1400x1050@16 is good)

-Chris

one commonly asked question is doing independent animation loops of sprites in the game, I was wondering if this could be added to your code, and then the source provided for learning experiences? I’m sure everyone has an idea of how to do it properly, but since you already have the drawing routines down to scroll smoothly, could it be extended to support animation loops of arbitrary sprites?

-Chris

I’m not sure what you mean by "independent animation loops ". I assume you don’t mean a separate thread per sprite. My sprite system can handle animations at different speeds for any number of sprites. Also has ability for 1 to n animations per sprite.

I’m working on a Impossible Mission (from the old C-64 days) rip off with a few new twists that uses the tile map system. I’ll put it up when it’s finished. Also the AnimImageSprite example show a number of sprites animating at different speeds.

I need to get the animated tile palette code working in the map editor so you can have animated tiles as well.

Yep, you would be correct: I don’t want separate threads for animation. I’m sorry I didn’t look closer at the code, I’ll take a closer look and see how you are doing it, but basically, that’s exactly what I would want: N sprites animated at X FPS with any number of animation frames per sprite…and manged through a single thread (the main game thread). Thanks for the info.

-Chris

I’m working on completeing the javadocs for all of the classes. Hopefully this will help shed some light on what I was thinking as I built the system.

Currently everything is based on milliseconds for animations, updates, movement, etc. I’m thinking about adding methods that allow these thing to be controlled via a specific number of screen frames as well.

The way I have it set up that shold be easy to do without breaking anything I already have, and then you can choose which way you want the control to happen.

[quote]Hi, I have a laptop that supports up to 1400x1050@32 and all the resolutions gave me 60fps (max based on the refresh rate) except running at 1400x1050@32 and 1280x 1024@32 which gave me 6fps. (however, 10400x1050@16 gave me 60fps and 1024x768@32 gave me 60fps). I have a 1.8ghz P4 with NVIDIA GF4 Go video. Very smoothe animation except for the very high resolutions…I don’t know if it’s a geometry problem, driver problem, or what, but to get max frames at 1024x768@32 is nice. (even 1400x1050@16 is good)

-Chris

[/quote]
I think the problem with the two slow modes is that I have the program set to use 3 buffers in the buffer strategy. When there isn’t enough video memory to fit all of them some can be put in main memory and therefore they won’t be accelerated. You might try changing the buffers down to 2 and then run it.

1400x1050@32 * 3 buffers is around 141 megs of video ram. 1280x 1024@32 * 3 buffers is around 125 megs of video ram.

I’ll try it. I wonder if there’s a way to figure out how much volitile storage you have (I would guess not, seems very platform specific) but I’m wondering how I would do this in practice, start with 3 frames of buffered strategy, and if the fps is low, reduce the number of frames in the strategy? hmm

-Chris

Hi, I tried to do a build on the source you gave, but the compiler says the follwoing problems:

com/sas/planetation/examples/MapDisplayExample.java [13:1] cannot resolve symbol
symbol : class BitmapFont
location: package data
import com.sas.planetation.data.BitmapFont;
^
com/sas/planetation/examples/MapDisplayExample.java [14:1] package com.sas.planetation.sprites does not exist
import com.sas.planetation.sprites.ScoreSprite;
^
2 errors

Looks like a few classes weren’t included in the zip. care to update the zip with the classes so I can see if changing the buffer strat works?

-Chris

UPDATE:
Doh! I just removed the imports because they aren’t actually being used in the code and got it to recompile. I will send an update to this message when I see if a buff strat of 2 works better.

UPDATE2:
Ok, I made the buffstrat use 2 frames instead of 3, and the 1280x1024x32@60 worked properly now, but 2 would not work at 1400x1050x32@60 (I should use the proper notation for the display modes, eh?). I set the buffered strategy to 1 (I donno if that’s legal) but got hideous screen flickering, so never use a buffer strat of 1 :slight_smile: The 1400x1050x16@60 worked fine with a buff strat of 2.

That’s very interesting how the buffer strategy requires all frames to be alloocated in memory or it gives up (guess it makes sense, but it’s interesting to me, nonetheless).

Thanks for the demo and source, I think this is the right way to do 2d based games.

-Chris

Okay, that old zip file is out of date so I’ve put up a new jar file that contains all the classes, source, resources and javadocs at:

http://www.scottshaver2000.com/planetation/files/planetation.jar

Just unzip the enitre contents of the jar into a directory. You will get the following sub directories:

src <-- java source files
api <-- javadocs
com <-- compiled classes and resource files

This file is the lastest for the system, I’m almost at version 1.0. ;D

The javadocs are far more complete now. I’ve also included an example of the MultiAnimImageSprite class in the AnimImageSpriteExample. All examples classes are in the com.sas.planetation.examples package and each one has a main() method. Also I’ve turned the display of the FPS on for all examples.

The new MapDisplayExample contains a better map file than the old one.

I found a number of bugs in the MapDisplay class from my Planetation system that only show up under very specific cercumstances. If anyone is using that code from the tile map and scrolling demo I put up and would like to have a new version of the source let me know.

8 bits in a byte, 32bit = 4byte :wink:

1400105043 = 17640000 bytes = 16.8mb
1280
102443 = 15728640 bytes = 15mb

:-X

anyhow, its nice and smooth ;D