Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
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 / Re: [Java|Android|LibGDX|...] Mouse movement and collision detection on: 2014-02-22 17:42:59
Thank you guys, I managed to solve the problem by doing exactly what @trollwarrior1 said. Both of answers helped me that I improved knowledge about the problem. Thanks again. But I have one more question so I wont open new thread for that I will just ask here.   Smiley

It is about antialiasing or "smoothing", when I was programming in pure Java with no engines like libGDX I just set rendering hints to Graphics2D to smooth lines,text,shapes and Java done its job beuatiful
1  
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);


But on libGDX I could not find anything usefull all what I found on internet and tried it, it makes situation worse. Is there any easy or little harder way to get desired smooth effect. Because without smoothing lines,it looks very ugly.
2  Game Development / Newbie & Debugging Questions / Re: [Java|Android|LibGDX|...] Mouse movement and collision detection on: 2014-02-22 12:56:35
Here is the flash video for better presentation how does the problem look like...

http://megaswf.com/file/2642304 (Click "Play flash full screen" for better view)
3  Game Development / Newbie & Debugging Questions / [Java|Android|LibGDX|...] Mouse movement and collision detection on: 2014-02-22 12:21:41
Hi everyone,

I have decided to make Air Hockey game. But I have already got into trouble. I am moving paddle with mouse that is cool. But when I am checking collision with middle line there is a problem. (2)On slow mouse movement collision works fine, but when moving mouse fast (1) collision is not detected well, because mouse move faster than paddle is rendered so paddle get stuck before middle. I have tried making game also in java without engines and it is the same, so here is the problem which I dont understand how to fix it? Any ideas?



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
... class public class MouseHandler implements MouseMotionListener
@Override
    public void mouseMoved(MouseEvent mouseEvent)
    {
        if (!(mouseEvent.getX() > panel.getWidth()/2 - paddle.getR()))
        {
            paddle.setX(mouseEvent.getX());
        }

        paddle.setY(mouseEvent.getY() - paddle.getR()/2);
        paddle.setR(panel.getHeight()/5);
    }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
... class Panel extends JPanel
@Override
    public void paint(Graphics g1) {
        ...

        g.setColor(Color.GREEN);
        g.fillOval(paddle.getX(),paddle.getY(),paddle.getR(),paddle.getR());
       
        ....
    }


// That is code from java but the similiar code I have in libGDX engine...

Regards
Jan
4  Game Development / Newbie & Debugging Questions / Re: How to run Applet outside NetBeans on: 2013-02-25 20:43:42

If you DO want to allow client access, you don't have to go as far as getting signing to work, but you will need JNLP and will have to go through steps of asking the client user to OK the access. Signing adds a level of security.


The applet is only asking me for permission to run it, than don´t ask me for any further permission, just throw error. My game is using API preferences for savegame and also is reading some text files,... So there is no problem how I run code in browser or appletviewer, it is the same,... Should I add some code for required permission or what?
5  Game Development / Newbie & Debugging Questions / How to run Applet outside NetBeans on: 2013-02-25 19:12:10
Hi,

I have problem with playing my Applet game. Currently I can run game only in NetBeans. When trying to manually run NetBeans generated file launch.jnlp there comes the AccessControlException error ("java.lang.RuntimePermission" "preferences").I was looking how to solve problem but I couldn´t find anything usefull. I am confused about this permissions, signing jars and so on... I cant understand how my mates will play my game if even I cant play it outside IDE.  Huh

Regards
Jan
6  Game Development / Newbie & Debugging Questions / Re: Java - Smooth tiles movement on: 2013-01-22 23:16:35
Thread.sleep cannot be relied on as a timing mechanism.

And what I should use instead?
7  Game Development / Newbie & Debugging Questions / Re: Java - Smooth tiles movement on: 2013-01-22 23:09:49
Hey. Now I have created new simple applet just for test(same structure like my game). And moving is same as my tiles.It is horible. So somewhere here in basic code is my problem.

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

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
public class game extends Applet implements Runnable{

    int x,y;
    public void init() {
        x = 0;
        y = 100;
        setSize(1280,560);
    }

private Image image;
private Graphics second;


@Override
    public void update(Graphics g) {
        if (image == null) {
            image = createImage(this.getWidth(), this.getHeight());
            second = image.getGraphics();
        }
       
        second.setColor(getBackground());
        second.fillRect(0, 0, 1280, 560);
        second.setColor(getForeground());
        paint(second);

        g.drawImage(image, 0, 0, this);
    }
   
    @Override
    public void paint(Graphics g) {
        g.fillRect(x, y, 80, 80);
    }
   
    @Override
    public void run() {
        while (true) {
            x += 10;
            if (x > 1280) {
                x = 0;
            }
            repaint();
            try {
               Thread.sleep(18);
            } catch (InterruptedException e) {}
        }
    }
   
    Thread thread;
    @Override
    public void start() {
        thread = new Thread(this);
        thread.start();
    }
}
8  Game Development / Newbie & Debugging Questions / Re: Java - Smooth tiles movement on: 2013-01-22 21:16:44
The moving speed should be a float value like 0.2f. To calculate the total moving amount, multiply the speed with the current frame delta:

1  
float speed = 0.2f * delta;


After that, you could move your tile (or game object, whatever) in any direction. After reaching the next tile cell, you can stop the movement (in a tile based map). Or how does your "tile" game look like?

Thank you guys for fast answers. I will try what you recommend. I don`t think the game lags. I paint only tiles that are visible in view field (1280x560) and tiles that positionX is smaller than 0 are removed and not updated. My game is a scrolling game.There is character on fixed location who is jumping,sliding and picking an objects on grid. Grid is moving left in negative direction.I tried also with removing a background, painting tiles like rectangle and make very small grid with only one visible object and is still the same, tiles are moving same way. My game structure:

In tile class is main constructor (public Tile() {}) where are defined positionX, positionY, speed and type (image) of moving object. Than there is a collision method and update method where I update position with
1  
tileX += tileSpeed;
(where speed is -10)

In main applet class there is an ArrayList for tiles and many methods. One of them is method which reads from txt file and create tiles. Than method for updating ArrayList of tiles and for tiles painting.

I dont have any FPS counter inside game, but FRAPS (tool for recording clips inside games) is showing me that in this applet FPS are between 109 and 111. With pause of 10ms i have 200 FPS and tiles are moving same way. It is not annyoing problem but still want to fix it. Cheesy

Tile move like: --------  Huh
I want: _____________  Smiley



9  Game Development / Newbie & Debugging Questions / Java - Smooth tiles movement [Solved] on: 2013-01-22 20:13:54
Hi!

I am developing my first game and all work perfectly except some moving tiles. I am moving tiles for 10px every 18ms. Moving and collision detection work fine, but movement does not look smooth. It looks like the tiles are jumping for 10 px and not moving smooth.If I set speed to 1px, is good but tiles are than moved too slow for my requirements.(Code is executed every 18ms)  The tiles are images but even if set them just like drawed rectangles it is the same. (So performance is not a problem but something else). I searched over internet for motion blur effect  but I could not find anything useful. Does anyone have an answer how can I fix this small problem about smooth moving?

Regards Jan
10  Game Development / Newbie & Debugging Questions / Ingame TextField on: 2013-01-17 19:52:05
Hi,

I am developing my first game and in settings menu I would like to have field where player will be able to change a name. I tried with JTextField but is not working properly, it is blinking because of updating game.I also tried with setIgnoreRepaint but did not work. Can you please tell me how can I fix the problem? My code looks something 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  
private JTextField player_name;

public void init() {
        .... more code ....
        player_name= new JTextField();
        player_name.setText("Player name");
}

public void paint(Graphics g) {

if (status == GameState.settings) {
           
            g.drawImage(submenu, 0, 0, this);
            player_name.setLocation(330,250);
            player_name.setSize(150,50);
            add(player_name);
           
            g.setColor(new Color(229,241,95));
            g.drawRect(330, 400, 140, 50);
            g.drawString("BACK",340,440);
           
        }

         .... more code ....
}
}



Regards Jan
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.

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

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

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

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

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

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

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

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

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
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!