Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / J2ME / Re: Help: Unable to load image on: 2005-01-24 13:14:19
I finally got it to work, i don't know why or how this works, but i copied the splash.png file into every directory in the folder.
the classes, bin, lib src folders, all of them,  and now it works. I'm sure that i've put it into more folder than is nessicary, but i'll fix that through trial and error later.
but it works.

Or  be more correct it doesn't give me an IOException anymore.

on the downside it now displays an empty screen.... so the code is probably b0rked somewhere.

Arse.
2  Java Game APIs & Engines / J2ME / Re: Help: Unable to load image on: 2005-01-22 17:48:49
ok, i'm using Ktoolbar to build the game, then running it from the command line with midp -classpath . filename

[i don't have net access at home, so the RUN button just doesn't work]

I've built the Jad and .Jar files and the splash.png is included.

yet no matter where i place the image file [in the rec  or src folders, it matters not] i still get the IO Exception


For the sake of it, this is the Splash.java code i'm using

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
import javax.microedition.lcdui.*;

public class splash extends Canvas implements Runnable

{
   private boolean running = true;
   private Image osb;
   private Graphics osg;
   private Blockade theMidlet;
   private int starFieldViewY;
   private Image title;
   private int fontHeight;
   private Font font;
   private String filename;
   
   
   public splash(Blockade midlet)
   {
      theMidlet = midlet;
      initResources();

      // create the timer thread
     Thread t = new Thread(this);
      t.start();
   }

   private void initResources()
   {
      // setup the screen
     
      try
      {
      osb = Image.createImage(getWidth(), getHeight());
      osg = osb.getGraphics();

   
     
       filename =  "/splash.png";
     
       title = Image.createImage(filename);
     
      font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
      fontHeight = font.getHeight() + 2;

      osg.setFont(font);
          }
          catch(Exception e)
          {
             
          System.out.println("can't load file: " + filename + " why? ==> " + e);
         e.printStackTrace();  
          }
         
   }

   private static final int MAX_CPS = 100;
   private static final int MS_PER_FRAME = 1000 / MAX_CPS;

   public void run()
   {
      try
      {
         while (running)
         {
            // remember the starting time
           long cycleStartTime = System.currentTimeMillis();

            // do our work
           repaint();

            // sleep if we've finished our work early
           long timeSinceStart = (cycleStartTime - System.currentTimeMillis());
            if (timeSinceStart < MS_PER_FRAME)
            {
               try
               {
                  Thread.sleep(MS_PER_FRAME - timeSinceStart);
               }
               catch (java.lang.InterruptedException e)
               {
               }
            }
         }

         // fall back to the splash form at the end of our loop
        theMidlet.activateMenu();
      }
      catch (Exception e)
      {
         System.out.println("App exception2: " + e);
         e.printStackTrace();
      }

   }

   private void renderSplash()
   {
      // clear the background
     osg.setColor(0);
      osg.fillRect(0, 0, getWidth(), getHeight());

     

      osg.drawImage(title, getWidth() / 2, getHeight() / 2 - 10, Graphics.HCENTER | Graphics.VCENTER);

      // draw text
     osg.setColor(0x00888888);
      osg.drawString("© 2005", getWidth() / 2, getHeight() - fontHeight * 3,
                     Graphics.HCENTER | Graphics.TOP);
      osg.drawString(" Crontastic Production", getWidth() / 2, getHeight() - fontHeight * 2,
                     Graphics.HCENTER | Graphics.TOP);
      // draw the copy line
     osg.setColor(0x00ffffff);
      osg.drawString("Press Any Key", getWidth() / 2, getHeight() - fontHeight * 1,
                     Graphics.HCENTER | Graphics.TOP);
   }

   protected void paint(Graphics graphics)
   {
      renderSplash();
      graphics.drawImage(osb, 0, 0, Graphics.LEFT | Graphics.TOP);
   }

   protected void keyPressed(int keyCode)
   {
      running = false;
   }

   

}
3  Java Game APIs & Engines / J2ME / Help: Unable to load image on: 2005-01-21 15:48:59
i'm trying to add a splash screen to a small java game i wrote, and i'm using the following code to get the file

1  
image = Image.createImage ("/splash.png");



Now the file is located in the same directory as the source code, and isn't set to read-only or anything.

yet i get a IO exception when i try and run the midlet

it claims it cannot load the  image.
Am i missing file permissions for the image, or is it even in the right place?

Thanks in advance for your help


4  Java Game APIs & Engines / J2ME / Re: Help: Moving image leaving trail on-screen on: 2005-01-14 17:37:03
Thanks, that solved it.

i owe you, it's been driving me insane.
5  Java Game APIs & Engines / J2ME / Help: Moving image leaving trail on-screen on: 2005-01-12 11:29:47
I've just started to learn Java for mobile devices, and i've been playing around with simple MIDP1.0.3 games.

The problem is this, i have one square in the center of the screen, and on the X and Y axis i have targets.
By pressing the up, down, left, right keys  a small shot is fired in the corresponding direction.

these shots are colouered pixels of about 2 high by 2 wide.
when they are launched the game draws in their path [a straigth line along the appropriate axis] the game leaves in all the images it draws during it's movment.

So instead of having a shot fly up the screen, i have a trail leading to the top of the screen.

Deleting the object only removes the dot that remians on the end of the trail, not any of the ones that are before it.


These are the areas of code that i think have the errant instructions in them
[excuse the poor quality of the code, i'm still trying to get my head arouns Java and OO]


In GameScreen.java


//  
private Vector actorList;
    private Vector NactorList;
    private Vector SactorList;
    private Vector EactorList;
    private Vector WactorList;
    private Vector ShotList;

       
        protected void cycle()
              {

                if (lastCycleTime > 0)
        {
        msSinceLastCycle = System.currentTimeMillis() - lastCycleTime;

        // cycle all the actors
       
        // North actors
 
          // shot actors
          
          for (int i = 0; i < ShotList.size(); i++)
        {
           Actor a = (Actor) ShotList.elementAt(i);
         
Actor N = (Actor) NactorList.elementAt((NactorList.size() - 1));
           Actor S = (Actor) SactorList.elementAt((SactorList.size() - 1));
           Actor E = (Actor) EactorList.elementAt((EactorList.size() - 1));
           Actor W = (Actor) WactorList.elementAt((WactorList.size() - 1));
           
           
           System.out.println("*********[Cycle]*************");
           a.cycle((int)msSinceLastCycle);
                 System.out.println("*********[End cycle]*********");
           // check if any hit the oncomming cubes
           if ((N.isCollidingWith(a) && N != a) ||((S.isCollidingWith(a) && S != a))
           || (E.isCollidingWith(a) && E != a) ||(W.isCollidingWith(a) && W != a))
                 {
           // yar! it's a hit
             
           
           System.out.println("HIT!");

           // if so, remove the brick
           
          ShotList.removeElementAt(i);
            // remove the shot
             }
             
             
           System.out.println("ShotList.size() " + ShotList.size());
           
              }
              
              
          }
          
          
          
     }
     lastCycleTime = System.currentTimeMillis();      
                    
                    
                    
           }


In GameScreen.java

    private void renderWorld()
{   
     // this is called every cycle to paint the world
     // first to an offscreen buffer, then to the screen
     
       Graphics osg = offScreenBuffer.getGraphics();
   
       
        // there is very little to draw to begin with,
        // once we render the actors later then we'll be doing much more
       
        // so draw the score line
       
       osg.setColor(0, 0, 0);
     osg.fillRect(0, getHeight() - 10, getWidth(), getHeight());
     osg.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
     osg.setColor(0x00ffffff);
       
     
     osg.setColor(0x00ffffff);
     osg.drawString("CPS:  " + cps , 5, getHeight() - 10 + 1,
                    Graphics.LEFT | Graphics.TOP);
                   
                   
      for (int i=0; i < actorList.size(); i++)
     {
        Actor a = (Actor)actorList.elementAt(i);
        a.render(osg);
     }  
     
     
     // draw the 'attacking' blocks
                 
         for (int i=0; i < NactorList.size(); i++)
     {
        Actor a = (Actor)NactorList.elementAt(i);
        a.render(osg);
     }              
     
               
         for (int i=0; i < SactorList.size(); i++)
     {
        Actor a = (Actor)SactorList.elementAt(i);
        a.render(osg);
     }      
     
               
         for (int i=0; i < EactorList.size(); i++)
     {
        Actor a = (Actor)EactorList.elementAt(i);
        a.render(osg);
     }      
     
               
         for (int i=0; i < WactorList.size(); i++)
     {
        Actor a = (Actor)WactorList.elementAt(i);
       
        a.render(osg);
     }      
                   
     
     // render the shots
     
     
      for (int i=0; i < ShotList.size(); i++)
     {
       
           System.out.println("**************[Start Shots!]******************");
           Actor a = (Actor)ShotList.elementAt(i);
           a.render(osg);
         System.out.println("**************[End Shots!]******************");
    }
  }  




And finally in ShotActor.java


public void cycle(long deltaMS)
  {
     long ticks = (deltaMS + fluff) / 100;

     // remember the bit we missed
     fluff += (deltaMS - (ticks * 100));

     // move based on our speed in pixels per ticks
     if (ticks > 0)
     {
           
           int move = (int)(10 * ticks);
     switch(Direction)
           {
                   case 0:
                   System.out.println("Moving Down");
                 setY(move);
                 break;
                 case 1:
                 System.out.println("Moving up");
                 setY(move);
                 break;
                 case 2:
                 System.out.println("Moving Right");
                 setX(move);
                 break;
                 case 3:
                 System.out.println("Moving left");
                 setX(move);
                 break;
           }
        }  
       
    }
     




thanks in advance for any help i recieve.


1  
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (8 views)
2014-09-21 01:30:30

BurntPizza (9 views)
2014-09-21 00:34:41

moogie (10 views)
2014-09-21 00:26:15

UprightPath (23 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!