Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] Sprite not being drawned where i ask to be. [FREAKING SOLVED]  (Read 1113 times)
0 Members and 1 Guest are viewing this topic.
Offline Andre Lopes
« Posted 2013-05-25 00:54:06 »

Hi guys.
I will go directly to the point.

Whenever my missile hits the enemyplane, which are both two rectangles sprites. I want to create an explosion.
Whenever i create and and tell it to draw itself, it draws in a dif location than i told it to.

I mean, as far as i researched and studied, in libgdx the 0,0 stays in bottom left , as a cartesian graphic, right?

Well, it isnt working that. So heres what i did, i decided to load each texture separetly and draw it, still same error happens..


The weird thing is that, i tell it to draw exactly where the missile last pos were...  So it should be in same place!

Can anyone give me a hand with this ? Its driving me nuts!

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  
package Atlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import java.util.ArrayList;
import java.util.List;

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

public class ExplosionLoader {

   
    public Texture[] explosionsTextures;
   
    //Should have used List instead but .. whatever
    public List<Texture> textures;
   
    public ExplosionLoader()
    {
        explosionsTextures = new Texture[48];
     
        loadExplosionsTextures();
    }
   
    private void loadExplosionsTextures() {
        explosionsTextures[0] = new Texture(Gdx.files.internal("ExplosionSheet_001.png"));
        explosionsTextures[1] = new Texture(Gdx.files.internal("ExplosionSheet_002.png"));
        explosionsTextures[2] = new Texture(Gdx.files.internal("ExplosionSheet_003.png"));
        explosionsTextures[3] = new Texture(Gdx.files.internal("ExplosionSheet_004.png"));
        explosionsTextures[4] = new Texture(Gdx.files.internal("ExplosionSheet_005.png"));
        explosionsTextures[5] = new Texture(Gdx.files.internal("ExplosionSheet_006.png"));
        explosionsTextures[6] = new Texture(Gdx.files.internal("ExplosionSheet_007.png"));
        explosionsTextures[7] = new Texture(Gdx.files.internal("ExplosionSheet_008.png"));
        explosionsTextures[8] = new Texture(Gdx.files.internal("ExplosionSheet_009.png"));
        explosionsTextures[9] = new Texture(Gdx.files.internal("ExplosionSheet_010.png"));
        explosionsTextures[10] = new Texture(Gdx.files.internal("ExplosionSheet_011.png"));
        explosionsTextures[11] = new Texture(Gdx.files.internal("ExplosionSheet_012.png"));
        explosionsTextures[12] = new Texture(Gdx.files.internal("ExplosionSheet_013.png"));
        explosionsTextures[13] = new Texture(Gdx.files.internal("ExplosionSheet_014.png"));
        explosionsTextures[14] = new Texture(Gdx.files.internal("ExplosionSheet_015.png"));
        explosionsTextures[15] = new Texture(Gdx.files.internal("ExplosionSheet_016.png"));
        explosionsTextures[16] = new Texture(Gdx.files.internal("ExplosionSheet_017.png"));
        explosionsTextures[17] = new Texture(Gdx.files.internal("ExplosionSheet_018.png"));
        explosionsTextures[18] = new Texture(Gdx.files.internal("ExplosionSheet_019.png"));
        explosionsTextures[19] = new Texture(Gdx.files.internal("ExplosionSheet_020.png"));
        explosionsTextures[20] = new Texture(Gdx.files.internal("ExplosionSheet_021.png"));
        explosionsTextures[21] = new Texture(Gdx.files.internal("ExplosionSheet_022.png"));
        explosionsTextures[22] = new Texture(Gdx.files.internal("ExplosionSheet_023.png"));
        explosionsTextures[23] = new Texture(Gdx.files.internal("ExplosionSheet_024.png"));
        explosionsTextures[24] = new Texture(Gdx.files.internal("ExplosionSheet_025.png"));
        explosionsTextures[25] = new Texture(Gdx.files.internal("ExplosionSheet_026.png"));
        explosionsTextures[26] = new Texture(Gdx.files.internal("ExplosionSheet_027.png"));
        explosionsTextures[27] = new Texture(Gdx.files.internal("ExplosionSheet_028.png"));
        explosionsTextures[28] = new Texture(Gdx.files.internal("ExplosionSheet_029.png"));
        explosionsTextures[29] = new Texture(Gdx.files.internal("ExplosionSheet_030.png"));
        explosionsTextures[30] = new Texture(Gdx.files.internal("ExplosionSheet_031.png"));
        explosionsTextures[31] = new Texture(Gdx.files.internal("ExplosionSheet_032.png"));
        explosionsTextures[32] = new Texture(Gdx.files.internal("ExplosionSheet_033.png"));
        explosionsTextures[33] = new Texture(Gdx.files.internal("ExplosionSheet_034.png"));
        explosionsTextures[34] = new Texture(Gdx.files.internal("ExplosionSheet_035.png"));
        explosionsTextures[35] = new Texture(Gdx.files.internal("ExplosionSheet_036.png"));
        explosionsTextures[36] = new Texture(Gdx.files.internal("ExplosionSheet_037.png"));
        explosionsTextures[37] = new Texture(Gdx.files.internal("ExplosionSheet_038.png"));
        explosionsTextures[38] = new Texture(Gdx.files.internal("ExplosionSheet_039.png"));
        explosionsTextures[39] = new Texture(Gdx.files.internal("ExplosionSheet_040.png"));
        explosionsTextures[40] = new Texture(Gdx.files.internal("ExplosionSheet_041.png"));
        explosionsTextures[41] = new Texture(Gdx.files.internal("ExplosionSheet_042.png"));
        explosionsTextures[42] = new Texture(Gdx.files.internal("ExplosionSheet_043.png"));
        explosionsTextures[43] = new Texture(Gdx.files.internal("ExplosionSheet_044.png"));
        explosionsTextures[44] = new Texture(Gdx.files.internal("ExplosionSheet_045.png"));
        explosionsTextures[45] = new Texture(Gdx.files.internal("ExplosionSheet_046.png"));
        explosionsTextures[46] = new Texture(Gdx.files.internal("ExplosionSheet_047.png"));
        explosionsTextures[47] = new Texture(Gdx.files.internal("ExplosionSheet_048.png"));
   
    }

   
}


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  
package Atlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

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

public class Explosion {

    private Texture currentFrame; //
    private SpriteManager spriteManager; //
    private int posX, posY;
    private int indexFrame;

    public Explosion(SpriteManager sm, int posX, int posY) {

        spriteManager = sm;
        //
        this.posX = posX;
        this.posY = posY;
        //
        indexFrame = 0;



    }

    public void update() {
        indexFrame++;

        if (indexFrame >= spriteManager.getExplosionLoader().explosionsTextures.length) {
            indexFrame = 0;
        }

        currentFrame = spriteManager.getExplosionLoader().explosionsTextures[indexFrame];
    }

    public void render(SpriteBatch sb) {

        if (currentFrame == null) {
            update();
        }


        sb.draw(currentFrame, posX, posY);

    }

    public boolean isFinished() {
        if (indexFrame > 30) {
            return true;
        } else {

            return false;

        }


    }
}
Offline Phased
« Reply #1 - Posted 2013-05-25 01:01:54 »

I can't see anything wrong with the classes quickly, it has too be how you are creating the explosion.

I'm going to assume, you are feeding in random positions into the method instead of the enemy's location

1  
new Explosion(sm, enemy.xPos, enemy.yPos);


That will render it to where the x and y pos are, but if u wanted it centered, you can add half the width to xPos, and half the height for yPos and it should be centered.
Offline Andre Lopes
« Reply #2 - Posted 2013-05-25 01:08:43 »

Im feeding the enemies position.

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  
package Collisions;

import Atlas.Explosion;
import Logic.GameUpdate;
import Models.EnemyPlane;
import Models.Missile;
import Models.Plane;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

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

public class MainCollision {

    private GameUpdate gameupdate;
//
    private ArrayList<EnemyPlane> enemies;
    private ArrayList<Missile> myMissiles;
    //private ArrayList<Explosion> explosions;
    //private Plane plane;
    private Rectangle ENEMIEPLANE_RECTANGLE;
    private Rectangle MYMISSILE_RECTANGLE;

    public MainCollision(GameUpdate g) {
        gameupdate = g;
        System.gc();
    }

    public void collision() {
        //explosions = gameupdate.getExplosions();

        enemies = gameupdate.getEnemies();
        myMissiles = gameupdate.getMyMissiles();
        //plane = gameupdate.getShooterGame().getPlane();

        for (int m = 0; m < myMissiles.size(); m++) {
            Missile getMissileM = myMissiles.get(m);
           
            //Detecta Colisao Entre Missel e inimigo.
            MYMISSILE_RECTANGLE = getMissileM.getMissileRepresentativeRectangle();
       
            for (int e = 0; e < enemies.size(); e++) {
                EnemyPlane getEnemieE = enemies.get(e);

                ENEMIEPLANE_RECTANGLE = getEnemieE.getEnemyPlaneRepresentativeRectangle();
           
                if (ENEMIEPLANE_RECTANGLE.intersects(MYMISSILE_RECTANGLE))
                {
                   
                    gameupdate.removeMissile(m);
                    gameupdate.removeEnemyPlane(e);
                    //Create Explosion Based on (x;y) Intersection
                    int x = getMissileM.posX;
                    int y = getMissileM.posY;
                    gameupdate.addNewExplosion(x,y);
                    //Adiciona novo inimigo casa haja colisao.//
                    gameupdate.addNewEnemy();
                }



            }
        }


    }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-05-25 02:26:13 »

A few things.

1. Whenever you are writing a lot of repetitive code, it's probably a sign you should refactor. Using lists would have made it a bit clearer, but for loops would be even better:

1  
2  
3  
for (int i=0; i<MAX_IMAGES; i++) {
    textures.add( new Texture(Gdx.files.internal("tex_0"+i+".png");
}


2. Use texture atlases. This will improve performance and readability.
https://code.google.com/p/libgdx-texturepacker-gui/

Generall you shold only have a few Texture objects, and many TextureRegions.
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Textures#texture-atlases

3. Don't call System.gc().

4. In Java, all caps (i.e. ENEMIEPLANE_RECTANGLE) usually suggests a constant. Use camelCase for members and UpperCase for class names.

5. Where is your sprite batch rendering code? Make sure your cameras are working properly.


Your code is hard to read, and thus hard to debug. This is why clean code is important, even if you plan to be the only one looking at it. Tongue

Offline Andre Lopes
« Reply #4 - Posted 2013-05-25 03:35:01 »

Yeah sorry, that class is a bit outdated i need to change those stuff.

How do i mess with cameras?
I researched in wiki, but its kinda complicated , i never kinda understood it, even in that Java Game Killer Programming book..

What does a camera means?

Please, if you help me fix it, i will give you one ZILLION DOLLARSSS or Reais actually.. jking

Anyway, i beg for this forum help Cheesy
Offline ReBirth
« Reply #5 - Posted 2013-05-25 04:36:15 »

As davedes said, your code is not eyes friendly and no one bother to rubber duck it. But at glance I can see your SpriteBatch draws only ONE texture.

- Spam TextureRegion/Sprite/Image, Texture is expensive
- All you need to is Animation class. There is tutorial of it on users wiki

Trivia: I don't like debate between lwjgl or libgdx for newbie. My answer is always same: Java2D. Why? because it teaches, forces you to understand how basic game working by looping, acting, rendering, etc. Soon after you mastered Java2D you can use other frameworks easily. You just read/skim the source code and you understand what's going on, what its place in Java2D world.

Offline Andre Lopes
« Reply #6 - Posted 2013-05-25 12:58:05 »

Yeah i will fix all those stuff.
I had a sprite with all the images together , but i decided to slice them to see if the problem would end, which it didnt.

The fact is, whenever i ask it to draw any other sprite or as i just did, i asked it to draw a String at pos 0,0 , and then at 10,10 and it was OK.
At the same time, i asked to draw the explosion at 0,0

I could see the difference of positions... it was such a huge gap that i got a seizure lol.

Im getting kinda desperate... idk whats happening, seriously, i dont.
https://www.dropbox.com/s/krg0p965m31f8d3/PlaneShooterDebug3.0.zip?v=0rw

Thats the link of the project, with the source code plus the images... if anyone can help me find whats happening, i would thank you and build a statue on your name.


--
And yes, i will fix all those issues described as soon as i can get this explosion Animation working, i had the class Explosion with An object called ANimation, as it is in Source Code, etc... And still didnt work.
In the source code theres all that, all preety and sexy.Still no-go.
Offline Andre Lopes
« Reply #7 - Posted 2013-05-25 14:49:27 »

Ok, i made a new project and designed to represent better my issue :

1) i ask to draw the explosion at position 10,10;

2) I ask to draw the font at the position explosion.getX() , explosion.getY()

The result :




Now, the classes are preety simple, So i think will be easier to read.

* The SpriteManager Class loads the Images that i use, i use it instead of Atlas, due to a problem that i had some time ago :
http://www.java-gaming.org/topics/atlas-bug-when-i-draw-my-image-it-draw-all-the-images/29636/view.html

* The "ExplosionModel" Class, divide the Texture for me and prepare all the objects for use.

* The "Explosion" Class is the Explosion itself with its variables, it have its render(SpriteBatch sb) method and Update()  method.


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  
package Atlas;

import View.ShooterGame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

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

public class SpriteManager {

    //REFERENCE EXP MODEL
    private ExplosionModel explosionModel;

   
    //Create Textures
    private Texture explosionTexture;
    private Texture myPlane;
    private Texture enemyPlane;
    private Texture myMissile;
   
   
   
    public SpriteManager() {
       
        explosionTexture = new Texture(Gdx.files.internal("ExplosionSheet.png"));
        myPlane = new Texture(Gdx.files.internal("plane.jpg"));
        enemyPlane = new Texture(Gdx.files.internal("enemyOrangePlane.jpg"));
        myMissile = new Texture(Gdx.files.internal("missileArthur.jpg"));
       
        //
        explosionModel = new ExplosionModel(this);
    }

    public Texture getExplosionTexture() {
        return explosionTexture;
    }

    public Texture getMyPlane() {
        return myPlane;
    }

    public Texture getEnemyPlane() {
        return enemyPlane;
    }

    public Texture getMyMissile() {
        return myMissile;
    }


    public Texture getExplosion() {
        return explosionTexture;
    }

    public ExplosionModel getExplosionModel() {
        return explosionModel;
    }
}


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  
package Atlas;


import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

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

public class ExplosionModel {

    private final int FRAME_COLS = 8;
    private final int FRAME_ROWS = 6;
    private Animation explosionAnimation;
    private TextureRegion[] explosionsFrames;
    private TextureRegion currentFrame;
    private float stateTime;
    private SpriteManager spriteManager;
    private Texture explosionSheet;

    public ExplosionModel(SpriteManager sm) {
        spriteManager = sm;
        explosionSheet = spriteManager.getExplosion();
        TextureRegion[][] tmp = TextureRegion.split(explosionSheet, explosionSheet.getWidth() / FRAME_COLS, explosionSheet.getHeight() / FRAME_ROWS);

        explosionsFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];

        int index = 0;
        for (int i = 0; i < FRAME_ROWS; i++) {
            for (int j = 0; j < FRAME_COLS; j++) {
                explosionsFrames[index++] = tmp[i][j];
            }
        }
        explosionAnimation = new Animation(0.025f, explosionsFrames);
        stateTime = 0f;

    }

    public int getFRAME_COLS() {
        return FRAME_COLS;
    }

    public int getFRAME_ROWS() {
        return FRAME_ROWS;
    }

    public Animation getExplosionAnimation() {
        return explosionAnimation;
    }

    public TextureRegion[] getExplosionsFrames() {
        return explosionsFrames;
    }

    public TextureRegion getCurrentFrame() {
        return currentFrame;
    }

    public float getStateTime() {
        return stateTime;
    }

    public SpriteManager getSpriteManager() {
        return spriteManager;
    }

    public Texture getExplosionSheet() {
        return explosionSheet;
    }

   
   
   
}




--------------------------------
--------------------------------

Now the Two important Classes :

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  
package Atlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

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

public class Explosion {

 
    private Animation explosionAnimation; //
    private TextureRegion[] explosionsFrames; //
    private TextureRegion currentFrame; //
    private float stateTime; //
    private SpriteManager spriteManager; //
    private Texture explosionSheet; //
    private int posX, posY;

    public Explosion(SpriteManager sm, int posX, int posY) {

        spriteManager = sm;
        //
        this.posX = posX;
        this.posY = posY;
        //
        explosionSheet = spriteManager.getExplosion();

        explosionsFrames = sm.getExplosionModel().getExplosionsFrames();

        explosionAnimation = sm.getExplosionModel().getExplosionAnimation();
        stateTime = sm.getExplosionModel().getStateTime();

    }

    public void update() {
        currentFrame = getCurrentFrame();
    }

    public void render(SpriteBatch sb) {
        if (currentFrame == null) {
            update();
        }
        sb.draw(currentFrame,posX,posY);
    }

    public boolean isFinished() {
        return explosionAnimation.isAnimationFinished(stateTime);
    }

    private TextureRegion getCurrentFrame() {
        stateTime += Gdx.graphics.getDeltaTime();
        currentFrame = explosionAnimation.getKeyFrame(stateTime, false);
        return currentFrame;
    }

    public int getPosX() {
        return posX;
    }

    public int getPosY() {
        return posY;
    }
   
}



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  
package View;

import Atlas.Explosion;
import Atlas.SpriteManager;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

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

public class ShooterGame implements ApplicationListener{

    private SpriteBatch spriteBatch;
    private Explosion ex;
    private SpriteManager spriteManager;
    private BitmapFont font;
   
    @Override
    public void create() {
        spriteBatch = new SpriteBatch();
        spriteManager = new SpriteManager();
        font = new BitmapFont();
        ex = new Explosion(spriteManager,10,10);
       
    }

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

    @Override
    public void render() {
      spriteBatch.begin();
     
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      ex.render(spriteBatch);
      font.draw(spriteBatch,"[X]",ex.getPosX(),ex.getPosY());
      //
      //
      //
      ex.update();
     
      spriteBatch.flush();
      spriteBatch.end();
    }

    @Override
    public void pause() {
     
    }

    @Override
    public void resume() {
       
    }

    @Override
    public void dispose() {
     
    }

}
Offline Andre Lopes
« Reply #8 - Posted 2013-05-25 15:25:15 »

Ok, just to pop up, i noticed some things ,

1) The png explosion , is 2048/2048
 private final int FRAME_COLS = 8;
    private final int FRAME_ROWS = 6;

That means, it have 8 Columns and 6 Rows

.: 2048 / 8 = 256
And
2048 / 6 = 341,33333333333333333333...
as Shown here : http://www.wolframalpha.com/input/?i=2048+%2F+6&dataset=

That means, im either loosing or leaking some space in the png.
That could be the problem?

Well, i did test it :

....
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
 public ExplosionModel(SpriteManager sm) {
        spriteManager = sm;
        explosionSheet = spriteManager.getExplosion();
        TextureRegion[][] tmp = TextureRegion.split(explosionSheet,(256),(341));
        // TextureRegion[][] tmp = TextureRegion.split(explosionSheet,(explosionSheet.getWidth()/FRAME_COLS),(explosionSheet.getHeight()/FRAME_ROWS));
       
        explosionsFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
        //TextureRegion(TextureRegion region, int x, int y, int width, int height)
        int index = 0;
        for (int i = 0; i < FRAME_ROWS; i++) {
            for (int j = 0; j < FRAME_COLS; j++) {
                explosionsFrames[index++] = tmp[i][j];
            }
        }
        explosionAnimation = new Animation(0.025f, explosionsFrames);
        stateTime = 0f;

    }

...

Same Thing Happens, and if i overflow like this :
        TextureRegion[][] tmp = TextureRegion.split(explosionSheet,(256),(342));

I get an Error... but, before it gives the overflow error, it draws in a dif place on the screen.... So it could be the root of the issue?
Offline Andre Lopes
« Reply #9 - Posted 2013-05-25 16:11:04 »

HAHAHAHAHA
I think i finnally figured it out!!
Its because the Transparent size of the png is too big, so it SEEMS its drawing out of place, but in reality it isnt!!!

So heres what i did, i removed the alpha Transparency and i draw some colored stuff so i could see where was being drawn.

And it worked. It seems, im stupid.
Yes that does feel right.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
 public void render(SpriteBatch sb) {
        if (currentFrame == null) {
            update();
        }
        posXCompensation = (currentFrame.getRegionWidth()/2);
        posYCompensation = (currentFrame.getRegionHeight()/2);
       
        int x = posX - (posXCompensation);
        int y = posY - (posYCompensation);
       
        sb.draw(currentFrame,x,y);
       
    }


Tongue

Well, theres just that one thing...
2048/6 is 341,3333 , how does libgdx work with that? does it transform to 341,3 ? Trunk ?

Oh well . ty !
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #10 - Posted 2013-05-25 16:32:55 »

You wouldn't have wasted all this time if you just used a texture packer in the first place. Tongue

Since you are diving an int (regionWidth/Height) by 6, you would end up with another int. e.g. 341. If you want float values you need to divide by 6f. Drawing at half-pixels might lead to blurring or aliasing, but it also makes for smoother movement.

Offline Andre Lopes
« Reply #11 - Posted 2013-05-25 16:42:37 »

Texture pack bugs for me :
http://www.java-gaming.org/topics/atlas-bug-when-i-draw-my-image-it-draw-all-the-images/29636/view.html

idk how to solve that.

So im using my own sprite manager.
Offline ReBirth
« Reply #12 - Posted 2013-05-26 02:43:17 »

Don't worry, hundreds android games (yes I believe) made by libgdx including mine are flying freely through store right now. So if the texture pack breaks you, it must be your fault somewhere. We just not happened to find it.

Offline Andre Lopes
« Reply #13 - Posted 2013-05-26 03:16:28 »

Don't worry, hundreds android games (yes I believe) made by libgdx including mine are flying freely through store right now. So if the texture pack breaks you, it must be your fault somewhere. We just not happened to find it.

Im sorry, im still learning a lot here. Theres much that i still dont know.
Offline ReBirth
« Reply #14 - Posted 2013-05-27 05:25:46 »

Your best bet since you've acknowledged your weak (bit harsh, but yeah) is to follow basic pattern/structure provided from wiki/tutorial. Stop trying to make your game robust by implementing manager, singletons, it-should-be-OOP, it-should-be-whatever, or whatever. Just got one damn Game/ApplicationListener class and several screens with entities inside. Screw performance. Screw beauty code (but still follow standard coding rules). Just make it work first for nut's sake! Cheesy

Pages: [1]
  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 (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (40 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (26 views)
2014-10-26 10:14:04

theagentd (32 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!