Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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]
31  Game Development / Newbie & Debugging Questions / Can I use a Touchpad without using a stage? on: 2013-07-30 21:14:07
Hi again!
So I'm currently trying to make a touchpad into my game. Im using Libgdx and I noticed that Libgdx offers a Touchpad widget, but its only for Stage2D Sad So my question is if you can still use it outside of Stage2D or if there is any other library out there that offers the same? Smiley
32  Game Development / Newbie & Debugging Questions / [LibGdx, TiledMap] getCell returns null :S on: 2013-07-26 15:35:13
So I'm using both LibGdx and TiledMap to create a game. Im currently working on the collision between the player and the map, but everytime when I try to use the getCell method I only recieve a NullPointerException Sad Im using the latest version of Libgdx and I know some of the methods has been redesigned. The map will render fine though.

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  
package com.mayogames.zombiecubes;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.mayogames.zombiecubes.screens.GameScreen;

public class World {
   ZombieCubes zombieCubes;
   private GameScreen gameScreen;
   
   TiledMap testMap;
   OrthogonalTiledMapRenderer mapRender;
   
   TiledMapTileLayer layer;
   
   public World(ZombieCubes zombieCubes, GameScreen gameScreen, String mapName){
      this.zombieCubes = zombieCubes;
      this.gameScreen = gameScreen;
     
      if(mapName == "testMap"){
         TiledMap testMap = new TmxMapLoader().load("data/Maps/testMap.tmx");
         OrthogonalTiledMapRenderer mapRender = new OrthogonalTiledMapRenderer(testMap);
         
         layer = (TiledMapTileLayer) testMap.getLayers().get(0);
         
         System.out.println(layer.getCell(0, 0));
         
         this.layer = layer;
         this.testMap = testMap;
         this.mapRender = mapRender;
      }
     
   }
   
   public void tick(){
     
   }
   
   public void render(OrthographicCamera camera){
      mapRender.setView(camera);
      mapRender.render();
   }
   
   public TiledMapTileLayer getCollisionLayer(){
      return layer;
   }
}
33  Game Development / Newbie & Debugging Questions / How to make text/numbers add to the left instead of right? :( on: 2013-07-20 19:24:36
Hi Smiley So I'm pretty sure you're all confused over the title, so I'll try to be more clear Tongue

Im currently adding score to my game, but my problem is that I want to display the Score in the top-right corner, but when I do that, it adds the extra numbers to the right so they go offscreen Sad Is there any way to make it put the extra numbers to the left? :/

Here's a pic to explain what I mean Smiley



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  
package com.mayogames.zombiecubes;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.mayogames.zombiecubes.entities.Player;
import com.mayogames.zombiecubes.screens.GameScreen;
import com.mayogames.zombiecubes.weapon.Weapon;

public class HUD {
   
   ZombieCubes zombieCubes;
   private GameScreen gameScreen;
   private Player player;
   private Weapon weapon;
   
   private float stateTime;
   private TextureRegion currentHeartFrame;
   
   public HUD(ZombieCubes zombieCubes, GameScreen gameScreen, Player player, Weapon weapon){
      this.zombieCubes = zombieCubes;
      this.gameScreen = gameScreen;
      this.player = player;
      this.weapon = weapon;
   }
   
   public void tick(){
     
   }
   
   public void render(SpriteBatch hudBatch){
      renderHearts(hudBatch);
      Assets.white.draw(hudBatch, getPointsAsString(gameScreen.getPoints()), 700, 483);
   }
   
   public void renderHearts(SpriteBatch hudBatch){
      stateTime += Gdx.graphics.getDeltaTime();
      currentHeartFrame = Assets.healthHUDAnim.getKeyFrame(stateTime, true);
     
      if(player.getHp() >= 3){
         hudBatch.draw(currentHeartFrame, 64, 448);
         hudBatch.draw(currentHeartFrame, 32, 448);
         hudBatch.draw(currentHeartFrame, 0, 448);
      }else if(player.getHp() == 2){
         hudBatch.draw(Assets.heartEmpty, 64, 448);
         hudBatch.draw(currentHeartFrame, 32, 448);
         hudBatch.draw(currentHeartFrame, 0, 448);
      }else if(player.getHp() == 1){
         hudBatch.draw(Assets.heartEmpty, 64, 448);
         hudBatch.draw(Assets.heartEmpty, 32, 448);
         hudBatch.draw(currentHeartFrame, 0, 448);
      }else if(player.getHp() <= 0){
         hudBatch.draw(Assets.heartEmpty, 64, 448);
         hudBatch.draw(Assets.heartEmpty, 32, 448);
         hudBatch.draw(Assets.heartEmpty, 0, 448);
      }
   }
   
   public String getPointsAsString(int convertToString){
      return String.format("%02d", convertToString);
     
   }
}
34  Game Development / Newbie & Debugging Questions / [libgdx] Should I use Scene2D or stick with my own stuff? :) on: 2013-07-07 22:26:47
Hi! So I just started with libgdx and Im wondering if I should learn how to use Scene2D or use "regular" java, which I already know some, just with using spritebatches and the cool libgdx stuff? Smiley
35  Game Development / Newbie & Debugging Questions / [LibGDX] How to add multiple actors/enemies? :) on: 2013-07-03 18:12:13
Hi again! Cheesy So right now I'm working on how to add multiple enemies/actors in Scene2D Tongue I made a Entity inteface, a Enemy superclass that extends Entity and at the last a ZombieCubesEnemy(The enemy in the game) that extends Enemy Smiley

Everything works great when I create them manually in the GameScreen class, but since the spawning will be random and the amount, I have to have easy way to add them instead of adding them manually Smiley

Thanks for reading Smiley
36  Game Development / Newbie & Debugging Questions / [LibGdx] Any tutorials on making a HUD for games :) on: 2013-07-02 18:01:32
Hi! So Im currently trying to make a HUD with a healthbar and a Score string in my game, but I cant find any tutorials on how to do it in LibGdx with Scene2D Sad Do you guys know anyone? Smiley
37  Game Development / Newbie & Debugging Questions / Re: Screen gets messed up on some android devices! :( on: 2013-06-11 21:40:52
Anyone? Sad
38  Game Development / Newbie & Debugging Questions / Re: Screen gets messed up on some android devices! :( on: 2013-06-10 18:06:33
Oh lol, srry xD Was to busy watching the M$ E3 conference Tongue Im using Libgdx

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.mayogames.zombiecubes.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.mayogames.zombiecubes.ZombieCubes;

public class HelpScreen1 implements Screen {
   
   ZombieCubes zombieCubes;
   
   Stage stage;
   TextureAtlas atlas;
   Skin skin;
   SpriteBatch batch;
   Texture helpScreen1Texture;
   
   OrthographicCamera camera;
   Rectangle glViewport;
   
   Button arrowLeftButton;
   Button arrowRightButton;
   
   public HelpScreen1(ZombieCubes zombieCubes){
      this.zombieCubes = zombieCubes;
   }

   @Override
   public void render(float delta) {
      GL10 gl = Gdx.graphics.getGL10();
     
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
      gl.glViewport((int) glViewport.x, (int) glViewport.y,
                (int) glViewport.width, (int) glViewport.height);
     
      camera.update();
        camera.apply(gl);
     
      stage.act(delta);
     
      batch.begin();
      stage.draw();
      batch.end();
     
   }

   @Override
   public void resize(int width, int height) {
      if(stage == null){
         stage = new Stage(width, height, true);
         stage.clear();
         
         Gdx.input.setInputProcessor(stage);
         
         helpScreen1Texture = new Texture(Gdx.files.internal("data/HelpScreens/HelpScreen1.png"));
         helpScreen1Texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
         
         TextureRegion helpScreen1Region = new TextureRegion(helpScreen1Texture, 0, 0, 800, 480);
         Image helpScreen1Image = new Image(helpScreen1Region);
         helpScreen1Image.setX(0);
         helpScreen1Image.setY(0);
         
         ButtonStyle arrowLeftStyle = new ButtonStyle();
         arrowLeftStyle.up = skin.getDrawable("arrowLeft");
         arrowLeftStyle.down = skin.getDrawable("arrowLeftPressed");
         
         ButtonStyle arrowRightStyle = new ButtonStyle();
         arrowRightStyle.up = skin.getDrawable("arrowRight");
         arrowRightStyle.down = skin.getDrawable("arrowRightPressed");
         
         arrowRightButton = new Button(arrowRightStyle);
         arrowRightButton.setWidth(64);
         arrowRightButton.setHeight(64);
         arrowRightButton.setX(735);
         arrowRightButton.setY(0);
         arrowRightButton.addListener(new InputListener(){
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
               return true;
            }
            public void touchUp(InputEvent event, float x, float y, int pointer, int button){
               zombieCubes.setScreen(new HelpScreen2(zombieCubes));
            }
            });
         
         stage.addActor(helpScreen1Image);
         stage.addActor(arrowRightButton);
      }
   }

   @Override
   public void show() {
      batch = new SpriteBatch();
      atlas = new TextureAtlas("data/Misc/buttons.atlas");
      skin = new Skin();
      skin.addRegions(atlas);
     
      camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
      camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
     
        glViewport = new Rectangle(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
   }

   @Override
   public void hide() {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void pause() {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void resume() {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void dispose() {
      helpScreen1Texture.dispose();
      batch.dispose();
      stage.dispose();
      skin.dispose();
      atlas.dispose();
     
   }

}


This is just one example out of the three others helpscreens I have Smiley The other twos don't have the camera in it, but it didn't make a difference :/
39  Game Development / Newbie & Debugging Questions / Screen gets messed up on some android devices! :( on: 2013-06-10 17:05:58
So when I'm trying my game (I only got a splashscreen, mainmenu and some How to Play screens at the time) on my PC, everything works fine, but when I try on my android devices (Xperia PLAY and S3) it places the splashscreen and mainmenu screen where I want (although it scales it down on S3, guessing its the resolution), but with the how to play screens it places it at the bottom right :O

Help? Sad
40  Game Development / Newbie & Debugging Questions / Re: Problems when trying to render a Sprite when rendering stage :( on: 2013-06-09 22:46:35
Thanks! Cheesy It works now Cheesy
41  Game Development / Newbie & Debugging Questions / Re: need to be able to wait inbetween image changes. on: 2013-06-09 21:33:31
You could also use incredibly unprofessional loop stuff:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
slot1.setImage(image1);
invalidate();
int duration = 200;
long time = System.currentTimeMillis();
boolean done = false;
while(System.currentTimeMillis() - time < duration) {
    if(System.currentTimeMillis() - time > 100 && !done) {
        slot2.setImage(image2);
        invalidate();
        done = true;
    }
}
slot2.setImage(image2);
invalidate();


Hey! :O Don't mock me and my "professional" coding skills! Sad
42  Game Development / Newbie & Debugging Questions / Problems when trying to render a Sprite when rendering stage :( on: 2013-06-09 21:25:57
So I'm currently making the MainMenu screen for my game, but I when I try to render both the stage and the logo, it just shows the logo as a big white box on the screen Sad Im a newbie with libGdx so this is probably simple for you experts Tongue

Here's the 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  
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  
package com.mayogames.zombiecubes;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
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.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;

public class MainMenu implements Screen {
   
   ZombieCubes zombieCubes;
   Stage stage;
   BitmapFont black;
   BitmapFont white;
   TextureAtlas atlas;
   Skin skin;
   SpriteBatch batch;
   TextButton playButton;
   OrthographicCamera camera;
   Texture logoTexture;
   Sprite logoSprite;
   
   public MainMenu(ZombieCubes zombieCubes){
      this.zombieCubes = zombieCubes;
   }

   @Override
   public void render(float delta) {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
      stage.act(delta);
     
      batch.begin();
      batch.draw(logoSprite, 0, 0);
      stage.draw();
      batch.end();
   }

   @Override
   public void resize(int width, int height) {
      if(stage == null) stage = new Stage(width, height, true);{
      stage.clear();
     
      Gdx.input.setInputProcessor(stage);
     
      logoTexture = new Texture(Gdx.files.internal("data/ZombieCubesLogo.png"));
      logoTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
      logoSprite = new Sprite(logoTexture);
      logoSprite.setX(100);
      logoSprite.setY(50);
     
      TextButtonStyle style = new TextButtonStyle();
      style.up = skin.getDrawable("button");
      style.down = skin.getDrawable("buttonpressed");
      style.font = white;
     
      playButton = new TextButton("Play!", style);
      playButton.setWidth(600);
      playButton.setHeight(50);
      playButton.setX(Gdx.graphics.getWidth() / 2 - (playButton.getWidth() / 2));
      playButton.setY(Gdx.graphics.getHeight() / 2 - (playButton.getHeight() / 2));
     
      stage.addActor(playButton);
      }
   }

   @Override
   public void show() {
      batch = new SpriteBatch();
      atlas = new TextureAtlas("data/button.atlas");
      skin = new Skin();
      skin.addRegions(atlas);
      black = new BitmapFont(Gdx.files.internal("data/black.fnt"), false);
      white = new BitmapFont(Gdx.files.internal("data/white.fnt"), false);
     
   }

   @Override
   public void hide() {
      dispose();
   }

   @Override
   public void pause() {
     
     
   }

   @Override
   public void resume() {
     
     
   }

   @Override
   public void dispose() {
      batch.dispose();
      skin.dispose();
      atlas.dispose();
      black.dispose();
      white.dispose();
      stage.dispose();
     
   }

}


And yes the image size is PoT Tongue
43  Game Development / Newbie & Debugging Questions / Re: Should I switch over to libgdx? :/ on: 2013-06-06 13:59:13
Yeah, Im going to start all over, but still keep the old code to see if I can reuse some of it Smiley I also have all my graphics done too so Tongue Now Im out looking for some good libgdx tutorials Smiley Do you guys happend to know any? Smiley
44  Game Development / Newbie & Debugging Questions / Re: Should I switch over to libgdx? :/ on: 2013-06-06 13:46:15
So should I just start a new project and start allover? :/ Seems to me that that would be the best option instead of using alot time on probably rewrite the whole thing...even though I really don't want too Tongue
45  Game Development / Newbie & Debugging Questions / Should I switch over to libgdx? :/ on: 2013-06-06 12:52:21
So I'm working on a Java 2D overview type of game which Im planning to port over to Android later Smiley I have worked in pure Java now, but I've heard that using Libgdx might be the best choice because of the Androids performance and memory limitations :/

My question is if I should too this and do I have to rewrite alot of my code? Sad I have already made the player, enemies, animations, powerups, GUI and some more :/
46  Game Development / Newbie & Debugging Questions / Re: Which of these two level method should I use? :P on: 2013-06-06 12:02:41
Okay, so I found this thing called Tiled Map Editor which seems really nice! Smiley All I'm wondering about is if anybody out there have used this before and if I can use it with just pure java for my game? Smiley
47  Game Development / Newbie & Debugging Questions / Re: How to add knockback? :S on: 2013-05-27 14:37:52
Okay, so I have almost got everything working, except that I have one small problem left Sad I want the enemies to not go through eachother, but I just can't find a solution Sad I tried this code:
Note: I'm using it on the player for testing purposes!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
if(player.isMovingRight() == true){
            player.setX(x - 22 + speedX);
         }else if(player.isMovingLeft() == true){
            player.setX(x + 22 - speedX);
         }
         
         if(player.isMovingDown() == true){
            player.setY(y - 22 + speedY);
         }else if(player.isMovingUp() == true){
            player.setY(y + 22 - speedY);
         }
         
         if(player.getSpeedX() == 0 && player.getSpeedY() == 0){

            if(speedX > 0 && speedX < 3) player.setX(x + 22 - speedX);
            if(speedX < 0 && speedX > -3) player.setX(x - 22 + speedX);
            if(speedY > 0 && speedY < 3) player.setY(y + 22 - speedY);
            if(speedY < 0 && speedY > -3) player.setY(y - 22 + speedY);
         }
48  Game Development / Newbie & Debugging Questions / Re: How to add knockback? :S on: 2013-05-21 19:44:45
Ahh, thanks! Got it working now! ^^

Since I'm still a newbie at this, I feel it's important to learn what I actually did, so here's another question for you Java experts out there! Wink

Here is the code for my entity controller class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void tick(){
      for(int i = 0; i < entityList.size(); i++){
         tempEntity = entityList.get(i);
         
         tempEntity.tick();
         
         if(entityList.size() >= 2){
            for(int j = 0; j < entityList.size(); j++){
               
               tempEntity2 = entityList.get(j);
               
               if(tempEntity != tempEntity2){
                 
                  if (tempEntity.getRectEnemy().intersects(tempEntity2.getRectEnemy())){
                     
                     System.out.println("Collision between enemies!");
                  }
               }
            }
         }
      }
   }


My question is that to get this working I had to go the Enemy superclass and remove the "static" modifier that was on my rectangle around my enemy (don't know what it was doing there in the first place :S ), but what did I really do? Tongue If I remember correctly, static is used when you have to use something in a class you haven't initialised yet, but I'm sure you use it for different stuff Tongue
49  Game Development / Newbie & Debugging Questions / Re: How to add knockback? :S on: 2013-05-21 16:54:32
Ok, so I have been able to make the knockback work for when the player hits a enemy, but how do I make the collision for when a enemy hit another enemy work? Sad I tried doing this:

1  
2  
3  
4  
5  
public void checkCollisionBetweenEnemies(Rectangle rectEnemy){
      if (rectEnemy.intersects(rectEnemy)){
         System.out.println("Collision between enemies!");
         }
      }


But that makes it think that it is always a collision Sad It always displays the message since its always hitting it self :/ Note: Im using a superclass called Enemy and I currently have one subclass which is called Zombie Tongue
50  Game Development / Newbie & Debugging Questions / How to add knockback? :S on: 2013-05-16 17:08:40
Hi again! So Im currently trying to figure out how to add knockback to my game, but I'm stuck Sad I searched around a bit, but the only thing I could find was this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
  public void knockback(float r, float force){
      r = r - 180;
     
      force *= knockbackResistance; // how heavy the entity is (so lesser knock back)
     
      knockbackTimer = force * 8;
      knockbackTo = new Vector2((force * (float) MathUtils.sin(r * MathUtils.degreesToRadians)),
                         (-force * (float) MathUtils.cos(r * MathUtils.degreesToRadians)))
                                       .add(position);
               
   }


//Then I have this on the update loop for the entity

   public void update(){
      if(knockbackTimer > 0){
         position = Tools.lerp(position, knockbackTo, 0.2f);
         knockbackTimer -= Gdx.graphics.getDeltaTime() * 1000;
      }
        }


To be honest, I really don't understand it Sad Help, please? Smiley
51  Game Development / Newbie & Debugging Questions / Re: Not able to render my font :( on: 2013-05-12 20:40:11
Was able to fix it myself with some derp coding ^^

Here's the code if anyone else needs it:

Spritesheet class (had to change a little on the getLetterImage method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
import java.awt.image.BufferedImage;

public class SpriteSheet {
   
   private BufferedImage image;
   
   public SpriteSheet(BufferedImage image){
      this.image = image;
   }
   
   public BufferedImage grabImage(int col, int row, int width, int height){
     
      BufferedImage img = image.getSubimage((col * 32) - 32, (row * 32) - 32, width, height);
      return img;
     
   }
   
   public BufferedImage grabLetterImage(int col, int row, int width, int height){
      BufferedImage img = image.getSubimage((col * 16), + (row * 16), width, height);
      return img;
   }
}


And here's the font 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  
public class Font {
   
   private SpriteSheet spriteSheet;
   
   public Font(SpriteSheet spriteSheet){
      this.spriteSheet = spriteSheet;
   }
   
   public static final int SIZE = 8 * Game.SCALE;
   
   private static String chars ="ABCDEFGHIJKLMNOPQRSTUVWXYZ      0123456789.,:'\"!?$%()-=+/ ";
   
   public void render(Graphics g, String message, int x, int y){
      message = message.toUpperCase();
     
      for(int i = 0; i < message.length(); i++){
         int row = 14;
         
         int charIndex = chars.indexOf(message.charAt(i));
         
         if(charIndex < 0) continue;
         
         if(charIndex >= 16 && charIndex <= 31){
            charIndex -= 16;
            row = 15;
         }else if(charIndex >= 32 && charIndex <= 47){
            charIndex -= 32;
            row = 16;
         }else if(charIndex >= 48 && charIndex <= 63){
            charIndex -= 48;
            row = 17;
         }
         
         g.drawImage(spriteSheet.grabLetterImage(charIndex, row, 16, 16), x += 16, y, null);
      }
   }
   
   public static int getStringWidth(String message){
      return message.length() * SIZE;
   }
}


Note: There is probably another way to get the row method, but I'm still a newbie so that's how I fixed it Tongue It works though Wink
52  Game Development / Newbie & Debugging Questions / Re: Not able to render my font :( on: 2013-05-12 14:35:07
I tried 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  
package com.mayogames.zombiecubes.gfx;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import com.mayogames.zombiecubes.Game;

public class Font {
   
   private SpriteSheet spriteSheet;
   
   public Font(SpriteSheet spriteSheet){
      this.spriteSheet = spriteSheet;
   }
   
   public static final int SIZE = 8 * Game.SCALE;
   
   private static String chars ="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,:;'\"!?$%()-=/?$%()-=+/";
   
   public void render(Graphics g, String message, int x, int y){
      message = message.toUpperCase();
     
      for(int i = 0; i < message.length(); i++){
         int charIndex = chars.indexOf(message.charAt(i));
         
         if (charIndex < 0) continue;
         
         g.drawImage(spriteSheet.grabLetterImage((charIndex % 61), (charIndex / 61), 16, 16), x += 16, y, null);
      }
   }
   
   public static int getStringWidth(String message){
      return message.length() * SIZE;
   }
}


But only got a ByteInterleavedTaster error Sad I also fixed the String chars now Tongue
53  Game Development / Newbie & Debugging Questions / Not able to render my font :( on: 2013-05-12 14:10:14
Hi again Smiley

So, currently I'm making the font system and trying to render some text on the screen and I'm almost done, except that I can't get the right character to render Sad I tried Googling and even found some videos, but nothing works Sad The problem is that I can't find the right math formula to use, to get the letter I want Sad Here's my code:

Font 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  
package com.mayogames.zombiecubes.gfx;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import com.mayogames.zombiecubes.Game;

public class Font {
   
   private SpriteSheet spriteSheet;
   
   public Font(SpriteSheet spriteSheet){
      this.spriteSheet = spriteSheet;
   }
   
   public static final int SIZE = 8 * Game.SCALE;
   
   private static String chars =""+
   "ABCDEFGHIJKLMNOPQRSTUVWXYZ      "+
   "QRSTUVWXYZ      "+
   "0123456789.,:;'\"!?$%()-=+/"+
   "
?$%()-=+/       ";
   
   public void render(Graphics g, String message, int x, int y){
      message = message.toUpperCase();
     
      for(int i = 0; i < message.length(); i++){
         int charIndex = chars.indexOf(message.charAt(i));
         
         if (charIndex < 0) continue;
         
         g.drawImage(spriteSheet.grabLetterImage(1, (charIndex / 1), 16, 16), x += 16, y, null);
      }
   }
   
   public static int getStringWidth(String message){
      return message.length() * SIZE;
   }
}


And here's my SpriteSheet class (to load parts of the spritesheet):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
package com.mayogames.zombiecubes.gfx;

import java.awt.image.BufferedImage;

public class SpriteSheet {
   
   private BufferedImage image;
   
   public SpriteSheet(BufferedImage image){
      this.image = image;
   }
   
   public BufferedImage grabImage(int col, int row, int width, int height){
     
      BufferedImage img = image.getSubimage((col * 32) - 32, (row * 32) - 32, width, height);
      return img;
     
   }
   
   public BufferedImage grabLetterImage(int col, int row, int width, int height){
      BufferedImage img = image.getSubimage((col * 16) - 16, + (row * 16) - 16, width, height);
      return img;
   }
}


Here's the spritesheet itself:



I'm sorry if it feels like I'm asking you guys to do it, but I just can't figure it out Sad
54  Game Development / Newbie & Debugging Questions / Re: Which of these two level method should I use? :P on: 2013-05-12 13:38:14
Okay, thanks for all the answers Cheesy
55  Game Development / Newbie & Debugging Questions / Re: Which of these two level method should I use? :P on: 2013-05-11 15:15:54
Yeah, thats a good idea Smiley I'll have the game load up parts of the images which is required Tongue

I'm really not looking forward to learning how to make the map since I'm bad at graphics and stuff like that xD Do any of you guys know a good tutorial on how to code maps in to java games? Smiley
56  Game Development / Newbie & Debugging Questions / Re: Which of these two level method should I use? :P on: 2013-05-10 23:15:53
Okay, I see Smiley I'm planning to port the game to android later Tongue Do you think that would be a problem with rendering a big background then? Tongue I know that andorid devices have less RAM than PCs :/
57  Game Development / Newbie & Debugging Questions / Which of these two level method should I use? :P on: 2013-05-10 22:04:15
Sorry for the bad title, I'll try and explain more Tongue

You see, I'm currently creating a overview 2D type of game, and in that game I'm going to have a big city overview map for the players to roam around in (think GTA and Zelda type). Smiley The problem is that I'm very uncertain on how I should do this. I know a lot of people make tiles and use arrays to make maps in 2D overview games, but since I'm going to create a large map, with alot of free space like streets, I was wondering if it would be better to just make a big background and then use the arraylist method to draw important objects, like building and trashcans, on top of the background again Tongue

What do you think? Smiley
Pages: 1 [2]
 
EgonOlsen (1669 views)
2018-06-10 19:43:48

EgonOlsen (1706 views)
2018-06-10 19:43:44

EgonOlsen (1158 views)
2018-06-10 19:43:20

DesertCoockie (1585 views)
2018-05-13 18:23:11

nelsongames (1185 views)
2018-04-24 18:15:36

nelsongames (1709 views)
2018-04-24 18:14:32

ivj94 (2533 views)
2018-03-24 14:47:39

ivj94 (1758 views)
2018-03-24 14:46:31

ivj94 (2835 views)
2018-03-24 14:43:53

Solater (971 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!