Hi'
Anybody know if its possible to animate an animated gif or multiple png's on the 40 series? If yes, how?
Thanks,
Dark16
Printable View
Hi'
Anybody know if its possible to animate an animated gif or multiple png's on the 40 series? If yes, how?
Thanks,
Dark16
Hi,
animated gifs are not supported, but you can animate a series of png images by a thread.
Kind regards,
Tinke / FN
How do i do that ? If i want to animate pic1.png, pic2.png and pic3.png ? Code please !
OK, here's some code from my OEngine :) This class is for sprites. One can use it like:
private OSprite mt;
mt = new OSprite( "/metak", 1, 2, 2, "metak" );
The first parameter is name of the picture in JAR (multiple pictures start from 0, so, if you have 3 pictures, you name it like "pic0.png", "pic1.png" and "pic2.png"), second parameter is number of frames (pictures), third is the width of pic, fourth height and last one is type of sprite (for example, you can have "good" and "bad" sprites, and you can check collision with them and add or substract points or energy).
You set next picture of sprite with mt.nextFrame(), previous with mt.prevFrame()... Comments are on Croatian, but method calls are self-explanatory :)
Stevica
/**
Klasa za spriteove, podrzava vise frameova
*/
class OSprite
{
//private
private int count;
private int width, height;
private int currentIndex;
private int x, y;
private Vector images = new Vector();
private int worldX, worldY;
/**energija*/
private int energy = 0;
/**Tip spritea, koristi se za razne usporedbe */
public String type = "";
/**Je li sprite vidljiv*/
public boolean visible = true;
//public
/**Vraca sirinu spritea*/
public int getWidth()
{
return this.width;
}
/**Vraca visinu spritea*/
public int getHeight()
{
return this.height;
}
/**Vraca broj frameova za animaciju*/
public int getCountFrames()
{
return this.count;
}
/**Vraca index trenutno aktivnog framea*/
public int getCurrentIndex()
{
return this.currentIndex;
}
/**Postavlja aktivan frame rednog broj index*/
public void setCurrentIndex( int index )
{
this.currentIndex = index;
}
/**Vraca x koordinatu na ekranu*/
public int getX()
{
return this.x;
}
/**Vraca Y koordinatu na ekranu*/
public int getY()
{
return this.y;
}
/**Postavlja x koordinatu na ekranu*/
public void setX( int x )
{
this.x = x;
}
/**Postavlja y koordinatu na ekranu*/
public void setY( int y )
{
this.y = y;
}
/**Vraca X koordinatu u <b>svijetu</b>*/
public int getWorldX()
{
return this.worldX;
}
/**Vraca Y koordinatu u <b>svijetu</b>*/
public int getWorldY()
{
return this.worldY;
}
/**Postavlja x koordinatu u <b>svijetu</b>*/
public void setWorldX( int x )
{
this.worldX = x;
}
/**Postavlja y koordinatu u <b>svijetu</b>*/
public void setWorldY( int y )
{
this.worldY = y;
}
/**Postavlja energiju na zadanu vrijednost*/
public void setEnergy( int e )
{
this.energy = e;
}
/**vraca vrijednost energije*/
public int getEnergy()
{
return this.energy;
}
/**Postavlja iduci frame aktivnim
Ako je iduci frame veci od getCountFrames(), postavlja na 0
*/
public void nextFrame()
{
this.currentIndex++;
if ( this.currentIndex == this.count ) {
this.currentIndex = 0;
}
}
/**Postavlja prethodni frame aktivnim
Ako je prethodni frame mani od 0, postavlja na getCountFrames() - 1
*/
public void prevFrame()
{
this.currentIndex--;
if ( this.currentIndex < 0 ) {
this.currentIndex = this.count - 1;
}
}
/**Iscrtava trenutno aktivan frame na ekransku poziciju getX(), getY()
*/
public void paint( Graphics g )
{
g.drawImage( (Image) this.images.elementAt( currentIndex ), this.getX(), this.getY(), 0 );
}
/**
Kao osnovu frameova uzima PNG slike. <i>imageName</i> je "/slika", dok stvarne slike
pocinju sa "/slika" + broj_framea ("/slika0", "/slika1", "/slika2"...).
<i>count</i> sluzi za odredjivanje broja frameova, <i>width</i> za sirinu,
<i>height</i> za visinu, a <i>tip</i> za tip spritea
*/
OSprite( String imageName, int count, int width, int height, String tip )
{
Image tmpImage;
int nI;
String tmpName = "";
this.count = count;
this.width = width;
this.height = height;
this.currentIndex = 0;
this.x = 0;
this.y = 0;
for ( nI = 0; nI < count; nI++ )
{
tmpName = imageName + Integer.toString( nI ) + ".png";
tmpImage = Image.createImage( width, height );
try
{
tmpImage = Image.createImage( tmpName );
} catch (IOException ioe ) {
}
this.images.addElement( tmpImage );
}
this.type = tip;
}
/**Provjerava sudar sa drugim spriteom
checkX i checkY su tocke <b>unutar</b> spritea
*/
public boolean checkCollision( OSprite other, int checkX, int checkY )
{
boolean res;
res = false;
if ( this.getX() + checkX >= other.getX() && this.getX() + checkX <= other.getX() + other.getWidth() &&
this.getY() + checkY >= other.getY() && this.getY() + checkY <= other.getY() + other.getHeight() )
{
res = true;
}
if ( !other.visible )
{
res = false;
}
return res;
}
}