(04-30-2021 11:53 PM)star cash Wrote: (04-30-2021 11:47 PM)JoseskVolpe Wrote: (04-30-2021 11:44 PM)star cash Wrote: Drop link for the app use for creating java game with java phone
http://ultraplicativos.blogspot.com/2013...le_30.html
Where should i click to start creating game
First, don't forgot to set file write/read permissions to "Allowed" or "Ask one time"
Go to "New Project...", specify your Project's name and its Folder Location, and click create. This will create a new project. > Click "Create" Soft Button and Create.
Now you should create your first package. Go to Source Packages > Left/Right Soft Key (it depends on your phone) > New > Java Package > Create > Specify your package name with dots and everything lower case (for example: "game.starcash") > right/left soft and "Finish"
Open your new package > left/right shoft > New > Java MIDlet > Name it anything > then create
A code will apear:
Code:
package game.starcash;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Game extends MIDlet{
public void startApp(){
//When player opens or resume your game
}
public void pauseApp(){
//When player minimizes your game, or receives a call, or system pauses it
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
//When player closes your game
}
}
Now you need to create a displayable and invoke it, you can create a new Java file for it, but you can make it inside the same file in the same class
Add the following line:
Code:
import javax.microedition.lcdui.game.GameCanvas;
class GameEngine extends GameCanvas{
protected GameEngine(boolean suppressKeyEvents) {
super(suppressKeyEvents);
//when invoked by the Game class
}
public void paint(Graphics g){
//Use this to render your game
//You can also use this to update each frame, although it will use the same thread
repaint();
}
public void Update(){
//Use this to update each frawme
}
}
Your code will look like this:
Code:
package game.starcash;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Game extends MIDlet{
public void startApp(){
//When player opens or resume your game
}
public void pauseApp(){
//When player minimizes your game, or receives a call, or system pauses it
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
//When player closes your game
}
class GameEngine extends GameCanvas{
protected GameEngine(boolean suppressKeyEvents) {
super(suppressKeyEvents);
//when invoked by the Game class
}
public void paint(Graphics g){
//Use this to render your game
//You can also use this to update each frame, although it will use the same thread
repaint();
}
public void Update(){
//Use this to update each frame
}
}
}
Now you invoke wit into your startApp() class and begin it
Don't forget startApp() is also used when you're resuming it, so you need to store in a variable your app was already started
Code:
boolean gameStarted=false; //False for the first startApp()
public void startApp(){
if(!gameStarted){
//First start()
}
gameStarted=true;
}
And invoke your GameEngine
Code:
GameEngine engine;
public void startApp(){
//When player opens or resume your game
if(!gameStarted){
//First start()
engine = new GameEngine(false);
}
gameStarted=true;
Display.getDisplay(this).setCurrent(engine);
}
Your code will look like this:
Code:
package game.starcash;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
public class Game extends MIDlet{
boolean gameStarted=false; //False for the first startApp()
GameEngine engine;
public void startApp(){
//When player opens or resume your game
if(!gameStarted){
//First start()
engine = new GameEngine(false);
}
gameStarted=true;
Display.getDisplay(this).setCurrent(engine);
}
public void pauseApp(){
//When player minimizes your game, or receives a call, or system pauses it
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
//When player closes your game
}
class GameEngine extends GameCanvas{
protected GameEngine(boolean suppressKeyEvents) {
super(suppressKeyEvents);
//when invoked by the Game class
}
public void paint(Graphics g){
//Use this to render your game
//You can also use this to update each frame, although it will use the same thread
repaint();
}
public void Update(){
//Use this to update each frawme
}
}
}
You are almost there, now you need to create a new thread, or in a easier way for this example, create a loop for the Update() method into the GameEngine, running separated from the paint() Thread:
Code:
while(true) {
engine.Update();
}
You can also use Thread.sleep() for limiting the FPS, but Java phones are very slow in performance so you won't need it at all, only for emulators, wich has FPS Limit in their settings
Now this is your first Game Engine code:W
Code:
package game.starcash;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
public class Game extends MIDlet{
boolean gameStarted=false; //False for the first startApp()
GameEngine engine;
public void startApp(){
//When player opens or resume your game
if(!gameStarted){
//First start()
engine = new GameEngine(false);
}
gameStarted=true;
Display.getDisplay(this).setCurrent(engine);
while(true) {
engine.Update();
}
}
public void pauseApp(){
//When player minimizes your game, or receives a call, or system pauses it
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
//When player closes your game
}
class GameEngine extends GameCanvas{
protected GameEngine(boolean suppressKeyEvents) {
super(suppressKeyEvents);
//when invoked by the Game class
}
public void paint(Graphics g){
//Use this to render your game
//You can also use this to update each frame, although it will use the same thread
repaint();
}
public void Update(){
//Use this to update each frawme
}
}
}
Follow the comment instructions, and good work :3
You will see there'll be nothing dispaying on your game, or it'll be stuck in the loading time. It's because there's nothing for it to paint on the screen. Play with the g variable (Graphics class) on the paint() method and have fun