FAQ
From FANG
Eclipse questions
I downloaded and unzipped Eclipse. How do I install it?
You don't need to install Eclipse. Once you unzip it, just look for eclipse.exe. Double click and Eclipse will start.
When I load the gaming engine into my Eclipse workspace, all of the files are flagged with errors like
The type HashSet/ArrayList is not generic; it cannot be parameterized with arguments <Sprite/ImageSprite>
Why doesn't it work?
You need your workspace settings to 5.0 compliance:
Project->Properties->Java Compiler->Configure Workspace Settings...->Compiler Compliance Level->5.0
Every time I extend GameLoop, it gives me the warning
serializable class X does not declare a static final serialVersionUID field of type long
This is just a warning. You do not need to fix this because the class you are writing will never be serialized by the gaming engine. If you really want the warning to go away, add the code to your class:
static final long serialVersionUID=0;
When I try to Javadoc my code, the 'Next' and 'Finish' buttons are disabled.
What do I do now?
You need to Configure the Javadoc command. Click on 'Configure' Go to where you installed the Java JDK. Go into the bin folder and select javadoc.exe. If you are using windows this is likely in a folder like
C:\Program Files\Java\jdk1.5.0\bin
Once you select javadoc.exe, the 'Next' and 'Finish' buttons should be enabled.
I downloaded the gaming engine and tried to run it, but I get this weird error that says
Activation.main: warning: sun.rmi.activation.execPolicy system property unspecified and no ExecPermissions/ExecOptionPermissions granted; subsequent activation attempts may fail due to unsuccessful ExecPermission/ExecOptionPermission permission checks. For documentation on how to configure rmid security, refer to: http://java.sun.com/j2se/1.4/docs/tooldocs/solaris/rmid.html
http://java.sun.com/j2se/1.4/docs/tooldocs/win32/rmid.html
How do I get this thing to work?
First, the gaming engine is not a game. It is the code and packages which can be used to write games. When you download fang.jar, you are downloading the packages and code which can help you write a game. You are not downloading an application you can run. Second, if you have downloaded the code for a game as well as the gaming engine, then you are getting this error because you are not running the game as an application. When you tried to run the game, you probably had the project name highlighted then selected Run->Run As->Java Application then pressed Okay when the Run Type window came up. This is not how you run applications in Eclipse. Instead, highlight the game you want to run in the Project Explorer, then right click and select Run As->Java Applet. If the game is also written to be an application (not all games are), you can select Run As->Java Application.
When I import the jar file for a game into a project containing the gaming engine, it comes up with all sorts of errors even though it is supposed to just work.
I get packages in them twice like pong.pong or fang.fang.
Your problem is the way you are importing the jar file into the project. When you import packages, you import them relative to the location you have highlighted in the Project Explorer. It seems you have been importing the game jar file when you likely have one of the packages highlighted instead of the project name. To fix this error, remove all packages that have two or more package names in them (like pong.pong or fang.fang), then highlight the Project name in the Project Explorer and import the jar file again. In the future, be sure to have the Project name highlighted before importing jar files.
I downloaded the code for a game, but when I run it, it says that there are compilation errors.
It says
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method runAsApplication() is undefined for the type
What do I do?
This error is most commonly caused by downloading the code for a game, but without the gaming engine. To fix this problem, download the most recent version of the gaming engine Media:fang.jar fang.jar.
I get the following error when I run my game: NullPointerException.
java.lang.NullPointerException: Cannot add null Sprite to AnimationCanvas at fang.AnimationCanvas.addSprite(AnimationCanvas.java:176) at wackadot.Wackadot.addSprites(Wackadot.java:102) at wackadot.Wackadot.(Wackadot.java:51) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at sun.applet.AppletPanel.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(Unknown Source) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)</span>
What is wrong?
As the error states this is because you are trying to add a null Sprite to the AnimationCanvas. To fix this error, go to the topmost class that you wrote and go to the line number indicated. For the case of the specific error above, you would go to line 102 of Wackadot.jave. On this line you will see something like
canvas.addSprite(someSpriteHere);
The sprite you are trying to add has not been initialized. To fix this error, you need to initialize the sprite before adding it to the canvas. This initialization should look something like
someSpriteHere=new SomeSpriteClass(someParameters);
In general when you get a NullPointerException, you should go to the topmost class that you wrote and investigate the objects used in the line indicated. One of these objects may not be initialized (or it could be an uninitialized object is being used in the method called on the line).
Sometimes I need to go to a particular line number in my code. How do I get Eclipse to show the line numbers?
Go to Window->Preferences->General->Editors->Text Editors and select Show Line Numbers. Or you could just right click in the margin to the left of the code and put the checkbox by 'Show Line Numbers'.
I used to be able to see all of my classes on the left frame, but now they have disappeared. How do I get them back?
Go to Window->Show View->Package Explorer.
Running/Posting Game
Help! I click on the fang.jar and it won't even run.
I get the error:
Failed to load Main-Class manifest attribute from C:\Documents and settings\desktop\fang.jar.
The gaming engine is a set of packages used to make games, not a game itself, therefore it cannot be run. The jar file contains code which can be used to make games. If you want to run sample games, [Student_Games |go here].
I exported the jar file, but it doesn't have my help file/audio clip/image.
This usually happens when Eclipse is out of sync with the file system. What happens is that you create or add some files within the project, but not using Eclipse. When you export the jar file, Eclipse only uses the files it knows about. Since the files were added outside of the Eclipse environment, it does not add them to the jar. The fix is to resynchronize the project and the file system. Highlight the project, right click, and select refresh. This will update the list of files within your project to be consistent with the file system. Now export the jar file again and this time it will include the newly found files within the project.
The applet works fine in Eclipse, but the audio/images are messed up when I try to post the applet to my web page.
Some operating systems such as Windows are case insensitive. Java is case sensitive. This can sometimes cause a problem because a case mismatch will not be detected when developing the game on a Windows computer, but when posting the game, the case mismatch becomes a problem. For example, in Windows when you have audio or image files, the filenames are not case sensitive when using Eclipse. It is possible to load image.jpg when the actual file name is image.JPG or to load your help file as Help.html when the file is actual Help.HTML. To fix this error, check all the filenames for case sensitivity.
The applet works fine in Eclipse, but there is a red X when I try to post the applet to my web page.
The following explanations assume you have read Posting Your Game.
This error of the red X appearing can be caused by a number of reasons:
- The most common reason is that the jar file is not in the same folder as the html from which it is linked. To fix this, just be sure to copy the jar file into the same directory or folder as
the html file from which it is linked. You also need to make sure the jar file has permissions set such that it is readable. You can check this by going to the web address of the jar file and seeing if it comes up for you to save or view.
- The second most common reason is that the name of the class is not fully specified. An example of not fully specifying the class name would be code="Wackadot.class". The correct fully specified name may be code="wackadot/Wackadot.class". To fix this error, fully specify the class name.
- The third most common reason is that there is a typo in the name of your class or jar file. Remember, these are case sensitive. To fix this error, correct any misspelled names or
improperly cased names.
- The fourth most common reason is that the jar file does not contain both your game and the gaming engine. Make sure you include in your jar file the following packages: fang, fang.resources,
and your game's packages.
The applet I posted on my web page works fine when I view it, but other people tell me it is not working.
The gaming engine uses Java 1.5 (or higher). If the version of Java is less than 1.5, then the appler will not load. To fix this error, the computers must install the Java 1.5 Plug-in for the browser used. Usually clicking on the red X will take them to the place to download the most recent version of Java.
My game is too slow. Why is it so slow?
This is a complicated question, hopefully with a simple answer! There are a few common reasons game can run more slowly than you would like. The three primary reasons are:
- having too many sprites on the canvas
- doing too much work in the advanceFrame method, and
- making the game too many pixels wide and tall.
Simply put, the more sprites on the screen, the slower the game play is going to be. If you have too many sprites, consider how you could reduce the number of sprites. This type of slow down would happen with most any gaming engine to a lesser or greater extent. The second most common reason is that too much is being done in the advanceFrame method. The time between frames is about 1/24 seconds. Some common time consuming activities include:
- adding sprites every frame. Your canvas would be accumulating sprites at a rate of at least 24 per second. You'll have about 100 sprites added every four seconds. In just over a minute of the game running, you'll have 1500+ sprites and the game will be very slow or frozen.
- calling the setText method on StringSprites every frame. StringSprites actually consist of several points and are somewhat expensive to make and/or alter. (PrettyStringSprites are even more time consuming to manipulate.)
- making Alarms go off to frequently. No more than 25 alarms really ought to be going off every second
If none of the above changes make your game faster, you'll just need to remove and add the parts of your game until you find out what is making it slow. Professionals do this with a tool called a profiler.
I want to share the source code for my game. How do I link it up to my website?
Link to the jar file you created in order to post your game. Another even better way to share your source code is to include the source when you generate your javadoc.
When I try to export my JAR file, it says JAR creation failed. See details for additional information.
It says
JAR creation failed. See details for additional information. ... Resource is out of sync with the file system: some_file Resource is out of sync with the file system: some_file ...
Eclipse sometimes gets confused when you make changes to files or folders inside of a project folder, but using a different application than Eclipse. A common example of this is adding audio, image or html files. The way you fix this is to highlight the project name and select refresh. The will sync back up the file system with Eclipse.& After doing this, you should be able to export the jar file properly without the sync errors.
When I post my multiplayer applet, it always says: Cannot connect to www.somedomain.edu
It says
Cannot connect to www.somedomain.edu Server unavailable or SomeGame full.
When you post your multiplayer applet, it must be hosted on a domain running the gaming engine server. There are two ways to do this. If you have access to running programs on the web server where you are posting (most don't have this administrative access), then simply run the gaming engine server fang.Server and leave it running indefinitely (it should run for months easily). If you are like most users, you don't have access to the web server hosting your applet, but you do have access to a computer with a static IP. In this case, you can run a web proxy on the computer with a static IP and also run the gaming engine server. There are details for setting this up at [[Posting#Running_Your_Game_as_a_Networked_Game]. With the web proxy set up, all you have to do is link to your game with the proxy replacing the original domain.
For example, I have a multiplayer game posted at http://www.cs.duke.edu/%7Ecjj1/professional/fang/games/instructor/pong/index.html Since I don't have access to running programs on the www.cs.duke.edu web server, I set up a proxy for www.cs.duke.edu at server.fangengine.org:8090. You'll notice that if you click on the link above, it won't be able to connect for 2 players. Instead if I link the same game as http://server.fangengine.org:8090/%7Ecjj1/professional/fang/games/instructor/pong/index.html it works because I do have access to server.fangengine.org and I am running a web proxy and gaming engine server on server.fangengine.org. If you are a student at Duke, I have set up a web proxy for
http://www.duke.edu at http://server.fangengine.org:8080
When linking to your multiplayer games, use the host server.fangengine.org:8080 instead of www.duke.edu. ===I tried posting as an executable jar, but when I click on it all that comes up is a bunch of numbers and strange characters.=== When you post your game as an executable jar, it depends on how the computer is set up whether it will display the raw jar file or use Java to run it. The most reliable way to post your game is as an applet. See Posting Your Game for instructions on how to post the game as an applet.
Game Engine questions
How do I know what methods and classes are in the gaming engine?
Visit the [API] documentation.
How do make a multiplayer game?
The gaming engine provide keyboards (getPlayer().getKeyboard()) and mice (getPlayer().getMouse()) for the computers involved in the networked game. These can be used to get input from each player. These arrays do not exist until the game starts and can only be accessed after the startGame method is called. Also, there is a random number generator provided (random) which must be used to generate all random numbers. Each individual game must respond in the same way to the same user input which is guaranteed to be consistent. In this way all the games in the multiplayer game can stay consistent. See [[How FANG works#The Details Behind the Networked Games |How FANG Works]] for a more thorough description of how multiplayer games work.
How do you run the game on multiple computers?
See Running Your Game as a Networked Game.
Why are the views in my multiplayer game inconsistent?
The most common reason for this is using a random number generator other than the one provided. If you want to use random numbers, you must use the provided generator in the GameLoop class called random.
Also, the game must be a function of only the user input directly on the canvas and nothing else. For example, it is not possible to pop up a dialog box during a multiplayer game because input would be given outside of the canvas (it would go in the dialog box instead). For more information on this, see Running Your Game as a Networked Game.
How do I add sound to my game?
Adding a sound to your game consists of 4 steps:
- Make the sound in the wav format and add it to the resources folder for your game. If your game is in the package mygame, then you would put the sound in the mygame.resources folder.
- Run the Sound program in the fang package. This will open up a dialog box where you can search for the audio file you just put in your resources folder. Select the audio file and click on Play Clip. If your sound does not play, then it is not in a format the FANG Engine can read. If it is in the wrong format, you will need to open up the audio clip in a sound editing tool such as Audacity and save it once again as wav format.
- Declare and initialize an instance variable of type Sound to your class which extends GameLoop or GameLevel. This line would look like Sound clip=new Sound("resources/yoursound.wav");
- Play the sound when you want it to occur. Add a line like clip.play(); Typically, you will want to play the sound when a particular event occurs. This usually means you will play the clip either in the advanceFrame method or in a method called from the advanceFrame method.
See the example AlarmBeep in the game examples page for a sample program which uses sound.
How do I add an image to my game?
You can use an ImageSprite to add an image. Follow these five steps.
- Put the image you want to in the resources folder for your game. If your game is in the package mygame, then you would put the image in the mygame.resources folder.===
- Declare an ImageSprite as in the line ImageSprite imageSprite;
- Initialize the ImageSprite as in the line imageSprite=new ImageSprite("resources/yoursound.wav");
- Set the scale and location of the image sprite as you would with any other sprite.
- Add the sprite to the canvas.
There is an example of this in the [[Games:Example:SpriteTest:Summary |SpriteTest example] in the game examples page. Simply uncomment the line which initializes the ImageSprite and comment out the other lines which initialize the different types of sprites. You should see a sidewalk with grass when you run the example.
How do I set the help file?
Make a simple html file and place it in your resources folder for your game. If your game is in the package mygame, then you would put the html file in the mygame.resources folder. In your startGame method or constructor call setHelp("resources/YourHelpFile.html");
- This page was last modified 18:59, 2 November 2007.
- This page has been accessed 812 times.
- Privacy policy
- About FANG
- Disclaimers
- Powered by MediaWiki!

