Java-Gaming.org Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (169)
games submitted by our members
Games in WIP (647)
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] 2 3 ... 6
1  Game Development / Newbie & Debugging Questions / Re: LibGDX Center player on tile half the size.. on: 2015-05-21 00:43:55
I use free movement. I think there is a better way to do it. Right now it basically adds player speed to x or y depending on key pressed. Then to get the tile x,y, of course I just divide by tilesize. I figured out why it wasn't centering but I'm still trying to improve my movement.

I appreciate the attempt pocket but all that would do is draw the sprite without centering it or doing anything to it at all.
2  Game Development / Newbie & Debugging Questions / Re: LibGDX Center player on tile half the size.. on: 2015-05-19 22:11:49
I don't that really explained my problem..I know how to center it in the tile..I think the problem is my movement system is flawed.
3  Game Development / Newbie & Debugging Questions / LibGDX Center player on tile half the size.. on: 2015-05-19 19:50:11
I refactored my tiled game to use 32x32 tiles instead of 16x16 tiles as I am using the LPC assets for tiles and sprites..The sprite characters are gridded out into 64x64 cells for animation....The player is a bit smaller...

Anyways, i've got the grid system set up and i've got a square highlighting the cell...But no matter what I do, I can't get the player to center into the tile...

Here is my simplified render call..

1  
batch.draw(downRegion, playerX - (playerWidth / 2 / 32f), playerY,playerWidth/32f, playerHeight/32f);   


Whereas, playerWidth and playerHeight = 64;

Here is what I get...

4  Game Development / Newbie & Debugging Questions / Re: LibGDX World units and width and height.. on: 2015-05-12 17:35:33
Yeah, not too bad I guess. Now just to figure out the movement system. The character moves around but freely. The plan is to center my sprite and make the base occupy one tile and use that to move...then it shouldn't be too hard for collision detection.
5  Game Development / Newbie & Debugging Questions / Re: LibGDX World units and width and height.. on: 2015-05-12 04:17:58
Yeah, I wrote that quickly while I was playing around with the texture regions and forgot. Already fixed.

I also just divided the width and height by tile size, but do I need to do that to everything? Or is there a better way?
6  Game Development / Newbie & Debugging Questions / LibGDX World units and width and height.. on: 2015-05-11 00:46:04
I've got a tiledmap rendered and i'm rendering the player sprite over it...When I call my player.draw() it draws a texture region of the player specifying x,y,width,height....which is good, it's rendering the correct place and moving around on the tiles...But the width and height are incorrect...My tiles are 16x16 and my player sprite is 24x32...so i'm getting a really blown up player sprite...How can I fix this?

This is my gamescreen class:
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  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
package com.psillicoder.farmGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;

public class gameScreen implements Screen {

   gameClass game;
   
   
   
   private OrthographicCamera camera;
   private OrthogonalTiledMapRenderer renderer;
   private TiledMap map;
   private PlayerClass player;
   
   
   SpriteBatch batch;
   SpriteBatch guibatch;
   
   BitmapFont font;
   
   
   float unitScale = 1/16f;
   int tileSize = 16;
   
   
   
    public gameScreen(gameClass game) {
       this.game = game;
       
     
    }
   
    @Override
    public void render(float delta) {
       
       Gdx.gl.glClearColor(0, 0, 0, 1);
         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
         
     
         //camera.position.x = player.getPos().x - (Gdx.graphics.getWidth() / 2);
         //camera.position.y = player.getPos().y - (Gdx.graphics.getHeight() / 2);
         
         camera.position.x = player.getPos().x;
         camera.position.y = player.getPos().y;
         
         camera.update();
         
         
         batch.setProjectionMatrix(camera.combined);
         
         renderer.setView(camera);
         renderer.render();
         
         
         
         batch.begin();
         player.render(batch);  
         batch.end();
         
         guibatch.begin();
         font.draw(guibatch, "FPS: " + Gdx.graphics.getFramesPerSecond() , 10, Gdx.graphics.getHeight() - 10);
         font.draw(guibatch, "Player X: " + player.getPos().x + " | Player Y: " + player.getPos().y , 10, Gdx.graphics.getHeight() - 20);
         guibatch.end();

      processInput();
     
       
    }
   
    @Override
    public void resize(int width, int height) {
       
    }
   
    @Override
    public void show() {
       
       map = new TmxMapLoader().load("tdmap1.tmx");
       
       renderer = new OrthogonalTiledMapRenderer(map,unitScale);
     
       
       font = new BitmapFont();
       
       camera = new OrthographicCamera();
       
       camera.setToOrtho(false,40,40);
       renderer.setView(camera);
       camera.update();
       
       
       
       batch = new SpriteBatch();
       guibatch = new SpriteBatch();
       player = new PlayerClass(30, 30);
         
    }
   
   
   
    public void processInput() {
       if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) player.setPos((int)player.getPos().x - player.getSpeed(),(int)player.getPos().y);
       
       if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) player.setPos((int)player.getPos().x + player.getSpeed(),(int)player.getPos().y);
       
       if (Gdx.input.isKeyPressed(Input.Keys.UP)) player.setPos((int)player.getPos().x,(int)player.getPos().y + player.getSpeed());
       
       if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) player.setPos((int)player.getPos().x,(int)player.getPos().y - player.getSpeed());
       
    }
   
    @Override
    public void hide() {
      dispose();
    }
   
    @Override
    public void pause() {
       
    }
   
    @Override
    public void resume() {
       
    }
   
    @Override
    public void dispose() {
       System.out.println("Disposed");
       batch.dispose();
       renderer.dispose();
       map.dispose();
       player.dispose();
       font.dispose();
    }
}


and my player class render method:
1  
2  
3  
4  
5  
6  
   public void render(SpriteBatch batch) {
     
      batch.draw(downRegion, playerX, playerY);
   
   }
   



Also, i'm confused as how camera.setToOrtho works. I'm using 40 as width and height and it seems to work okay...From what I understand, this is how many tiles I want to show on the screen?
7  Game Development / Newbie & Debugging Questions / Re: Libgdx TiledMapRenderer on: 2015-05-08 03:28:28
Okay I think my question is, how do I set my player up to move on my level coordinates instead of screen coordinates? I know libgdx does this for you by setting the unit scale..but when I call the players render function is only drawing in screen coordinates.. I'm confused about how and what libgdx does for you. I want to use lwjgl but I just don't think I'm experienced enough and I like having the sprite batch and stuff set up for me...I don't use libgdx's stage or actors or anything like that.
8  Game Development / Newbie & Debugging Questions / Libgdx TiledMapRenderer on: 2015-05-06 21:06:45
So I'm trying to get this whole level system down and I'm a bit confused.  The tiledmaprenderer does most of the work for me,  but I still need to set up my grid system and figure out my player movement... I know I can call each tile by using Cell but it doesn't seem to work the way I need it to.. My levels are 100x100..I want to be able to reference each tile by using the xy coordinates like 24,65, etc.  But I also need the player to be positioned on those coordinates...the player is 24x32 (which I may change this anyway)

I'm having a hard time figuring out how to use the level coordinates with the player and having them in unison... If this makes sense..

I'll elaborate more when I get off work,  sorry if it doesn't make sense... Just thinking about it during my downtime at work.
9  Game Development / Newbie & Debugging Questions / Re: Having trouble with the screen class.. on: 2015-04-29 03:17:38
........

Wow, i'm an idiot haha. I don't know how I missed that. I knew it was something dumb. I appreciate it! I guess I need to brush up on everything.
10  Game Development / Newbie & Debugging Questions / Re: Having trouble with the screen class.. on: 2015-04-29 03:08:22
Ah..I see what you're saying..I forgot more than I thought...so I should be passing the objects through to the render class? That doesn't seem right...It could get pretty lengthy.
11  Game Development / Newbie & Debugging Questions / Having trouble with the screen class.. on: 2015-04-29 02:39:50
I'm just getting back into this after a long break so bare with me...Basically, i'm making a 2d tiled game and having a big issue off gate...I'm implementing Screens with libgdx and basically, I immediately set it to the gamescreen and render tiles...I'm getting a NPE on my camera and my renderer in the render method...I think it's calling the render class before calling create() where the objects are created...I made a post over at stack exchange with the code:

http://gamedev.stackexchange.com/questions/99182/java-libgdx-game-screens-and-rendering-tile-map


I know it's gotta be something simple that i'm just missing..I just can't find it.
12  Game Development / Newbie & Debugging Questions / Re: Tower Defense pathfinding? on: 2014-11-23 22:32:12
Yeah, there is some good stuff on there! Thanks.

I'm rewriting this now to use tiled instead..It's too hard to manage in the array...My question is, how do I set up a grid to use a* with tiled? I tried this before and was unsuccessful. That's part of the reason, I decided to do it from scratch as I would already have a grid..I know it's something simple, but I don't see it.
13  Game Development / Newbie & Debugging Questions / Re: Tower Defense pathfinding? on: 2014-11-23 21:48:26
That is awesome! Thank you Gibbo. A simple search probably would have found that for me! I didn't think about searching for tower defense specifics.

I agree, CC. I just needed some reassurance!

I just hope I can stick with this without getting bored. I'm only developing it for the experience, but I need to finish something completely so I can move forward to the games I have been planning for months.
14  Game Development / Newbie & Debugging Questions / Re: Tower Defense pathfinding? on: 2014-11-23 21:00:12
That's what I'm going for. Just trying to figure out the best way to calculate the pathfinding..there aren't many obstacles and it's just from A to B, so I feel like a* might be too much..

This is the first time I've ever done any type of pathfinding.
15  Game Development / Newbie & Debugging Questions / Re: Tower Defense pathfinding? on: 2014-11-23 20:47:18
What do you mean? Who does?
16  Game Development / Newbie & Debugging Questions / Tower Defense pathfinding? on: 2014-11-23 19:57:37
Hey guys, i'm working on a small tower defense game using LibGDX. I'm probably going to put an android port on the play store.

So, the game is coming along pretty nicely so far. I'm just trying to figure out the best pathfinding method...I was thinking of using A* but I think that may be a little much for what I need...

I started the project using a multidimensional array for the map, but i'm now thinking of switching to using tiled so it is easier to manage larger maps..I don't know if there is another way to do it using tiled, I do know I was having trouble using the A* method with tiled...

Basically, the enemies will follow a path from A to B...I could define waypoints, but it seems like there could be an issue with enemies running into each other, etc.

Any suggestions or tips?
17  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-14 04:13:47
I see. I think I know what's going on. It's with my camera.
18  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-14 04:04:33
Change the
new Vector2(y, x)
to
new Vector2(x, y)
but leave everything else as-is.

..You're awesome. So why does the iterator need to be reversed but not the rest? Is it the order in which it iterates?

Should I be disposing of the tempTile somehow before I start on the next iteration? I changed one of the bottom lines to another color and it's making the whole line that tile..It doesn't make sense. I've gone through the code.
19  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-14 03:55:11
I switched them around in my tile class like so:
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  
private void loadLevel() {
   int[][] levelData = new int[][] {
         {0,0,0,0,1,0,0,0,0,0},
         {0,0,0,0,1,0,0,0,0,0},
         {3,3,3,3,1,3,3,3,3,3},
         {0,0,0,0,1,0,0,0,0,0},
         {0,0,0,0,1,0,0,0,0,0},
         {0,0,0,0,2,1,0,0,0,0},
         {0,0,0,0,0,1,0,0,0,0},
         {0,0,0,0,0,1,0,0,0,0},
         {0,0,0,0,0,1,0,0,0,0},
         {0,0,0,0,0,1,0,0,0,0}
   };
   
   
     
   
   for (int y = 0; y < 9; y++) {
      for (int x = 0; x < 9; x++) {
         Tile tempTile = new Tile(levelData[y][x],new Vector2(y,x));
         tileList.add(tempTile);
         
         
      }
}



}

public void Render(SpriteBatch batch) {
   
   for (int i = 0; i < tileList.size(); i++) {
      tileList.get(i).render(batch);
   }
}


But in my tile class where I actually draw them, it calls for x and y so I left them..Do I use y for everywhere x is referred and vice versa?

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  
   public void render(SpriteBatch batch) {
      if (tileType == 0) {
         batch.draw(new TextureRegion(tileTexture, 0, 0, 16, 16), tilePos.x,
               tilePos.y);

      } else {
         if (tileType == 1) {
            batch.draw(new TextureRegion(tileTexture, 0, 16, 16, 16),
                  tilePos.x, tilePos.y);

         } else {

            if (tileType == 2) {
               batch.draw(new TextureRegion(tileTexture, 16, 0, 16, 16),
                     tilePos.x, tilePos.y);

            } else {

               if (tileType == 3) {
                  batch.draw(new TextureRegion(tileTexture, 16, 16, 16,
                        16), tilePos.x, tilePos.y);
               }
            }
         }
      }
   }
20  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-14 03:48:05
Okay..I got it working but it's drawing everything rotated 90 degrees counter clockwise..
21  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-14 03:14:22
I've not even used hashmaps yet. Need to learn them next.
22  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-12 19:24:38
I like using x and y as it is what i'm used to from scripting on another game. It works well. Ive used tiled and its simple for maps. Its too much for what I need on this game though and id like to learn what it's doing. I need the experience. I think ive figured out a good way to do this. When i get home, im going to continue working on it. Im hoping to be able to stay with it longer.

Ive got a much bigger project that i want to do but i am nowhere near ready...so im just trying to learn everything i can.
23  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-12 03:23:10
Ah, I see. I could have googled that, I apologize for the dumb questions! Just a bitch to do when it's running so slow. I'm not closing it or doing anything. It stops when it has the NPE error.
24  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-12 03:03:34
That makes sense..Can't believe I missed that. so I need to do something like

List<Tile> tileList = new List();
This doesn't seem to work..do I really need the <Tile>?

On a completely unrelated note...What would cause the compiler to run like complete shit after i've ran the game a couple times...It runs perfectly fine when I first start it up but as soon as i've run the game two or three times, it freezes up every time I do anything. Just moving the cursor around takes a few seconds. I think that's a big part of my problem. It is extremely frustrating to debug like this.
25  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-12 02:51:17
Definitely somebody I was hoping to hear from!

I haven't really started into any of the advanced stuff yet though..That's what i'm saying. I've made a couple small games like pong, breakout, and pacman...I shouldn't be having these issues still..I don't open eclipse for a couple months, and when I get started back in, I feel like I know less than I did..If that makes sense.

It's the little things that get me...for example, I rewrote that using a List and i'm getting a null pointer exception when I add the tile to the list...which I set the title in the line directly above it, so it's not null...

1  
2  
3  
4  
   for (int x = 0; x < 9; x++) {
      for (int y = 0; y < 9; y++) {
         Tile tempTile = new Tile(levelData[x][y],new Vector2(x,y));
         tileList.add(tempTile);
26  Game Development / Newbie & Debugging Questions / 2D Array with ArrayList for map on: 2014-11-12 02:07:42
So, here I am again..Feeling like a newbie. It's been a while since i've coded anything and i'm trying to get back into it again...so i'm making a tower defense game. I'm just playing around right now with the map.

Basically, i've got a Level class and a Tile class. The tile class just holds the tile information like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class Tile {

   private int tileType;
   private boolean walkable;
   private Vector2 tilePos;
   public Tile(int type, Vector2 pos) {
      tileType = type;
      tilePos = new Vector2(pos);
   }
   
   
public Vector2 getPos() {
   return tilePos;
}
   
public boolean isWalkable() {
   return walkable;
}


In my Level class, i've got a 2d array which determines which tile is where:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
private void loadLevel(int width,int height) {
   int[][] levelData = new int[][] {
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0}
   };
   


Simple...So what i'm trying to figure out, is how to actually keep track of the tiles if that makes sense. I'm going to put my render method in the level class and will iterate through the level to draw the maps...I was going to use a for loop and add each tile to an arraylist, then iterate through the arraylist in my render method to draw each tile in the correct place and the correct tile...But, I remember reading that an arraylist would be a bad way to do this and it just doesn't seem like a good way...

I feel like i've taken one step forward and 10 back every time I take a break from java. I should be way more advanced than I am for as long as I have been messing around with java. Any suggestions or information would be greatly appreciated. I do well for a while, then get stuck and take a break, come back and am in the situation I am in now. Very frustrating...
27  Games Center / WIP games, tools & toy projects / Re: RPG Project on: 2014-09-12 02:50:37
Looks good. I'm doing a similar style game with a different style of play. I'm still learning though. I'm curious as to why so many packages. I've been trying to figure out how to organize everything a little better, but what are the benefits to doing it that way? Do you just import the packages you need into every class?

So far, every little game i've done has only had one package. I'm trying to figure out my next step in learning. I've made a few small games and read through my java books. I am getting ready to start reading up on entity systems so I can work on my 2d orthogonal tile-based game. I think i'm ready and work for a bit, then realize I need to read up on other methods. I've gotten a basic game that loads a map and has a player walking around but just doesn't seem organized and gets a little overwhelming to get any further.

Sorry for rambling. I don't mean to try to hijack the thread lol. To the OP, the game looks great so far!
28  Games Center / Featured Games / Re: [Slick2d] Retro-Pixel Castles > Now on Steam! < on: 2014-07-14 00:03:25
Sorry if you've already answered this but I didn't go through all the pages. What do you use for your graphics? I've been having problems finding what I need and I don't know any artists. I'm going to attempt to make my own. Also, does anybody know of any decent websites to find artists?
29  Game Development / Newbie & Debugging Questions / Re: wtf? eclipse and libgdx problem... on: 2014-07-08 18:59:09
30  Game Development / Newbie & Debugging Questions / Re: wtf? eclipse and libgdx problem... on: 2014-07-08 18:54:01
Yes.
Pages: [1] 2 3 ... 6
 
KaiHH (11 views)
2015-07-07 10:18:40

deepthought (54 views)
2015-06-30 15:39:44

deepthought (57 views)
2015-06-30 15:39:09

deepthought (65 views)
2015-06-30 15:36:52

Za\'Anzabar (44 views)
2015-06-29 05:44:54

TritonDreyja (50 views)
2015-06-24 17:10:40

CopyableCougar4 (52 views)
2015-06-23 00:34:45

BurntPizza (58 views)
2015-06-21 20:36:46

cookiecompiler (99 views)
2015-06-11 15:42:53

cookiecompiler (58 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!