Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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  Java Game APIs & Engines / Java 2D / Re: problem with code on: 2013-09-25 06:47:38
I believe you want to change...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
String option = VIDEO_ORDER[row][0];
            if (videoButtons[row][col].isButtonPressed(input)) {
                // this case is supposed that should invoke part of code
               // in else case
           } else {
                this.invoke = false;
                this.lastInvoke = container.getTime();
                this.buttonInvokeController(option, col);
                // case works
           }


to

1  
2  
3  
4  
5  
if (videoButtons[row][col].isButtonPressed(input)) {
                this.invoke = false;
                this.lastInvoke = container.getTime();
                this.buttonInvokeController(option, col);
            }


I believe isButtonPressed only fires the first time it's pressed down. So the else statement was constantly resetting everything and always causing the code in your if statements to not run.
2  Game Development / Newbie & Debugging Questions / Re: Loading .gif images - url = null trouble on: 2013-09-24 21:58:45
I'm fairly certain this.getClass().getClassLoader().getResource(ref); will look in the root directory of your program

Lets say src, bin etc are in C:/SpaceInvaders

So...

1  
this.getClass().getClassLoader().getResource("sprites/homer.gif");


is pointing to C:/SpaceInvaders/sprites/homer.gif
3  Game Development / Newbie & Debugging Questions / Re: Loading .gif images - null pointer trouble on: 2013-09-24 19:58:42
What he's saying is that your variable 'single' is null. You never assign it to anything. Therefore when you call the get() method it returns exactly that... null

Change it to this...

1  
private static SpriteStore single = new SpriteStore();


or you can do something like...

1  
2  
3  
4  
5  
6  
7  
8  
9  
private static SpriteStore single;

// other code

public static SpriteStore get() {
      if (single == null)
          single = new SpriteStore();
      return single;
   }
4  Game Development / Networking & Multiplayer / Re: [Kryonet] How to build a Mulitplayerserver? on: 2013-04-18 16:15:46
What do you have set up so far? Do you have anything? I'm doing something very similar right now so I could be of some help here. I have it working pretty well.
5  Game Development / Networking & Multiplayer / Re: [Kryonet] Getting indexOutOfBounds on Client.Update line 297 on: 2013-04-01 17:00:29
Are you sure the console isn't showing anything? If you're running the Server and the Client from Eclipse the console will switch back and forth between the 2. It's possible that it's staying on the Server's console.

To show the client console just open the debug tab and double click the client process and then click back on the console tab.

It'll most likely be called '<terminated> Main [Java Application]' or something like that since it's crashing.
6  Game Development / Networking & Multiplayer / Re: [Kryonet] Getting indexOutOfBounds on Client.Update line 297 on: 2013-04-01 16:30:50
Ah, I see. The actual Client class from the Kryonet Library is throwing the error. I thought you meant that your client class was throwing the error. I apologize.


With the information given I couldn't really tell you much other than what it's already telling you. Can you post your code?
7  Game Development / Networking & Multiplayer / Re: [Kryonet] Getting indexOutOfBounds on Client.Update line 297 on: 2013-04-01 16:02:46
Window -> Show View -> Console

The console window will give you a trace of what's going on. Also... Why would you go on Googles code page to find line 297 instead of just looking in your code?
8  Game Development / Newbie & Debugging Questions / Re: Another dumb question.. on: 2013-03-31 05:57:53
Do you ever initialize the Brick array?
1  
bricks = new Brick[10];
9  Game Development / Newbie & Debugging Questions / Re: Another dumb question.. on: 2013-03-31 04:00:37
Call all the rendering in your main class...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
public class Game implements ApplicationListener {
   private OrthographicCamera camera;
   private SpriteBatch batch;
   //private Texture ballImage;
  //private Texture paddleImage;

   Paddle paddle;
   Ball ball;

   @Override
   public void create() {    
       float w = Gdx.graphics.getWidth();
       float h = Gdx.graphics.getHeight();
       
       camera = new OrthographicCamera(1, h/w);
       batch = new SpriteBatch();      

       //Initialize your custom classes
      Ball ball = new Ball();
       Paddle paddle = new paddle();

   }  

   @Override
   public void dispose() {
      batch.dispose();
      ball.dispose();
      paddle.dispose();
   }

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

       CheckKeys();
       ball.overlaps(paddle);

       batch.begin()
       //Send the SpriteBatch to the ball and paddle render method
      ball.render(batch);
       paddle.render(batch);
       batch.end();
   }

    public void CheckKeys(){
           
         if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT))
         {
            paddle.isLeftPressed=true;
         }else{paddle.isLeftPressed=false;}
         
      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT))
      {
         paddle.isRightPressed=true;
      }else{paddle.isRightPressed=false;}
   }


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  
public class Paddle
{
     Texture texture;
     Rectangle paddleRect;
     
     int paddleSpeed;
     
     public boolean isRightPressed = false;
     public boolean isLeftPressed = false;
     
    //You could also create other constructors that allow you to assign a texture, paddle size etc.
    public Paddle(){
        texture = new Texture(...);
        paddleRect.x = 400/2 - 64/2;
        paddleRect.y = 20;
        paddleRect.width = 64;
        paddleRect.height = 16;
    }

    public void render(SpriteBatch batch){

         if (isLeftPressed==true && paddleRect.x >=0){paddleRect.x=paddleRect.x-paddleSpeed;}
         if (isRightPressed==true && paddleRect.x <= 400 - 64){paddleRect.x=paddleRect.x+paddleSpeed;}

        batch.draw(texture, paddleRect.x, paddleRect.y);
    }
    //dispose etc...
}


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  
//import your Paddle class
public class Ball
{
       Texture texture;
       Vector2 ballSpeed;

       Rectangle ballRect;
       
       //Once again you can add different contstructors to set different variables
      public Ball(){
           texture = new Texture(...);
           ballSpeed = new Vector2(1, 1);
           ballRect = new Rectangle();
           ballRect.x = 400/2;
           ballRect.y = 600/2;
           ballRect.width = 16;
           ballRect.height = 16;
       }
       
       public void render(SpriteBatch batch){
            ballRect.x= ballRect.x + ballSpeed.x;
            ballRect.y= ballRect.y + ballSpeed.y;
     
            if (ballRect.x >= 400-16){ballSpeedX=-ballSpeed.x;}
            if (ballRect.x <= 0){ballSpeedX=-ballSpeed.x;}
     
            if (ballRect.y >= 600-16){ballSpeedY=-ballSpeed.y;}
            if (ballRect.y <= 0){ballSpeedY=-ballSpeed.y;}
     
     
            ballRect.x= ballRect.x + ballSpeed.x;
            ballRect.y= ballRect.y + ballSpeed.y;

            batch.draw(texture,ballRect.x,ballRect.y);
       }

       //I made this a boolean but you can make it void if you don't want it to return anything
      public boolean overlaps(Paddle paddle){
            if (ballRect.overlaps(paddle.paddleRect)){ballSpeed.y = -ballSpeed.y; return true; }
            return false;
       }
       //dispose etc...
}


That's roughly what I would do.

Note: I changed a few variable types but forgot to change it in the original code I got from you but you get the idea.
10  Game Development / Newbie & Debugging Questions / Re: Need help with displaying text for a certain amount of time [UnSolved] on: 2013-03-30 03:39:10
Something along the lines of...


1  
2  
3  
4  
5  
6  
7  
8  
9  
int displayTime = 50; //Change accordingly
public void update() //Or whatever your update/draw method is called
{
    if(displayTime > 0)
    {
        //Code to display text here
       displayTime -= 1;
    }
}


That's a really simple way to do it.
11  Game Development / Newbie & Debugging Questions / Re: Linking strings / textures together somehow on: 2013-03-28 05:04:06
Not sure if you would want to do this, or if it's even recommended by better programmers than myself but you can always declare your own class and extend Texture.

It would look like...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class Texture2 extends Texture
{
    String str;
   
    public Texture2(FileHandle file, String str)
    {
        super(file);
        this.str = str;
    }
    //... More constructors here
   
    // You can also add get/set methods if you want
}


In the main code just change 'new Texture(blah)' to 'new Texture2(blah, string)'

Then it's always tied to that texture.

Edit: Updated the code example.
12  Game Development / Newbie & Debugging Questions / Re: LibGDX - Get TouchPoint X and Y in Perspective? on: 2013-03-27 18:17:10
Not sure if this helps...

ProjectTest.java

Nevermind that's the wrong file... Give me a sec to find the one I was actually talking about lol.
13  Game Development / Newbie & Debugging Questions / Re: What have been/are your learning techniques? on: 2013-03-27 14:09:09
Quote
Why did you want to start programming? (What was your motivation?)
I had always been more interested in computers than anything else. I started with the hardware, building my own rig etc, and got more interested in the software not long after.

Quote
Why did you choose to begin with the language you begun with? And if applicable, why are you using the language you are using now?
Started with....
OOP: Java. Started in highschool because that's all they offered at the time.
Scripting: HTML and PHP.

Currently using...
C# and Java. They're similar in many, many ways. I personally like C# better though.

Quote
How long ago did you get started? And where are you at now?
Started around age... 12... I believe. I started a clan with a friend for BF2 and Counter-Strike, that's where the HTML and PHP come in. Made a website for the clan lol. I didn't learn Java until I was 14-15.

Quote
What learning methods did you employ personally to help you develop your skills in programming?
I'm a learn as I go kind of person. Not sure if 'Trial and Error' count as a learning technique but that's how I tackle most tasks. I also Google a lot... lol

Quote
What advice could you give to other programmers who might be feeling a little lost in what direction to take?
Decide on a simple, single program you want to write. Write it in a few different languages and see which one you enjoy/understand the most.

Quote
Is there anything you believe should be a "Rite of Passage" for programmers (such as the need to create hello world, or a snake program, etc etc).
You must break into Fort Knox with code alone. But seriously... I don't consider people "programmers" unless they know OOP. But maybe that's just me being mean...
14  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Resize Texture for use with TextureRegion on: 2013-03-27 08:49:16
You have a good point. I was looking at this wrong. Instead of downsizing the image I can just increase the tile size based on the texture resolution and then downsize the sprite that holds the tile so it will work with any size image..

Thank you, sir.
15  Game Development / Newbie & Debugging Questions / Re: translate and animate simultaneously on: 2013-03-27 03:21:40
Edit: Nevermind I was reading the code wrong.
16  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Resize Texture for use with TextureRegion on: 2013-03-27 02:34:53
Resizing the texture on the screen isn't the problem. TextureRegion using the textures native resolution is my problem.

Let's say I have a texture that's 100x100 but I need it to be 50x50 for use with TextureRegion. I need to resize the native resolution to 50x50 before sending it to be cut into pieces by TextureRegion.

For further clarification I'm splitting up a single picture into many little pictures that make up the main picture. I'm making a puzzle type game.

The pictures all need to be a certain resolution for the game to work correctly.
17  Game Development / Newbie & Debugging Questions / [LibGDX] Resize Texture for use with TextureRegion on: 2013-03-27 02:17:09
I want to resize a texture before sending it to be chopped up by TextureRegion.

Is this possible?

I've already tried using Sprites and that didn't work and I'm really not sure where else to look. It's probably something simple I'm just missing.

Note: I'm aware I can do this in an external program but I want my game to be able to do this on the fly.
18  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Make Texture/Sprite black and white? on: 2013-03-22 08:36:52
Figured it out.

Didn't need to use

1  
2  
3  
4  
5  
6  
time += Gdx.graphics.getDeltaTime();           
grayscale = (float)Math.sin(time)/2f+0.5f;
       
shader.begin();
shader.setUniformf("grayscale", grayscale);
shader.end();


It's now just...

1  
2  
3  
batch.setShader(shader);
sprite.draw(batch);
batch.setShader(default_shader)


And works as expected.
19  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Make Texture/Sprite black and white? on: 2013-03-22 08:00:05
If you don't need it done in real-time, then you're better off using Photoshop or GIMP to save two copies of your image.

If you need it in real-time or need to process a lot of sprites, using shaders is the ideal solution.

Shader Lesson 3: Grayscale and other effects
Code example

Another solution is to process the Pixmap before uploading it to a Texture:
Pixmaps & Textures

Yeah it needs to be done in real time. So I'm going with Shaders. I found settings for a default shader as well.

My problem right now is that when I apply the grayscaled shader nothing renders... but when I set the shader to the default it renders everything after it fine.

I'm, obviously, very new to shaders so is there anything simple that I might be missing?

Note: I copied VERT and FRAG entirely from the code example.

This is what takes place in my render...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
batch.setShader(shader);
time += Gdx.graphics.getDeltaTime();          
grayscale = (float)Math.sin(time)/2f+0.5f;
       
shader.begin();
shader.setUniformf("grayscale", grayscale);
shader.end();

sprite.draw(batch);
batch.setShader(default_shader)
...
20  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Make Texture/Sprite black and white? on: 2013-03-22 07:16:13
Yeah looking through the LWJGL Shader Tutorial now and that looks like the better solution.

Thanks a million for the code example as well. That will save me a ton of time lol.
21  Game Development / Newbie & Debugging Questions / [LibGDX] Make Texture/Sprite black and white? on: 2013-03-22 06:53:10
Is there any way to remove the color from a Texture in LibGDX and be left with a grayscaled image?
22  Game Development / Networking & Multiplayer / Re: [Kryonet] P2P through the server? on: 2013-03-15 18:40:38
Client A can send a message to the server, then the server could send the message to client B.

Read this post, went and checked Server methods and sure enough, the method I needed was there all along lol.

Last night was rough...
23  Game Development / Networking & Multiplayer / Re: [KryoNet] Desktop can connect, phone can't. on: 2013-03-15 10:19:30
Oh. My. God.

I hate myself.

I forgot to add...

<uses-permission android:name="android.permission.INTERNET" />

to the AndroidManifest.xml file.

Someone make fun of me, I deserve it.
24  Game Development / Networking & Multiplayer / [KryoNet] Desktop can connect, phone can't. on: 2013-03-15 09:47:37
I'm currently writing a game for a school project using Libgdx and KryoNet.

Since I'm using Libgdx I can run it on the desktop and my phone with the same code.

My problem is that I can connect to the server that is running on my desktop with any computer in my house no problem but when I try to connect with my phone it immediately says 'Unable to connect to: /192.168.1.120:9070'.

I've also tried forwarding the ports and using my actual IP address with no luck.

Any ideas?

I can provide code snippets on request but the project is too big to show everything.

Edit:

The timeout is set to 60000
25  Game Development / Networking & Multiplayer / [Kryonet] P2P through the server? on: 2013-03-14 08:30:41
DISCLAIMER: I'm aware that Kryonet is Server/Client based.

Is there any way I can have 1 client/peer talk to another using the server?

When they connect to the server if someone else doesn't have a client/peer you get assigned to them and the game starts. The game would only communicate with the client they were assigned to using the server as the middle man.

That's what I'm going for.

I'm assuming I can achieve this through having remote servers on the client machine that connect to the main server when you first start up the game but I'd like to cut out the remote server part.

Thanks,
Slyntax
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.

radar3301 (11 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (46 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24: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!