Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  Game Development / Newbie & Debugging Questions / Right way to keep objects in camera on: 2012-12-20 14:56:28
Im trying to keep my touchpad on screen when moving camera, im doing this after camera moves on the render() loop

1  
2  
        stage.getCamera().update();
        touchpad.setBounds((stage.getCamera().position.x-(Gdx.graphics.getWidth()/2))+15,(stage.getCamera().position.y-(Gdx.graphics.getHeight()/2))+15,100,100);


But im thinking this is not the right way, is there any "layer" class where i can add my UI objects and then make it move together with my camera on a simple way?

Hope some help, and sorry for any english mistakes.

ED: Im using LibGDX forgot to say it.
2  Game Development / Newbie & Debugging Questions / Re: Nullpointer exception at render on: 2012-12-18 21:11:18
I solved it myself and ofc it compiles with that code the currentframe only initializes when i drag the touchpad, i added a default frame and it works.

Thank u very much for the help i will be in this great forum, and again sorry for my poor english i try my best Smiley
3  Game Development / Newbie & Debugging Questions / Re: Nullpointer exception at render on: 2012-12-18 00:14:47
thanks that was a really stupid fail, but im still getting errors

E/AndroidRuntime( 1409): FATAL EXCEPTION: GLThread
E/AndroidRuntime( 1409): java.lang.NullPointerException
E/AndroidRuntime( 1409):        at com.badlogic.gdx.graphics.g2d.SpriteBatch.dra
w(SpriteBatch.java:730)
E/AndroidRuntime( 1409):        at gdx.game.Game.render(Game.java:67)
E/AndroidRuntime( 1409):        at com.badlogic.gdx.backends.android.AndroidGrap
hics.onDrawFrame(AndroidGraphics.java:449)
E/AndroidRuntime( 1409):        at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
E/AndroidRuntime( 1409):        at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)

on the next line
spriteBatch.draw(currentFrame, 100, 100);

that textureregion should be ok, the getSprites() function its almost copy paste from here: http://code.google.com/p/libgdx/wiki/SpriteAnimation

Really thanks for the help and sorry for my bad english
4  Game Development / Newbie & Debugging Questions / Nullpointer exception at render on: 2012-12-17 23:17:26
Hi, im starting with libgdx on android and im trying to do some practices, im getting this error

E/AndroidRuntime( 1592): FATAL EXCEPTION: GLThread
E/AndroidRuntime( 1592): java.lang.NullPointerException
E/AndroidRuntime( 1592):        at gdx.game.Game.render(Game.java:81)
E/AndroidRuntime( 1592):        at com.badlogic.gdx.backends.android.AndroidGrap
hics.onDrawFrame(AndroidGraphics.java:449)
E/AndroidRuntime( 1592):        at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
E/AndroidRuntime( 1592):        at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)

Here is my 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  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
public class Game implements ApplicationListener {

    Stage stage;
    SpriteBatch spriteBatch;
    muñeco pnj;
    Image image;
    Touchpad touchpad;
    TextureRegion[] walkFrames;
    float stateTime;
    OrthographicCamera camera;
    TextureRegion currentFrame;
    Label lbl;
    JoystickScreen js;

    public void create() {
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);

        Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
        pnj = new muñeco(getSprites("data/sprite.png", 3, 4));
        pnj.setAnims();
        touchpad = new Touchpad(20, skin);
        touchpad.setBounds(15, 15, 100, 100);

        stage.addActor(touchpad);

    }

    public void render() {

        Gdx.gl.glClearColor(0, 0, 0.2f, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        stage.act(Gdx.graphics.getDeltaTime());
        stateTime += Gdx.graphics.getDeltaTime();                       // #15
       if (touchpad.getKnobPercentX() > 50) {
            currentFrame = pnj.walkr.getKeyFrame(stateTime, true);      // #16
       }
        if (touchpad.getKnobPercentX() < -50) {
            currentFrame = pnj.walkl.getKeyFrame(stateTime, true);      // #16
       }
        if (touchpad.getKnobPercentY() > 50) {
            currentFrame = pnj.walku.getKeyFrame(stateTime, true);      // #16
       }
        if (touchpad.getKnobPercentY() < -50) {
            currentFrame = pnj.walkd.getKeyFrame(stateTime, true);      // #16
       }
        spriteBatch.begin();
        spriteBatch.draw(currentFrame, 100, 100);                         // #17
       spriteBatch.end();
        stage.draw();
    }

    public void resize(int width, int height) {
        stage.setViewport(width, height, true);
    }

    public void pause() {
    }

    public void resume() {
    }

    public void dispose() {
        stage.dispose();
    }

    public void escribir(String frase) {
        lbl.setText(frase);
    }

    public static TextureRegion[] getSprites(String filepath, int col, int fil) {
        Texture walkSheet = new Texture(Gdx.files.internal(filepath));
        TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / col, walkSheet.getHeight() / fil);
        TextureRegion[] walkFrames = new TextureRegion[col * fil];
        int index = 0;
        for (int i = 0; i < col-1; i++) {
            for (int j = 0; j < fil-1; j++) {
                walkFrames[index++] = tmp[i][j];
            }
        }
        return walkFrames;
    }
}


The line that gives the error is:

spriteBatch.begin();

Sorry for that dirty code, i have no idea of what im doing wrong but im sure its a really noob mistake.

Hope some help and sorry for my bad english
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.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!