Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
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 3 4
1  Java Game APIs & Engines / JInput / Disconnect and Reconnect GamePad using JInput on: 2020-01-16 04:28:44

 i am using Jinput with no issues so far, i struggled but the events are now working, however i am trying to make some disconnecting / reconnecting, i have the code that must work, but if i start the app without the GamePad connected there is no possibility to make it work it only works when the gamepad is connected and then start the application ( in this case a game ), if while the game is running i disconnect the device i could stopped the POLLING event, however when i try to reconnect the device again there is no possibility to reconnect it to the game, the poll message "Failed to poll device" is always present, even if i am restarting and trying to find the connected devices again.

any idea with this?

when the device is disconnected i started again to find the connected devices with:
1  
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();


but this does not work once the device is disconnected while the app is running, i have to restart the app to make it work again
2  Java Game APIs & Engines / JInput / Re: Jinput Analog X, Y, Z Axis input noise on: 2019-07-31 18:36:50
no problem, on PS4 triggers act like button but at the same time as analogic input, I've tested Xbox one and PS4 controllers, however where I have the issue is with the threshold but I kinda could fix this all values between -0.35 to 0.35 will be ignored, however when the X AXIS or Y AXIS are 1 or -1 the process is stopped, I mean when I reach those values I can't get more events from jinput, dunno if that is normal, gonna make more testing on it today, thank you.
3  Java Game APIs & Engines / JInput / Re: Jinput Analog X, Y, Z Axis input noise on: 2019-07-30 20:56:16
sure, thanks, that can work, I could make it work with DPAD and buttons, but I haven't make the analogic work yet.
4  Java Game APIs & Engines / JInput / Jinput Analog X, Y, Z Axis input noise on: 2019-07-29 04:10:39
Hello, 2 days ago i implemented JInput and mapped all buttons, DPAD and different AXIS, but i am having issues with Analogic AXIS, for example: when i move the stick on Y AXIS i am also having events on X AXIS, so when i try to move the player on Y AXIS is moved as well on X AXIS because of that.

what is the best approach to prevent this?, i am using Jinput 2.0.9 btw, horseman obviously.
5  Java Game APIs & Engines / JavaFX / Re: JavaFX blend effect using only one node (canvas) on: 2019-07-19 16:14:22
I remember someone says that canvas or graphics context was powerful enough, however did not wanted to make another library like Almas is currently doing, I handle the opacity with alpha property pretty well, however when I want to change the color sprite for something red or yellow ( when I hit the sprite ) I think it can be done with blend, I was setting the blend effect to canvas but everything is a single node or a sole canvas in this case, so the blend effects don't overlap 2 nodes like the other examples have.

what I what to achieve for now is blend the sprite with some specific color and put a black surface on top and then make the effect of a flashlight just to make transparent the part where the flashlight is, I was thinking to create a black rectangle, put the flashlight on top, and with the pixel writer of the canvas make all flashlight pixels transparent, but I think that can be overwhelming.
6  Java Game APIs & Engines / JavaFX / JavaFX blend effect using only one node (canvas) on: 2019-07-18 05:12:36
Hello everyone, its me again after a year, so i made progress using JavaFX for game Development as hobby, and basically what i am doing is putting a canvas in a node and that node in the stage, all the game is processed on that canvas, however, i would like to implement some blend effects, but so far all examples that exist online are using different nodes, does anyone knows if its possible to use blend using a sole canvas ( node ) instance?, i tried to make this with no result until now, thanks in advance.
7  Game Development / Shared Code / Utility Functions for JavaFX Game Development ( lerp, clamp, etc, etc ) on: 2019-07-18 05:07:38
i dont know if there are something like this in the forum( just let me know in that case ), here are some functions i created for a project i am working and are usefull for game dev, i am using JavaFX with Canvas only, dunno if they work on swing, any CC or sugestion will gradly received

CLAMP
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
/**
 * if value is mayor than max value, max value will be returned,
 * if value is minor than min value, min value will be returned,
 * if value is in range between mayor and minor values, then
 * value will be returned
 * @param value
 * @param minValue
 * @param maxValue
 * @return value will never falls below minValue or goes over maxValue
 */

public static float clamp( float value, float minValue, float maxValue )
{
    // value must be between minValue and maxValue
    return (value > maxValue) ? maxValue : (value < minValue) ? minValue : value;
}


LERP
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
/**
 * this function creates linear interpolation depending on argument t,
 * which is the percentage of v0 until v1
 * @example lerp(0, 10, 0.5): will return 5.0, because is the middle ( 0.5 ) between 0 and 10
 * @param v0
 * @param v1
 * @param t
 * @return
 */

public static float Lerp(float v0, float v1, float t)
{
    return (1-t)*v0 + t*v1;
}



LENGHT_DIR_X
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
/**
 * returns X position of the vector determined by length and angleDirection
 * <b>NOTE: you must add to this value to originX where will be added this vector
 * for example sprite.getX()+lengthdirX( 100, 45 )</b>
 * @param length
 * @param angleDirection
 * @return
 */

public static float lengthdirX( float length, float angleDirection )
{
return (float)Math.cos( angleDirection * (Math.PI/180) ) * length;
}


LENGHT_DIR_Y
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
/**
 * returns Y position of the vector determined by length and angleDirection
 * <b>NOTE: you must add to this value to originY where will be added this vector
 * for example sprite.getY()+lengthdirY( 100, 45 )</b>
 * @param length
 * @param angleDirection
 * @return
 */

public static float lengthdirY( float length, float angleDirection )
{
return (float)Math.sin( angleDirection * (Math.PI/180) ) * length;
}

8  Game Development / Shared Code / take screenshoot with JavaFX on: 2019-07-18 05:01:07
just recently implemented this in some project i am working, there are some examples of this in stackoverflow but not especifically with a canvas ( i am not 100% sure about that), when this method is called it will create a  UUID.png file on the root of the project, any CC or sugestiong will be gladly received.

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  
/**
 * this takes an snapshoot of the current game and is stored on the
 * root where the game resides in PNG format
 * @param  canvas
 * @param width width of the image
 * @param height height of the image
 */

public static void takeSnapshot(Canvas cnavas, int width, int height)
{
    WritableImage wim = null;//new WritableImage(width, height);
   
   try
   {
      String fileName = UUID.randomUUID().toString();
   
      File file =  new File( fileName+".png" );
      wim = gm.snapshot( null, null );
      ImageIO.write( SwingFXUtils.fromFXImage( wim ,null ), "png", file );
     
   }
   catch(IOException ioe)
   {
       System.err.println( "::: error when creating snapshot "+ioe.getMessage() );
   }
}//
9  Java Game APIs & Engines / JavaFX / Good GameLoop for JavaFx AnimationTimer on: 2018-09-12 17:18:11
hello, im using javaFX AnimationTimer for my game loop, i would like to know if there is another way to improve it, docs say that AnimTimer will run at 60 FPS or will try, below is my gameloop:



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
 gameThread = new AnimationTimer() 
        {

            @Override
            public void handle( long now )
            {
                //not to run if level is nul
                if( null == currentLevel ){return;}
               
                //getting delta
                delta = ( float ) ( ( now - pastTick ) / 1e9 ) ;
               
               update( delta );
               render();
               
               pastTick = now;
               
            }//
           
        };
10  Discussions / Miscellaneous Topics / Re: Using Math in Java FX is ok? on: 2018-08-29 14:56:40
I was looking yesterday and found two options:
1.- JAFAMA
2.- apache FastMath

I will do little research and will check LIBGDX math as well, however libgdx math should be better option due is for a game library/emgine
11  Discussions / Miscellaneous Topics / Using Math in Java FX is ok? on: 2018-08-28 15:29:37
hi everyone, I know there are other game libraries that use fast Math classes, I use common Math class, so my question is:

is ok if we use Math class, or do I need to look for a FastMath library to use it in my projects?
12  Game Development / Shared Code / get SubImages in JavaFX on: 2018-08-25 19:24:23
we dont have a specific way to get subimages in JavaFx like we had in Api2D with ImageIO, however i paste this code here so you can transform an image strip into an array of images:

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  
/*
suppose i have an image strip of 10 frames of 32x32 ( 320x32 ), then i want to separate all frames in individual images
getImage( 10, 32,32,"myStrip.png" );
*/

public static Image[] getImage( int frames, int w, int h,  String pathFile )
        {
           
            Image[] imgs =  new Image[ frames ];
           
            //img that contains all frames
            Image stripImg = new Image( pathFile );
            PixelReader pr =  stripImg.getPixelReader();
            PixelWriter pw = null;
           
            for( int i = 0; i < frames ; i++)
            {
           
                WritableImage wImg = new WritableImage( w, h );
           
                pw = wImg.getPixelWriter();
               
                for( int readY = 0 ; readY < h; readY++ )
                {
               
                    int ww = (w * i);
                    for( int readX = ww; readX < ww + w; readX++ )
                    {
                        //get pixel at X  & Y position
                        Color color = pr.getColor( readX, readY );
                       
                        //set pixel to writableimage through pixel writer
                        pw.setColor(readX - ww, readY, color);
                       
                    }//X
                   
                   
                }//Y
               
               
                //finally new image is stored
                imgs[ i ] = wImg;
            }//
           
           
            stripImg = null;
            pr = null;
            pw = null;
           
        return imgs;
        }//
13  Java Game APIs & Engines / JavaFX / GraphicsContext(FX) vs Api2D on: 2018-08-15 21:10:55
I've been hearing a lot that JavaFX is faster that 2D, however I would like to know what are the advantajes that graphicscontext have against Api2D?
14  Game Development / Articles & tutorials / Re: Getting Started with JavaFX Game Programming (for Java Programmers) on: 2018-08-07 17:23:47
just was thinking to mess a little with JavaFX due API2D is to slow if you run the game in mac or ubuntu, and just find this tutorial, I think is great one, but should be good if you teach us how to put all the logic on another class, or using the context object to draw like a canvas. don't know just suggesting and keep with your awesome work, do you have any youtube channel for this?
15  Games Center / WIP games, tools & toy projects / Re: Katt - Run on The Tide on: 2018-06-20 15:29:45
i have been waiting for this game to be finished, anybody knows how this is going?
16  Game Development / Newbie & Debugging Questions / Re: Game running slower with many objects on: 2018-06-12 20:15:36
so, it means if we are using 2D and we use JOGL instead that will make us to have a better performance in our game?
17  Java Game APIs & Engines / Java 2D / Re: Image vs BuferedImage on: 2018-05-18 18:37:24
that javaFX sounds great, i will take a look at it, however i pretend to use the game created in a Raspberry PI, and only works with Java2D cuz javaFX was removed.

so if there no performance issues i will leave the code like i have it, if they are sub classes that should not impact on the render method.
18  Java Game APIs & Engines / Java 2D / Image vs BuferedImage on: 2018-05-18 17:44:34
hello guys, i have an implementation of Image when i draw sprites, however i have been reading the use of buffered images, i would like to know if there are some performance issues if i use Image over Buffered images or what is the most convenient way to draw images?
19  Java Game APIs & Engines / Java 2D / Re: best way to draw tiles in java 2d on: 2018-05-15 14:57:37
thanks for your reply. actually i have been using two tilemaps, one for rendering the whole level and another to make solid tiles and slope tiles its working, but the issue comes when you want to have big levels i want to mitigate somehow the over process.
20  Java Game APIs & Engines / Java 2D / best way to draw tiles in java 2d on: 2018-05-11 17:10:12
hello guys, i was wondering what is thebest way to cerate a tiled level, for example i have:
 
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  
int [] tileMap = {
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,2,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   
     0,0,0,0,0,0,0,2,0,0,1,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,2,0,0,1,1,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,2,0,0,1,1,1,0,0,0,3,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     };


where 1 & 2 are diferent platforms, 0 are blank spaces, i have an image strip with 3 tiles.

the way im creating my tiled level is iterating above array and draw each image in the correct position, however im wondering if this is the correct way to do it i dont know if tiles work in the same way at this behind the curtain, can some one give some tips of how can i improve this, thanks in advance.
the method im using to draw those tiles is 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  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
public void drawBgTile(Graphics2D g2,Image[] img, int[] map,int cols, int rows, 
            int tileWidth, int tileHeight)
    {
        if( cols <=0 || rows <= 0 )
        {return;}
       
        int mapIndex = 0;
        int totalTiles = cols*rows;
       
        int width = tileWidth;   //img[0].getWidth(this);
       
        int height = tileHeight; //img[0].getHeight(this);
       
        int offsetx = cam.getOffsetX();
        int offsety = cam.getOffsetY();
//        int tilewidth=Config.TILE_WIDTH;
//        int nodib=0;
       
        //renglones
        //rows
        for(int i=0;i < rows;i++)
                {
                        //columnas
                        //columns
                        for(int j=0;j < cols;j++)
                        {
                         //checamos si el tile esta dentro de los limites de la camara
                         //si no lo esta, entonces no lo dibujamos
                           
                         //if tile is inside camera limits then is rendered otherwise
                         //not , this save a lot of process
                         if( j * tileWidth  > offsetx - tileWidth
                           && (j * tileWidth) + tileWidth < offsetx + cam.getViewWidth() + tileWidth
                           && i * tileHeight > offsety - tileHeight
                           && (i * tileHeight) + tileHeight < offsety + cam.getViewHeigth() + tileHeight)
                         {
                         if( map[ mapIndex ] != -1 )
                            g2.drawImage( img[ map[ mapIndex ] ], width * j, height * i, null );
                         }//if validacion si se dibuja
                             
                          if(mapIndex < totalTiles)
                             mapIndex++;
                        }//for cols
                }//for rows

       
    }//


PD: im only drawing tiles that are inside cammera offsets
21  Java Game APIs & Engines / Java 2D / Re: improving game loop on: 2018-04-06 14:52:23
thank you i will try to implement that,

 delta is inside client.update( /*HERE*/)?

and render is after update?
22  Java Game APIs & Engines / Java 2D / improving game loop on: 2018-04-05 15:16:33
hello guys, i am using below game loop for a long time now, i want to now if this is a correct approach or if i can improve a little bit more,
i would like to add a delta to update method but i dont know how that will impact



 
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  
[code]public final void run() 
    {
     
    long lastTime= System.nanoTime();
    double amountOfTicks=60.0;
    double ns= 1000000000 / amountOfTicks;
    double delta=0;
    long timer= System.currentTimeMillis();
//    int frames=0;
    while(running)
    {
   
        if(!pause)
        {
       
                long now= System.nanoTime();
                delta+=(now - lastTime)/ns;
                lastTime = now;
                while(delta >= 1)
                {
                   
                update();
                //render();
                delta--;
               
                }
               
                if(running)
                    render();
               
                //codigo para checar los frames
                frames++;
                if(System.currentTimeMillis() - timer > 1000)
                {
                timer +=1000;
                //System.out.println("FPS: "+frames);
                frames=0;
                }
             
               
        }//
               
    }//uail
[/code]
23  Game Development / Newbie & Debugging Questions / Re: Reactive Games? on: 2018-03-27 18:09:51
we have other libraries in java like Java Rx, spring 5 with react components, but i think this is due web development was more stateles, i think a game is reactive in nature, because all sprites for example have a reaction between them.
24  Game Development / Newbie & Debugging Questions / Reactive Games? on: 2018-03-27 17:15:32
i have been noted since last year, that today there is a trending topic called React, reactive, most for web development,

how can be react approaches be applied to games, or can we say that GAMES are REACTIVE BY NATURE?
25  Game Development / Newbie & Debugging Questions / Re: Does processing is using Java 2d api or open GL? on: 2018-03-22 15:35:53
thanks, my IDE is Netbeans, and i want to use with it, seems interesting maybe i can use processing rendering powers indise my application, thanks guys you helped me a lot.
26  Game Development / Newbie & Debugging Questions / java 2d Game its working in windows but on mac or linux is slow on: 2018-03-21 15:58:27
hi, i have some game structure im using, when i run the game for testing purposes, run smoothly in windows, but when i run it on linux, the laptop almost freezes everything, in mac is working but i can see the drop rate. i dont know if that is normal or if is because of different hardware.
27  Game Development / Newbie & Debugging Questions / Does processing is using Java 2d api or open GL? on: 2018-03-21 15:55:29
i would like to use processing as render template to see how it works, but if is using java 2d and am already using that, then i think wont be much useful.
28  Game Development / Newbie & Debugging Questions / LIBGDX on: 2018-03-09 02:21:17
i have been reading about libgdx and seems to be the better option to me ( i was about to use godot and libgdx, cause im moving from game maker studio 2, im a java developer so i had to choose between libgdx), so, the main class should be a GGAME, that game should have Screens, screenes is where each level reside, but there is another approach called Scene2D, bassically is to add an Stage and actors to a screen, so, my question is, what advantage have Stage over screen, what if i dont use Stage or actors, but screen and sprites?
29  Game Development / Newbie & Debugging Questions / collisions inside view near the player on: 2017-09-11 16:42:59

 I have a function to check collisions between the player and the tiles, im creating stages with tiles,  if the stage its too large then im only checking collision with those tilles are inside the view ( to not to check the whole bunch of tiles along the stage ), but I was reading about quadthrees collision, but instead to divide that view in 4 internal rectagles what if I create a rectangle area that its surrounding the player, then check only the collision that are inside that rectangle meaning that those tiles are about to collide with player?
30  Game Development / Shared Code / take ScreenShoot on: 2017-09-05 15:26:53
thiss code is used to take an screen shoot and save it on project path ( or .jar path)

* it only save PNG format files
* it implement getEpochSeconds to avoud repeated names
* tested on windows 10

PD: if you have any way to improve, this let me know...

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  
/** 
395      * this method is used to take an screen shot of the game
396      * NOTE: fileName is the name of the screenshoot saved, it have
397      * the next format fileName[epochseconds].[extension], i suggest to
398      * pass on the fileName the name of the game
399      * @param w
400      * @param h
401      * @param fileName this is the name of the new screenshot + seconds + png  
402      * @return  
403      */

404     public static boolean takeScreenShoot( float w, float h, String fileName )
405     {
406      
407      
408         try  
409         {
410         Robot robot = new Robot();
411              
412         String format = "png";
413 //        String pictureName = fileName + ( Instant.now().getEpochSecond() ) + format;
414          
415         StringBuffer sb = new StringBuffer();
416         sb.append( fileName );
417         sb.append( Instant.now().getEpochSecond() );
418         sb.append( '.' );
419         sb.append( format );
420          
421         Rectangle screenRect =  
422                     new Rectangle( ( int )w, ( int )h );
423          
424         BufferedImage screenFullImage =  
425                     robot.createScreenCapture( screenRect );
426          
427         ImageIO.write(  
428                 screenFullImage,  
429                 format,  
430                 new File( sb.toString() ) );
431          
432              
433         return true;    
434         }  
435         catch (AWTException ex)  
436         {
437             Logger.getLogger(
438                     Util.class.getName()).
439                     log(Level.SEVERE,
440                             null,  
441                     "::: error when trying to take screenshoot "+ex );
442         } catch (IOException ex) {
443             Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
444         }
445          
446          
447          
448         return false;
449     }//
Pages: [1] 2 3 4
 
Riven (847 views)
2019-09-04 15:33:17

hadezbladez (5795 views)
2018-11-16 13:46:03

hadezbladez (2603 views)
2018-11-16 13:41:33

hadezbladez (6211 views)
2018-11-16 13:35:35

hadezbladez (1499 views)
2018-11-16 13:32:03

EgonOlsen (4734 views)
2018-06-10 19:43:48

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

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

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

nelsongames (5501 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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