Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4 5 ... 10
 21 
 on: 2014-09-30 11:29:51 
Started by Yemto - Last post by Roquen
First note that these two are not equivalent.  The try version will do everything until any failure where the if version only does something if no failure will occur.  What I'd suggest is neither and disallow getImage to ever return null.

 22 
 on: 2014-09-30 11:29:42 
Started by matanui159 - Last post by opiop65
Don't create separate topics. Use the same one.

 23 
 on: 2014-09-30 11:28:55 
Started by matanui159 - Last post by matanui159
I have an idea of how to fix it but sadly I'm going away tomorrow...
You will have to wait till next week (i might put it in a fresh topic)...

 24 
 on: 2014-09-30 11:28:33 
Started by Yemto - Last post by Mike
The if statements all the way. If the first two elements aren't null and the third one is you will have wasted the time it takes to call the two render methods and you may get render artifacts in the result.

Also, entering try clauses is quick, catching exceptions is slow Smiley

Mike

 25 
 on: 2014-09-30 10:37:30 
Started by Yemto - Last post by Yemto
This isn't really a problem I have, more of a question of what's considered good practice. I recently realized that I can catch NullPointerExceptions, instead of using a if statement. So far I have only used it in places where I expect to not need and if statement, but I wonder is it right? and if not, when should I catch NullPointerException instead of using if's?

There is one place where I used it like this
1  
2  
3  
4  
5  
6  
7  
8  
try{
    renderComponent[RENDER_BG].getImage().render(g2, x, y+7);
    renderComponent[RENDER_NAME].getImage().render(g2, x+5, y);
    renderComponent[RENDER_DATE].getImage().render(g2, 30+(textBreakWidth*1), y);
    renderComponent[RENDER_TIME].getImage().render(g2, (textBreakWidth*2)-renderComponent[RENDER_TIME].getImage().getWidth()+20, y);
}catch(java.lang.NullPointerException e){
    showingAnimation = false;
}


instead of
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
if(     renderComponent[RENDER_BG].getImage() != null &&
        renderComponent[RENDER_NAME].getImage() != null &&
        renderComponent[RENDER_DATE].getImage() != null &&
        renderComponent[RENDER_TIME].getImage() != null){
    renderComponent[RENDER_BG].getImage().render(g2, x, y+7);
    renderComponent[RENDER_NAME].getImage().render(g2, x+5, y);
    renderComponent[RENDER_DATE].getImage().render(g2, 30+(textBreakWidth*1), y);
    renderComponent[RENDER_TIME].getImage().render(g2, (textBreakWidth*2)-renderComponent[RENDER_TIME].getImage().getWidth()+20, y);
}else{
    showingAnimation = false;
}


In situations like that I feel like the try statement is much more useful than a if, it also makes the code a lot more readable.

 26 
 on: 2014-09-30 10:29:44 
Started by jakethesnake - Last post by jakethesnake
Ok, just wanted to spare you this big chunk of code. This isn't just the minimap. The minimap is just a variable of  my actual tileMap. Feel free to point out any errors.

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  
132  
package model;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import controller.MinimapWindow;
import controller.SettlementWindow;
import data.ActiveSettlementSettings;
import data.GlobalConstants;

class ActiveMap {

   private Tile tiles[][];
   private Image tileImages[];
   private Image minimapImage;
   
   private final int WIDTH;
   private final int HEIGHT;
   private final int TILE_SIZE;
   
   ActiveMap(ActiveSettlementSettings settings, GlobalConstants gc) {
     
      WIDTH = settings.MAP_TILE_WIDTH();
      HEIGHT = settings.MAP_TILE_HEIGHT();
      TILE_SIZE = gc.GAME_SCALE()*gc.TILE_SIZE();
      tiles = new Tile[WIDTH][HEIGHT];
     
      try {
         tileImages = new Image[4];
         tileImages[0] = new Image("res/model/tiles/Sdirt1.png", false, Image.FILTER_NEAREST);
         tileImages[1] = new Image("res/model/tiles/Sdirt2.png", false, Image.FILTER_NEAREST);
         tileImages[2] = new Image("res/model/tiles/Sdirt3.png", false, Image.FILTER_NEAREST);
         tileImages[3] = new Image(32,32);
         
         minimapImage = new Image(WIDTH, HEIGHT);

      } catch (SlickException e) {
         // TODO Auto-generated catch block
        e.printStackTrace();
      }
     
      //generates a random map
     for (int y = 0; y < tiles.length; y++){
         for (int x = 0; x < tiles[0].length; x++){
            tiles[y][x] = new Tile ((short) ((Math.random()*3) ));
            }
         }
     
      tiles[15][15].setType((short)3);
      tiles[15][16].setType((short)3);
      tiles[15][17].setType((short)3);
     
      tiles[50][50].setType((short)3);
      tiles[50][51].setType((short)3);
      tiles[50][52].setType((short)3);
      tiles[51][50].setType((short)3);
      tiles[52][50].setType((short)3);
      tiles[53][50].setType((short)3);
     
      tiles[500][500].setType((short)3);
      tiles[500][501].setType((short)3);
      tiles[500][502].setType((short)3);
      tiles[501][500].setType((short)3);
      tiles[502][501].setType((short)3);
      tiles[503][502].setType((short)3);
     
      //paints the minimap image
     try {
         Graphics g = minimapImage.getGraphics();
         for (int y = 0; y < HEIGHT; y++){
            for (int x = 0; x < WIDTH; x++){
               switch (tiles[y][x].getType()){
               case 0: g.setColor(Color.pink); g.fillRect(x,y,1,1);
                  break;
               case 1: g.setColor(Color.gray); g.fillRect(x,y,1,1);
                  break;
               case 2: g.setColor(Color.yellow); g.fillRect(x,y,1,1);
                  break;
               default:g.setColor(Color.black); g.fillRect(x,y,1,1);
               }
            }
         }
         g.flush();
         g.destroy();
      } catch (SlickException e) {
         // TODO Auto-generated catch block
        e.printStackTrace();
      }
     
   }

   void update(){
     
   }
   
   void render (SettlementWindow window){
     
      short tempType;
     
      int tileJump = (int) (TILE_SIZE*window.getZoom());
      int firstDrawX = (int) (window.getFrameX1() - (window.getX1()%TILE_SIZE)*window.getZoom());
      int firstDrawY = (int) (window.getFrameY1() - (window.getY1()%TILE_SIZE)*window.getZoom());
     
      int firstTileX = (int) Math.ceil(window.getX1()/TILE_SIZE);
      int firstTileY = (int) Math.ceil(window.getY1()/TILE_SIZE);
     
      int tilesToDrawX = (int) Math.ceil(((window.getFrameX2()-window.getFrameX1())-firstDrawX)/tileJump);
      int tilesToDrawY = (int) Math.ceil(((window.getFrameY2()-window.getFrameY1())-firstDrawY)/tileJump);
     
      //preparations
     
      for (int y = 0; y <= tilesToDrawY; y++){
         for (int x = 0; x <= tilesToDrawX; x++){
            tempType = tiles[firstTileY + y][firstTileX + x].getType();
            tileImages[tempType].draw(firstDrawX + x*tileJump, firstDrawY + y*tileJump, tileJump, tileJump);

         }
      }
     
     
   }
   
   void renderMini (MinimapWindow window){
      minimapImage.startUse();
      minimapImage.drawEmbedded(window.getFrameX1(), window.getFrameY1(), window.getFrameX2(), window.getFrameY2(),
            window.getX1(), window.getY1(), window.getX2(), window.getY2());
      minimapImage.endUse();
   }
   
}

 27 
 on: 2014-09-30 09:42:39 
Started by rickytuga - Last post by rickytuga
Hey guys I'm trying to come up with something like this:



or




Preferably the very last one as I want it as smooth as possible, now I've done some research and apparently  the way to go about doing this is with batch.draw(Texture, Float[] vertices ... ), problem is I've no idea how to use it or if this really is the best method.

Could anyone give me a hand and just show me a small example ( snippet of code) of how it could be done, I just want it to randomise and make it seem like mountains on the ground. Thank you Smiley

 28 
 on: 2014-09-30 09:35:41 
Started by monsterbrain - Last post by richierich
Good-looking from the screenshot - I'll try it if you get an Android, iPad or desktop version ready. monsterbraingames.com isn't responding right now. I can't find it in the app store, although there are other games, "Spell it Right", "Spell it Forwards" and "Spell it Quiz" so maybe your name could do with a bit of differentiation Cheesy

Also in a spelling game make sure to get your own spelling and grammar right throughout or it'll have no credibility. E.g. "Newton" should be capitalized, and "Better World with Lesser Misspells" may (nearly) rhyme but has .... some issues Tongue

Looking forward to playing it anyway!

 29 
 on: 2014-09-30 09:32:23 
Started by matanui159 - Last post by kappa
Gets further in the start up process but fails with the following error now:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
java -jar faster.jar

java.io.FileNotFoundException: img\icon\i
con.png (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at rg.utils.ImageUtils.loadImage(ImageUtils.java:56)
        at rg.core.World.setIcon(World.java:220)
        at Main.main(Main.java:21)
java.io.FileNotFoundException: img\icon\icon-large.png (The system cannot find t
he path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at rg.utils.ImageUtils.loadImage(ImageUtils.java:56)
        at rg.core.World.setIcon(World.java:222)
        at Main.main(Main.java:21)
Exception in thread "main" java.lang.NullPointerException
        at rg.utils.ImageUtils.resizeImage(ImageUtils.java:73)
        at rg.core.World.setIcon(World.java:227)
        at Main.main(Main.java:21)

 30 
 on: 2014-09-30 08:49:45 
Started by pakito - Last post by pakito
I'm trying to work on a screen with an  options button. Currently my code works perfect on desktop but on my mobile device, when I touched the options button, it did changes color but doesn't switch to the next screen. I found out that the real triggering point is at the bottom left of the screen which I've no idea why. Hope someone could shed some light here. Thanks.



This is my current code:

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  
public class GameScreen implements Screen {

   public GameScreen( ) {
      screenWidth = Gdx.graphics.getWidth();
      screenHeight = Gdx.graphics.getHeight();
     
      cam = new OrthographicCamera();
      cam.setToOrtho(false, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
   }


@Override
   public void show() {
      stage = new Stage( );
      Gdx.input.setInputProcessor(stage);

      TextureAtlas buttons = new TextureAtlas( Gdx.files.internal("data/milk.txt") );
      Skin skin = new Skin( buttons );
     
      ImageButtonStyle btnStyle = new ImageButtonStyle();
      btnStyle.up = skin.getDrawable( "optionsBtn");
      btnStyle.down = skin.getDrawable( "optionsBtn");
     
      ImageButton button = new ImageButton(btnStyle);
      button.setBounds( ZBGame.VIRTUAL_WIDTH/2-(121/2), ZBGame.VIRTUAL_HEIGHT/2-100,
                   button.getWidth(), button.getHeight());

      button.addListener(new ClickListener( ) {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
               game.setScreen(new OptionScreen( game ) );
               return true;
            }
         });
        }


@Override
   public void render(float delta) {
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     
      if( Gdx.input.justTouched( ) ) {
         Vector3 touchPos = new Vector3();
         touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
         ZBGame.cam.unproject(touchPos);
         
         Actor actor = stage.hit( touchPos.x, touchPos.y, true );

         if( actor != null ) {
            // change the button color
           // Its working on mobile device when touch but not changing screen.
           actor.setColor((float)Math.random(), (float)Math.random(),
                        (float)Math.random(), 0.5f+0.5f*(float)Math.random());
         }
      }
     
      stage.act(delta);
      stage.draw();
   }
}

Pages: 1 2 [3] 4 5 ... 10
 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

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

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

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

BurntPizza (52 views)
2014-09-19 03:14:18
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!