Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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
  ignore  |  Print  
  [KindaSolved]Is box2D really neccessary ?  (Read 2552 times)
0 Members and 1 Guest are viewing this topic.
Offline Andre Lopes
« Posted 2013-06-02 14:13:42 »

Im having a hard time with box2d, seriously, i was able to draw balls on the screen and made them crash at the ground and rebounce.

I took out the camera thing to see if it improved, well, it did.
Now 0,0 is really 0,0

But if i draw my grass blocks on the screen, that i made with box2d Editor the balls get really small, i mean, VERY VERY small.


Before that, i had a normal class with the camera optimized like in the example, and the grass sprites simple fly over the screen or doesnt show up. It gets all bugged.
Though, the balls go down, rebounce and down again, its preety cool and fun and funny.
But i wanted to replace some ground with the grassBlocks, like this :



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  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
package grassproject;

import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
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.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import java.util.Random;

/**
 *
 * @author André Vinícius Lopes
 */

public class App extends ApplicationAdapter {

    private static final float VIEWPORT_WIDTH = 15;
    private OrthographicCamera camera;
    private float w;
    private float h;
    //
   private World world;
    //Ball
   private Sprite[] ballSprites;
    private Texture ballTexture;
    private int MAX_BALLS = 20;
    private Body[] ballModels;
    private static final float BALL_RADIUS = 0.15f;
    private Sprite grassSprite;
    private Texture grassTexture;
    //Ground ::
   private Sprite groundSprite;
    private Texture groundTexture;
    // Render general
   private SpriteBatch batch;
    private final Random rand = new Random();
    private final TweenManager tweenManager = new TweenManager();
    private Body grassModel;
    private float GRASS_WIDTH = 512;
    private Vector2 grassModelOrigin;

    @Override
    public void create() {
        w = Gdx.graphics.getWidth();
        h = Gdx.graphics.getHeight();
        //
       world = new World(new Vector2(0, -10), true);
        batch = new SpriteBatch();

        //
       camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_WIDTH * h / w);
        camera.position.set(0, camera.viewportHeight/2, 0);
        camera.update();

        createSprites();
        createBalls();
        createGround();

    }

    private void createSprites() {
        ballTexture = new Texture(Gdx.files.internal("imagens/ball.png"));
        ballTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

        ballSprites = new Sprite[MAX_BALLS];
        for (int i = 0; i < MAX_BALLS; i++) {
            ballSprites[i] = new Sprite(ballTexture);
            ballSprites[i].setSize(BALL_RADIUS * 2, BALL_RADIUS * 2);
            ballSprites[i].setOrigin(BALL_RADIUS, BALL_RADIUS);
        }

        grassTexture = new Texture(Gdx.files.internal("imagens/grassSmall.png"));
        createGrass();
        grassSprite = new Sprite(grassTexture);
       

        groundTexture = new Texture(Gdx.files.internal("imagens/white.png"));
        groundSprite = new Sprite(groundTexture);
        groundSprite.setSize(VIEWPORT_WIDTH, 1);
        groundSprite.setPosition(-VIEWPORT_WIDTH / 2, 0);
        groundSprite.setColor(Color.GREEN);

    }

    private void createGrass() {
        BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("GrassProject"));

        // 1. Create a BodyDef, as usual.
       BodyDef bd = new BodyDef();
        bd.position.set(10,10);
        bd.type = BodyDef.BodyType.StaticBody;

       
        // 2. Create a FixtureDef, as usual.
       FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.5f;
        fd.restitution = 0.3f;

       
        // 3. Create a Body, as usual.
       grassModel = world.createBody(bd);

       
        // 4. Create the body fixture automatically by using the loader.
       loader.attachFixture(grassModel, "grass02", fd, 1);
        grassModelOrigin = loader.getOrigin("grass02", 1).cpy();

    }

    private void createBalls() {
        BodyDef ballBodyDef = new BodyDef();
        ballBodyDef.type = BodyDef.BodyType.DynamicBody;
        //ballBodyDef.position.x = getRandom();
       //ballBodyDef.position.y = 15;

        CircleShape shape = new CircleShape();
        shape.setRadius(BALL_RADIUS);

        FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.4f;
        fd.restitution = 0.5f;
        fd.shape = shape;

        ballModels = new Body[MAX_BALLS];

        Vector2 vec = new Vector2();

        for (int i = 0; i < MAX_BALLS; i++) {
            ballModels[i] = world.createBody(ballBodyDef);
            ballModels[i].createFixture(fd);

            float tx = rand.nextFloat() * 1.0f - 0.5f;
            float ty = camera.position.y + camera.viewportHeight / 2 + BALL_RADIUS;
            float angle = rand.nextFloat() * MathUtils.PI * 2;
            ballModels[i].setLinearVelocity(vec.set(0, 0));
            ballModels[i].setAngularVelocity(0);
            ballModels[i].setTransform(vec.set(tx, ty), angle);
            ballModels[i].setBullet(true);
            ballModels[i].setActive(true);
        }



        shape.dispose();
    }

    private void createGround() {
        BodyDef bd = new BodyDef();
        bd.position.set(0,0);
        bd.type = BodyDef.BodyType.StaticBody;

        PolygonShape shape = new PolygonShape();
        shape.setAsBox(VIEWPORT_WIDTH, 1);

        FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.8f;
        fd.restitution = 1f;
        fd.shape = shape;

        world.createBody(bd).createFixture(fd);

        shape.dispose();
    }

    @Override
    public void render() {
        GL10 gl = Gdx.gl10;
        gl.glClearColor(1, 1, 1, 1);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        w = Gdx.graphics.getWidth();
        h = Gdx.graphics.getHeight();

        tweenManager.update(1 / 60f);
        world.step(1 / 60f, 10, 10);


        Vector2 grassPos = grassModel.getPosition().sub(grassModelOrigin);
        grassSprite.setPosition(grassPos.x, grassPos.y);
        grassSprite.setOrigin(grassModelOrigin.x, grassModelOrigin.y);



        for (int i = 0; i < MAX_BALLS; i++) {
            Vector2 ballPos = ballModels[i].getPosition();
            ballSprites[i].setPosition(ballPos.x - ballSprites[i].getWidth() / 2, ballPos.y - ballSprites[i].getHeight() / 2);
            ballSprites[i].setRotation(ballModels[i].getAngle() * MathUtils.radiansToDegrees);
            if (i == 0) {
                System.out.println(ballPos.x + " ; " + ballPos.y);
            }
        }

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        groundSprite.draw(batch);
        grassSprite.draw(batch);
        for (int i = 0; i < MAX_BALLS; i++) {
            ballSprites[i].draw(batch);
        }
        batch.flush();
        batch.end();


    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
    }
}
Offline Andre Lopes
« Reply #1 - Posted 2013-06-02 14:46:15 »

I really fail

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  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
package grassproject;

import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import java.util.Random;

/**
 *
 * @author André Vinícius Lopes
 */

public class DrawGrass implements ApplicationListener {

    private World world;
    private static final float VIEWPORT_WIDTH = 10;
    private OrthographicCamera camera;
    private float w, h;
    private Sprite grassSprite;
    private Texture grassTexture;
    private TweenManager tweenManager;
    private Body grassModel;
    private float GRASS_WIDTH = 256;
    private Vector2 grassModelOrigin;
    private SpriteBatch batch;
    //Ball
   private Sprite[] ballSprites;
    private Texture ballTexture;
    private int MAX_BALLS = 20;
    private Body[] ballModels;
    private static final float BALL_RADIUS = 0.15f;
    private final Random rand = new Random();

    @Override
    public void create() {
        w = Gdx.graphics.getWidth();
        h = Gdx.graphics.getHeight();
        //
       world = new World(new Vector2(0, -10), true);
        batch = new SpriteBatch();

        camera = new OrthographicCamera();
     
        tweenManager = new TweenManager();
        grassTexture = new Texture(Gdx.files.internal("imagens/grassSmall.png"));
        grassSprite = new Sprite(grassTexture);

        BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("GrassProject"));

       
        // 1. Create a BodyDef, as usual.
       BodyDef bd = new BodyDef();
        bd.position.set(0, 0);
        bd.type = BodyDef.BodyType.StaticBody;


        // 2. Create a FixtureDef, as usual.
       FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.5f;
        fd.restitution = 0.3f;


        // 3. Create a Body, as usual.
       grassModel = world.createBody(bd);


        // 4. Create the body fixture automatically by using the loader.
       loader.attachFixture(grassModel,"grass02", fd, GRASS_WIDTH);
        grassModelOrigin = loader.getOrigin("grass02",GRASS_WIDTH).cpy();
        createGround();

        ///BALLS
       
        createBalls();
        ballTexture = new Texture(Gdx.files.internal("imagens/ball.png"));
        ballTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

        ballSprites = new Sprite[MAX_BALLS];
        for (int i = 0; i < MAX_BALLS; i++) {
            ballSprites[i] = new Sprite(ballTexture);
            ballSprites[i].setSize(BALL_RADIUS * 2, BALL_RADIUS * 2);
            ballSprites[i].setOrigin(BALL_RADIUS, BALL_RADIUS);
        }

       


    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void render() {
        GL10 gl = Gdx.gl10;
        gl.glClearColor(1, 1, 1, 1);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        w = Gdx.graphics.getWidth();
        h = Gdx.graphics.getHeight();

        tweenManager.update(1 / 60f);
        world.step(1 / 60f, 10, 10);

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
       
        grassSprite.draw(batch);
       
        for (int i = 0; i < MAX_BALLS; i++) {
            Vector2 ballPos = ballModels[i].getPosition();
            ballSprites[i].setPosition(ballPos.x - ballSprites[i].getWidth() / 2, ballPos.y - ballSprites[i].getHeight() / 2);
            ballSprites[i].setRotation(ballModels[i].getAngle() * MathUtils.radiansToDegrees);
           ballSprites[i].draw(batch);
        }

        batch.flush();
        batch.end();


    }

    private void createBalls() {
        BodyDef ballBodyDef = new BodyDef();
        ballBodyDef.type = BodyDef.BodyType.DynamicBody;
        ballBodyDef.position.x = 200;
        ballBodyDef.position.y = 100;

        CircleShape shape = new CircleShape();
        shape.setRadius(BALL_RADIUS);

        FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.4f;
        fd.restitution = 0.5f;
        fd.shape = shape;

        ballModels = new Body[MAX_BALLS];

        Vector2 vec = new Vector2();

        for (int i = 0; i < MAX_BALLS; i++) {
            ballModels[i] = world.createBody(ballBodyDef);
            ballModels[i].createFixture(fd);

            float tx = rand.nextFloat() * 1.0f - 0.5f;
            float ty = camera.position.y + camera.viewportHeight / 2 + BALL_RADIUS;
           
            float angle = rand.nextFloat() * MathUtils.PI * 2;
            ballModels[i].setLinearVelocity(vec.set(0, 0));
            ballModels[i].setAngularVelocity(0);
            ballModels[i].setTransform(vec.set(tx, ty), angle);
            ballModels[i].setBullet(true);
            ballModels[i].setActive(true);
        }
    }

    private void createGround() {
        BodyDef bd = new BodyDef();
        bd.position.set(0, 0);
        bd.type = BodyDef.BodyType.StaticBody;

        PolygonShape shape = new PolygonShape();
        shape.setAsBox(VIEWPORT_WIDTH,1);

        FixtureDef fd = new FixtureDef();
        fd.density = 1;
        fd.friction = 0.8f;
        fd.restitution = 1f;
        fd.shape = shape;

        world.createBody(bd).createFixture(fd);

        shape.dispose();
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
    }
}


Heres a picture of whats happening :
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-06-02 14:49:41 »

Ok, it's getting to the point of where you're asking WAY too many questions. Slow down, take your time, read the tutorials and reread them, and fix the problem by yourself. Your 21 topics started are almost all about something that we told you about in a previous question - I recommend atlases, you start posting 3 topics on atlases, someone starts you on box2d, you post 2+ topics on box2d. Not all your problems are going to be solved in a day or less, and to be successful in the industry, you have to be more independent. I'm getting the feeling that 99% of your code is either copied from tutorial/example code, or stuff that we're giving you, which isn't right.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andre Lopes
« Reply #3 - Posted 2013-06-02 14:52:49 »


Im sorry, i will try to research more.
Offline Andre Lopes
« Reply #4 - Posted 2013-06-02 15:07:20 »

Ok, it's getting to the point of where you're asking WAY too many questions. Slow down, take your time, read the tutorials and reread them, and fix the problem by yourself. Your 21 topics started are almost all about something that we told you about in a previous question - I recommend atlases, you start posting 3 topics on atlases, someone starts you on box2d, you post 2+ topics on box2d. Not all your problems are going to be solved in a day or less, and to be successful in the industry, you have to be more independent. I'm getting the feeling that 99% of your code is either copied from tutorial/example code, or stuff that we're giving you, which isn't right.


Jimmt, is this tutorial any good?
http://sierakowski.eu/list-of-tips/114-box2d-basics-part-1.html

Is C++ i think, but i know a little of C++, Probably will give me an idea of whats actually happening.

I mean, box2D of libgdx = any box2D, right ?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2013-06-02 15:12:15 »

Any c++ box2d tutorials are pretty much good for libgdx's version. JBox2D, maybe not. But yeah, iforce2d, etc are pretty much all the same.
Offline davedes
« Reply #6 - Posted 2013-06-02 15:14:01 »

You won't really get that far if you just keep following tutorials for specific purposes and copying their code. Most of these assume prior programming knowledge.

Start small. Don't use box2d physics until you have a firm grip of Java and LibGDX concepts, and can debug on your own.

Programming requires a lot of debugging and solving problems on your own. If you can't be arsed, maybe another tool like Game Maker would be better suited for you. Cheesy

Offline Andre Lopes
« Reply #7 - Posted 2013-06-02 15:20:11 »

You won't really get that far if you just keep following tutorials for specific purposes and copying their code. Most of these assume prior programming knowledge.

Start small. Don't use box2d physics until you have a firm grip of Java and LibGDX concepts, and can debug on your own.

Programming requires a lot of debugging and solving problems on your own. If you can't be arsed, maybe another tool like Game Maker would be better suited for you. Cheesy

hey, i will make it.
Im just kinda lost, its all new to me, except java.
I have a need for tutorials to explain to me whats happening in the code, not just copying. Im trying to learn what each object does, and whats the logic the guy is using.

And no, game maker , no. seriously, no,thats like the biggest insult ever Cheesy  , dont be rude!!! xD
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #8 - Posted 2013-06-02 15:25:20 »

Not an insult, but good advice - if you don't want to/can't debug - like your recent posts seem to show, then Game Maker would be better.
Offline Cero
« Reply #9 - Posted 2013-06-02 15:36:36 »

Also: Only use a physics engine if you really it much of it.
In most cases hacking some physics stuff in is enough.
If your game primarily relies on physics go for it. If not, then not.

There many primarily casual games which focus on "lets look at physics - and maybe play with it", like angry birds. Then you will want it.
If not, then there is no reason.

Do no treat box2D as a default goto solution to simple physics problems.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andre Lopes
« Reply #10 - Posted 2013-06-02 16:27:09 »

Also: Only use a physics engine if you really it much of it.
In most cases hacking some physics stuff in is enough.
If your game primarily relies on physics go for it. If not, then not.

There many primarily casual games which focus on "lets look at physics - and maybe play with it", like angry birds. Then you will want it.
If not, then there is no reason.

Do no treat box2D as a default goto solution to simple physics problems.

Oh ok, then i can make a 2D game , like sonic without box2D ?
Because i dont feel ready for it.
Offline Andre Lopes
« Reply #11 - Posted 2013-06-02 16:27:43 »

Not an insult, but good advice - if you don't want to/can't debug - like your recent posts seem to show, then Game Maker would be better.

I like to debug, its just somewhat confusing.I am learning.
Offline Cero
« Reply #12 - Posted 2013-06-02 17:32:10 »

sonic without box2D ?

Absolutely.
Box2D would be way way more than you need in Sonic.
We are creating a Metroid/Castlevania type game - its all improvised physics.

Offline Andre Lopes
« Reply #13 - Posted 2013-06-02 18:12:24 »

sonic without box2D ?

Absolutely.
Box2D would be way way more than you need in Sonic.
We are creating a Metroid/Castlevania type game - its all improvised physics.

Hm, i am thinking how will i be able to draw the map and check the collisions, because, when its about checking collisions with rectangles is ok.But Its a whole Sprite of the level is way different, because i will have a whole giant rectangle.
So i had the idea of making a txt with positions of each tile, and draw them and treat each one separately.

Like, i could have a txt like this :

[TXT}

grass.png

x = 0 ; y = 0
x = 5 ; y = 0
x = 10 ; y = 0

}TXT}

Supposing the grass.png is 5 in width;

Is that a good approach ?
Offline Cero
« Reply #14 - Posted 2013-06-02 18:39:29 »

cannot follow you completely, but in a tilemap every tile is a rectangle, there are exceptions like slopes, but either a tile is filled or not.
and since everything is a rectangle you can collision check them.

how you check with objects/players/sprites/entities depends on what kinda of collision boundaries they have.
the main approaches are: one big rectangle, one rectangle which is a little smaller than the whole image, multiple rectangles as many as you need and you can also use polygons - its of course possible to use polygon collision without box2D

performance wise: only check rectangle/tiles in the vicinity and it is possible with a static map to combine rectangles I guess

Offline Andre Lopes
« Reply #15 - Posted 2013-06-02 20:48:26 »

cannot follow you completely, but in a tilemap every tile is a rectangle, there are exceptions like slopes, but either a tile is filled or not.
and since everything is a rectangle you can collision check them.

how you check with objects/players/sprites/entities depends on what kinda of collision boundaries they have.
the main approaches are: one big rectangle, one rectangle which is a little smaller than the whole image, multiple rectangles as many as you need and you can also use polygons - its of course possible to use polygon collision without box2D

performance wise: only check rectangle/tiles in the vicinity and it is possible with a static map to combine rectangles I guess

Oh, if i make like, a tmx file, like the wiki tutorial describes, will i be able to do that?
I will, wont i? So i actually never really needed box2D.

Because as far as im researching, tmx just tells where to draw the tile, and thats what i need.
Then i can load the sprite with the atlas, like in the tutorial, and make the collision test Cheesy

Something like that, right ?

Offline relminator
« Reply #16 - Posted 2013-06-03 02:00:01 »

Patience is a virtue.  Learn one thing at a time.  You're burning yourself out.
Offline Cero
« Reply #17 - Posted 2013-06-04 12:22:05 »

I have never used tmx/Tiled before, so I can't say.
But I'm 99.9% sure that it doesn't need box2D is any way.

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #18 - Posted 2013-06-04 17:39:46 »

It doesn't "need" box2d in be sense that you can definitely load and render a map without it. However, box2d makes it significantly easier to do collision if you assign collision boundaries to each tile - article and code here: http://dpk.net/2011/05/01/libgdx-box2d-tiled-maps-full-working-example-part-1/
>Uses the deprecated tiled map package but it shouldn't be a problem.
Offline Andre Lopes
« Reply #19 - Posted 2013-06-04 18:37:06 »

It doesn't "need" box2d in be sense that you can definitely load and render a map without it. However, box2d makes it significantly easier to do collision if you assign collision boundaries to each tile - article and code here: http://dpk.net/2011/05/01/libgdx-box2d-tiled-maps-full-working-example-part-1/
>Uses the deprecated tiled map package but it shouldn't be a problem.

It kinda is.

Well, anyway, im now stalled at this :
http://www.java-gaming.org/topics/tmx-x-y-doesnt-match-libgdx-x-y-how-to-already-tried-several/29794/view.html

Would you give me any tip Cheesy Huh
preety plx
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #20 - Posted 2013-06-04 19:38:10 »

The main thing is being able to map box2d bodies to tiles. If you can't implement code without copy+pasting the entire thing you've got bigger problems.
Offline Andre Lopes
« Reply #21 - Posted 2013-06-04 20:45:47 »

The main thing is being able to map box2d bodies to tiles. If you can't implement code without copy+pasting the entire thing you've got bigger problems.

Ok, i will give up and use Game Maker or maybe go play Tibia.
Is more suitable for my lack of intelligence, since its just 2 years since i actually started programming.

But you are way better than me, and way more intelligent in any aspect of life, also, i should make myself your slave and do anything you ask.
Not only that, but figuring code by yourself in your first game should be like, something common. Copying a while, or a for, is so stupid, ppl should figure the while/for by themselves not actually be teached in courses.

Anything else?
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #22 - Posted 2013-06-04 20:51:15 »

The main thing is being able to map box2d bodies to tiles. If you can't implement code without copy+pasting the entire thing you've got bigger problems.

Ok, i will give up and use Game Maker or maybe go play Tibia.
Is more suitable for my lack of intelligence, since its just 2 years since i actually started programming.

But you are way better than me, and way more intelligent in any aspect of life, also, i should make myself your slave and do anything you ask.
Not only that, but figuring code by yourself in your first game should be like, something common. Copying a while, or a for, is so stupid, ppl should figure the while/for by themselves not actually be teached in courses.

Anything else?


Hey, don't quit on yourself so easily.
Quote
Put up in a place
where it's easy to see
the cryptic admonishment
T.T.T.

When you feel how depressingly
slowly you climb,
it's well to remember that
Things Take Time.
I only started programming less than a year ago and I have come a long way. Most people here remember when I used to post so much things about silly questions I could have answered myself if I gave it more time.  If your going to give up so easily, programing won't work for you. These things are often not easy...

Offline Andre Lopes
« Reply #23 - Posted 2013-06-04 20:54:30 »

The main thing is being able to map box2d bodies to tiles. If you can't implement code without copy+pasting the entire thing you've got bigger problems.

Ok, i will give up and use Game Maker or maybe go play Tibia.
Is more suitable for my lack of intelligence, since its just 2 years since i actually started programming.

But you are way better than me, and way more intelligent in any aspect of life, also, i should make myself your slave and do anything you ask.
Not only that, but figuring code by yourself in your first game should be like, something common. Copying a while, or a for, is so stupid, ppl should figure the while/for by themselves not actually be teached in courses.

Anything else?


Hey, don't quit on yourself so easily.
Quote
Put up in a place
where it's easy to see
the cryptic admonishment
T.T.T.

When you feel how depressingly
slowly you climb,
it's well to remember that
Things Take Time.
I only started programming less than a year ago and I have come a long way. Most people here remember when I used to post so much things about silly questions I could have answered myself if I gave it more time.  If your going to give up so easily, programing won't work for you. These things are often not easy...

Oh sorry, i was ironic.
I wont give up. Never, ever.

Even if i have to pay someone to teach me.
Then i will make free youtube videos teaching ppl and become GOD.

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #24 - Posted 2013-06-05 05:15:08 »

A good programmer is an independent programmer.

Debug AND find the solution yourself.
Google is your friend.

And if still doesn't work, strip it back to the bare minimum and get it to work on a simple scale before implementing it properly.

Edit: Sometimes I think it's best to ignore sarcasm and take whatever someone says as what they really mean. In that case:

@Andre Lopes - Go use Gamemaker then. Whether you think you're stupid, or think you're smart, you are always right. In which case maybe Gamemaker is too advanced.

(Also, for future reference, copy-pasting is BAD. If you don't understand something, you shouldn't be using it for that purpose until you do. If you don't understand anything about making a game, go back to Hello World and work your way up from there.)

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #25 - Posted 2013-06-05 05:24:29 »

I'll agree that wreed has come a long way, you can too. Just ignore the urge to post every question you have just because it frustrates you (I have the opposite problem, I hate asking questions, so I spend a lot of time on bugs that are easily solved sometimes).
Offline Andre Lopes
« Reply #26 - Posted 2013-06-05 12:14:51 »

A good programmer is an independent programmer.

Debug AND find the solution yourself.
Google is your friend.

And if still doesn't work, strip it back to the bare minimum and get it to work on a simple scale before implementing it properly.

Edit: Sometimes I think it's best to ignore sarcasm and take whatever someone says as what they really mean. In that case:

@Andre Lopes - Go use Gamemaker then. Whether you think you're stupid, or think you're smart, you are always right. In which case maybe Gamemaker is too advanced.

(Also, for future reference, copy-pasting is BAD. If you don't understand something, you shouldn't be using it for that purpose until you do. If you don't understand anything about making a game, go back to Hello World and work your way up from there.)

Dont rage please. Its annoying.

Also, the topic is already solved.Wreed has helped me already.
And yes, you probably are a big company game dev, so i totally should take your comment seriously.

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #27 - Posted 2013-06-05 12:38:40 »

And yes, you probably are a big company game dev, so i totally should take your comment seriously.

Heh. Made me giggle Cheesy

No, he's not. But regardless of whether someone is a company dev or not, in my opinion experience and passion says much more about the 'skill' of a person/programmer.

I know back when wreed asked lots of simple programming questions. Now he helped you. Really cool stuff.
Keep evolving, people! Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Andre Lopes
« Reply #28 - Posted 2013-06-05 15:01:30 »

And yes, you probably are a big company game dev, so i totally should take your comment seriously.

Heh. Made me giggle Cheesy

No, he's not. But regardless of whether someone is a company dev or not, in my opinion experience and passion says much more about the 'skill' of a person/programmer.

I know back when wreed asked lots of simple programming questions. Now he helped you. Really cool stuff.
Keep evolving, people! Smiley

I know, i am trying to help with the little i know and trying to learn from the more experienced ppl.
But you dont need to go out claiming that X or K is retarded and should not try to program.

Im not an experienced programmer, and i am trying to debug myself, and using wiki , but its somewhat confusing sometimes.

Btw, is there anyway i can download the whole wiki ? I would like to print it and make a little book Tongue Cheesy
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #29 - Posted 2013-06-05 19:53:03 »

FYI, I'm still in school and I've been programming for only about 1 and a 1/2 years. (ie: I'm nowhere near professional. But on the other hand, I'm not a noob either)

Do you really think responding sarcastically to something perfectly reasonable, pretending to take insult and trying to make others feel sorry for you to get what you want is going to get you anywhere?

(Seriously think about that one Smiley)

I don't mean to insult you. I think if you take the time, you could become a good programmer. I'd just prefer it if you acted more reasonable to me and other members of the forum.

Thanks. Smiley

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (68 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
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!