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 is an example of a RectangleSprite.
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 RectangleSpriteExample 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 /**Here we declare our sprite named rectangle. You can declare a RectangleSprite,
20 ***but Sprite is the classclass is a group of fields and methods used for making objects that the RectangleSprite is derived from
21 **/
22 Sprite rect;
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 /**Here, we instantiate the rectangle and give it a width and height*/
28 rect =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite( .1, .2 );
29 /**Here, the location in screens is set.
30 ***This means we are putting the Rectangle at half the screen's width and height
31 **/
32 rect.setLocation( 0.5, 0.5 );
33 /**Here is where we add our sprite to the screen*/
34 addSprite( rect );
35 }close braces end code blocks and must match an earlier open brace
36
37 }close braces end code blocks and must match an earlier open brace
|
Download/View examples/sprites/RectangleSpriteExample.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 is an example of a RectangleSprite.
* @author Alan Davis
*/
public class ARectangle extends Game
{
/**Here we declare our sprite named rectangle. You can declare a RectangleSprite,
***but Sprite is the class that the RectangleSprite is derived from
**/
Sprite rect;
/**sets up the game*/
public void setup()
{
/**Here, we instantiate the rectangle and give it a width and height*/
rect = new RectangleSprite( .1, .2 );
/**Here, the location in screens is set.
***This means we are putting the Rectangle at half the screen's width and height
**/
rect.setLocation( 0.5, 0.5 );
/**Here is where we add our sprite to the screen*/
addSprite( rect );
}
}