Tu source koji me zajebava vec 15 dana ne mogu mu nista
Tiled Layer jednostavno odbija saradnju. (Sve se lepo kompajluje ali nece da vrati objekat Tiled Layer) ;(
da li ima neki doktor za ovu bolest ?
Code:
/*
verzija 5 sa Tiled Layerom
*/
/* import */
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
/*
verzija : 1.0
*/
public final class GameCanvas1 extends GameCanvas implements Runnable
{
private boolean isPlay;
private long delay;
private int currentX, currentY;
private int width;
private int height;
//TiledLayer
public TiledLayer tiledBackground;
// Slike
Image tileImage;
// Sprajtovi
// Layer manager
private LayerManager layerManager;
// Inicijalizacija konstruktora
//--------------------------------------------------------------------------------
public GameCanvas1() throws Exception
{
super(true);
width = getWidth();
height= getHeight();
delay = 20;
try
{
//tiledBackground = initBackground();
try
{
tileImage = Image.createImage("/Background.png");
}
catch(Exception e)
{
System.out.println("Problem sa kreiranjem slike");
System.out.println(e.toString()); // ok
}
try
{
tiledBackground = initBackground();
}
catch(Exception e)
{
System.out.println("Problem sa Tiled Layerom"); // tu je negde greska
System.out.println(e.toString());
}
} catch(Exception e)
{
System.out.println("Konstruktor ufatio gresku");
System.out.println(e.toString());
}
// Ucitavanje sprajtova
// podesavanje layer managera
layerManager = new LayerManager();
layerManager.append(tiledBackground);
}
//--------------------------------------------------------------------------------
// Automatski startuje nit za petlju igre
public void start()
{
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop()
{
isPlay = false;
}
//--------------------------------------------------------------------------------
// GLAVNA PETLJA
public void run()
{
Graphics g = getGraphics(); // klasa GameCanvas
while(isPlay== true)
{
input();
drawScene(g);
try
{
Thread.sleep(delay);
}
catch(InterruptedException ie)
{
System.out.println("run ufatio gresku");
}
// Metde za handle user input a
} // end while
} // end run
//--------------------------------------------------------------------------------
private void input()
{
// no input
} // end input
//--------------------------------------------------------------------------------
// Metode za prikaz grafike
private void drawScene(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(0x0000ff);
// prikaz spritova
// prikazati sve slojeve
layerManager.paint(g,0,0);
// PlayerSprite.paint(g);
flushGraphics();
}
//--------------------------------------------------------------------------------
private TiledLayer initBackground() throws Exception
{
Image tileImage = Image.createImage("/Background.png");
TiledLayer tiledLayer = new TiledLayer(10,10,tileImage,32,32);
int map[] = {
5,1,1,4,1,1,1,1,1,6,
5,1,3,1,1,3,1,1,1,6,
5,1,2,1,1,2,1,1,1,6,
5,1,2,3,1,2,1,1,1,6,
5,1,4,2,1,2,1,1,1,6,
5,1,1,4,1,2,1,1,1,6,
5,1,1,1,1,4,1,1,1,6,
5,1,1,1,1,1,1,1,1,6,
5,1,1,1,1,1,1,1,1,6,
5,1,1,1,1,1,1,1,1,6
};
//--------------------------------------------------------------------------------
for(int i=0; i< map.length;i++)
{
int col = i%10;
int row = (i-col)/10;
tiledLayer.setCell(col,row,map[i]);
}
return tiledLayer;
}
//--------------------------------------------------------------------------------
} // kraj za klasu
/*
verzija 5 sa Tiled Layerom
*/
/* import */
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
/*
verzija : 1.0
*/
public final class GameCanvas1 extends GameCanvas implements Runnable
{
private boolean isPlay;
private long delay;
private int currentX, currentY;
private int width;
private int height;
//TiledLayer
public TiledLayer tiledBackground;
// Slike
Image tileImage;
// Sprajtovi
// Layer manager
private LayerManager layerManager;
// Inicijalizacija konstruktora
//--------------------------------------------------------------------------------
public GameCanvas1() throws Exception
{
super(true);
width = getWidth();
height= getHeight();
delay = 20;
try
{
//tiledBackground = initBackground();
try
{
tileImage = Image.createImage("/Background.png");
}
catch(Exception e)
{
System.out.println("Problem sa kreiranjem slike");
System.out.println(e.toString()); // ok
}
try
{
tiledBackground = initBackground();
}
catch(Exception e)
{
System.out.println("Problem sa Tiled Layerom"); // tu je negde greska
System.out.println(e.toString());
}
} catch(Exception e)
{
System.out.println("Konstruktor ufatio gresku");
System.out.println(e.toString());
}
// Ucitavanje sprajtova
// podesavanje layer managera
layerManager = new LayerManager();
layerManager.append(tiledBackground);
}
//--------------------------------------------------------------------------------
// Automatski startuje nit za petlju igre
public void start()
{
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop()
{
isPlay = false;
}
//--------------------------------------------------------------------------------
// GLAVNA PETLJA
public void run()
{
Graphics g = getGraphics(); // klasa GameCanvas
while(isPlay== true)
{
input();
drawScene(g);
try
{
Thread.sleep(delay);
}
catch(InterruptedException ie)
{
System.out.println("run ufatio gresku");
}
// Metde za handle user input a
} // end while
} // end run
//--------------------------------------------------------------------------------
private void input()
{
// no input
} // end input
//--------------------------------------------------------------------------------
// Metode za prikaz grafike
private void drawScene(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(0x0000ff);
// prikaz spritova
// prikazati sve slojeve
layerManager.paint(g,0,0);
// PlayerSprite.paint(g);
flushGraphics();
}
//--------------------------------------------------------------------------------
private TiledLayer initBackground() throws Exception
{
Image tileImage = Image.createImage("/Background.png");
TiledLayer tiledLayer = new TiledLayer(10,10,tileImage,32,32);
int map[] = {
5,1,1,4,1,1,1,1,1,6,
5,1,3,1,1,3,1,1,1,6,
5,1,2,1,1,2,1,1,1,6,
5,1,2,3,1,2,1,1,1,6,
5,1,4,2,1,2,1,1,1,6,
5,1,1,4,1,2,1,1,1,6,
5,1,1,1,1,4,1,1,1,6,
5,1,1,1,1,1,1,1,1,6,
5,1,1,1,1,1,1,1,1,6,
5,1,1,1,1,1,1,1,1,6
};
//--------------------------------------------------------------------------------
for(int i=0; i< map.length;i++)
{
int col = i%10;
int row = (i-col)/10;
tiledLayer.setCell(col,row,map[i]);
}
return tiledLayer;
}
//--------------------------------------------------------------------------------
} // kraj za klasu
i glavni midlet
Code:
/*
Game5 No animated Tiled Layer
*/
/* import */
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
/*
verzija : 1.0
*/
public class Game5MIDlet extends MIDlet
{
private Display display;
public Display getDisplay()
{
return display;
}
public void startApp()
{
try
{
display = Display.getDisplay(this);
GameCanvas1 gc1 = new GameCanvas1();
gc1.start();
display.setCurrent(gc1);
} catch( Exception e)
{
System.out.println(e);
System.out.println("Game5MIDlet uhvatio gresku");
}
}
public void pauseApp()
{
}
public void destroyApp(boolean unc)
{
exit();
}
public void exit()
{
System.gc();
destroyApp(false);
notifyDestroyed();
}
}
/*
Game5 No animated Tiled Layer
*/
/* import */
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
/*
verzija : 1.0
*/
public class Game5MIDlet extends MIDlet
{
private Display display;
public Display getDisplay()
{
return display;
}
public void startApp()
{
try
{
display = Display.getDisplay(this);
GameCanvas1 gc1 = new GameCanvas1();
gc1.start();
display.setCurrent(gc1);
} catch( Exception e)
{
System.out.println(e);
System.out.println("Game5MIDlet uhvatio gresku");
}
}
public void pauseApp()
{
}
public void destroyApp(boolean unc)
{
exit();
}
public void exit()
{
System.gc();
destroyApp(false);
notifyDestroyed();
}
}
i naravno postoji slika dimenzija 32x196 u direktorijumu res
Unapred hvala na strpljenju
Tape loading error