From FANG
|
01 packagepackage is used to name the directory or folder a class is in examples.sprites;
02 //start auto-imports
03 //end auto-imports
04
05 importimport means to make the classes and/or packages available in this program fang2.core.*;
06 importimport means to make the classes and/or packages available in this program fang2.sprites.*;
07 importimport means to make the classes and/or packages available in this program fang2.transformers.*;
08 importimport means to make the classes and/or packages available in this program fang2.attributes.*;
09 importimport means to make the classes and/or packages available in this program java.awt.*;
10 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
11
12 /**
13 * This shows a bunch of tanks on a screen.
14 * @authorthis is the Javadoc tag for documenting who created the source code Alan Davis
15 */
16
17 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects CustomStringSprite extendsextends means to customize or extend the functionality of a class Game
18 {open braces start code blocks and must be matched with a close brace
19 /**
20
21 **/
22 StringSprite tank;
23
24 /**sets up the game*/
25 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
26 {open braces start code blocks and must be matched with a close brace
27 /**This is the StringSprite initiation.
28 ***I put several letters in to show that it is possible
29 *** because we are playing with fonts. Think Wingdings.
30 **/
31 tank =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite( "A B C D\n" +adds two numbers together or concatenates Strings together
32 "E F G H\n" +adds two numbers together or concatenates Strings together
33 "I J K L\n" +adds two numbers together or concatenates Strings together
34 "M N O P" );
35
36 /**Sets the font to be no more than 80%this divides the left side by the right side and evaluates to the remainder of the screen size.
37 **/
38 tank.setSize( 0.8 );
39
40 /**Puts the Sprite in the middle of the screen*/
41 tank.setLocation( 0.5, 0.5 );
42
43 /**This is what you need to change your regular font to a newnew is used to create objects by calling the constructor one.
44 ***It finds your file in the resource folder with the name you gave the font.
45 **/
46 tank.setFontFamilyName( "Tank" );
47
48 /**Dont forget to add your sprite to the game.
49 **/
50 addSprite( tank );
51 }close braces end code blocks and must match an earlier open brace
52
53 /**handle input and game events*/
54 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
55 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
56 }close braces end code blocks and must match an earlier open brace
|
Download/View examples/sprites/CustomStringSprite.java//start auto-imports
//end auto-imports
import fang2.core.*;
import fang2.sprites.*;
import fang2.transformers.*;
import fang2.attributes.*;
import java.awt.*;
import java.awt.geom.*;
/**
* This shows a bunch of tanks on a screen.
* @author Alan Davis
*/
public class CustomStringSprite extends Game
{
/**
**/
StringSprite tank;
/**sets up the game*/
public void setup()
{
/**This is the StringSprite initiation.
***I put several letters in to show that it is possible
*** because we are playing with fonts. Think Wingdings.
**/
tank = new StringSprite( "A B C D\n" +
"E F G H\n" +
"I J K L\n" +
"M N O P" );
/**Sets the font to be no more than 80% of the screen size.
**/
tank.setSize( 0.8 );
/**Puts the Sprite in the middle of the screen*/
tank.setLocation( 0.5, 0.5 );
/**This is what you need to change your regular font to a new one.
***It finds your file in the resource folder with the name you gave the font.
**/
tank.setFontFamilyName( "Tank" );
/**Dont forget to add your sprite to the game.
**/
addSprite( tank );
}
/**handle input and game events*/
public void advance()
{}
}