first commit
This commit is contained in:
93
CS1322/p6/MyWay2/CSprite.java
Normal file
93
CS1322/p6/MyWay2/CSprite.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CSprite.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 23, 2002
|
||||
* Created the CSprite class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CSprite {
|
||||
|
||||
/**
|
||||
*Holds image value(s)
|
||||
*/
|
||||
private ImageIcon[] imgSprite;
|
||||
|
||||
/**
|
||||
*Holds the baseName for the Image Sprite
|
||||
*(i.e. Imagename000.jpg, where 000 = animation number
|
||||
*/
|
||||
private String strImgName;
|
||||
|
||||
/**
|
||||
*Holds value for time (in fps) for animation delay
|
||||
*/
|
||||
private int iAnimDelay;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*@param imgName, the base name for the image file
|
||||
* ex:Street.jpg and Street000.jpg would both have imgName of Street
|
||||
* use / to represent a different folder
|
||||
*@param strExt, the extension for the file
|
||||
* Acceptable types: .jpg, .gif, .bmp
|
||||
*@param animCount, the number of animations
|
||||
* Acceptable values: 1 or higher
|
||||
*/
|
||||
public CSprite(String imgName, String strExt, int animCount){
|
||||
imgSprite = new ImageIcon[animCount];
|
||||
this.strImgName = imgName+strExt;
|
||||
|
||||
for(int i=0; i<animCount; i++){
|
||||
String strName;
|
||||
if(i<10){
|
||||
strName = imgName + "00" + i + strExt;
|
||||
}
|
||||
else if(i<100){//no need to recheck if i<10, already done that and
|
||||
//skipped else{}
|
||||
strName = imgName + "0" + i + strExt;
|
||||
}
|
||||
else{
|
||||
strName = imgName + strExt;
|
||||
}
|
||||
|
||||
try{
|
||||
imgSprite[i] = new ImageIcon(imgName);
|
||||
}
|
||||
catch(Exception e){
|
||||
imgSprite[i] = new ImageIcon("Error.gif");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAnimDelay(int c){
|
||||
iAnimDelay = c;
|
||||
}
|
||||
|
||||
public int getAnimDelay(){
|
||||
return iAnimDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CSprite.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class CSprite
|
||||
Reference in New Issue
Block a user