I want to develop a java graphic application. The concept is that there will be a circle in the middle and several balls will rotate around the circle. Is it possible to make the circle stable forever and only change the position of balls? If it is, how? Also, Is it possible to get a circle or ball like a normal java object?
When I use repaint() method, all of the drawings are repeated. But I do not want to change the location of circle, I only want to change the position of ball that I need.
Thanks.
It is not a game, but you can use a loop of update-render-sleep.
https://www.google.pt/#q=java+game+loop
And as for the fact tht you want to mantain the balls, use math:
Where will the center ball be?
How much will the radius of the center ball measure?
And the others balls? How will they rotate? What is their radius? How many are they?
etc..
Answer this and many aothers to yourself, and make a bit of studies in internet.
I hope I could help you.
Related
I'm creating "tile game"
The question I would like to ask is: let's say that my map is gonna be 5000*5000 tiles and as you can see I already got some enemies there (two red piles-slimes :D) the problem is that I would like to have cca one enemy per 500 tiles so 5000*5000/500 which results in about 50000enemies which is impossible to render at once so I've got rectangle object which holds the actual screen that player can see and if the hitbox of the "slime" intersects the rectangle then Im rendering it, but the problem is that I still have to loop through each of those slimes to see whether their hitbox isnt in the screen rectangle after the player moved, is there anyone who ever had similar problem ? If so could you tell me your solution ?
but the problem is that I still have to loop through each of those
slimes to see whether their hitbox isnt in the screen rectangle after
the player moved,
Looping through some slimes when the player moves is normal or rather acceptable but looping through all slimes is not.
You should probably maintain a structure where you know for each tiles area the enemies that are present on.
A tiles area should gather a certain number of tiles but beware you should find/adjust its size to make it not too small (you lose interest of that as you have to inspect many of them) and not too big either (you will loop on many enemies that may be too far).
The overall idea is so checking the enemy presence only for tiles area close form the player. A structure such as Map<TilesZone, List<Enemy>> may make sense or maybe TreeMap<TilesZone, List<Enemy>> to benefit from NavigableMap interface that could be helpful in your use case.
I am making a 2D game in JavaFX and when detecting collisions, I am getting rather inaccurate results due to the player sprite being set as the fill of a rectangle and therefore not having the intended borders. Is there a way I could make my own shape so thatI could get as accurate as possible?
Another idea I had is checking if the pixel that collided was transparent and then not ending the game if it was. Does anyone know of a way I can get the coordinates of the pixel that collides so that from there I can use PixelReader to check?
If anyone knows a better way, please let me know!
Thanks,
Ethan
There are different ways to do this. Here is one way I have used with good success. I would make hit boxes, that were themselves rectangles. Then during collision detection, I would iterate through all the hit boxes to see if they collided with the flying projectile's hit boxes.
What this allows you to do is fill in complex shapes with smaller rectangles. For example a plane would have one long horizontal rectangle and one smaller rectangle crossing at the middle.
Currently I am using libGDX. In libGDX I use their Polygon object as stated here. https://stackoverflow.com/a/28540488/1490322 I have not seen similar functionality in JavaFX, but it would not be hard to copy what libGDX is doing into JavaFX code... their code is open sourced.
I'm new to libgdx and to game development in general. I'm trying to make a 2D game with libgdx on Android. For now, for detecting collisions I was using rectangles and the "overlaps" method, it worked very well. I now want to add very specific objects into my game that are randomly generated and with various shapes like circles, stars etc..
Can you guys help me find a way to detect these kind of collisions ? I heard about Box2D, should I use that ?
Thank you very much for your help !
I believe you can use the overlaps method with any polygon. You pass it in as an array of the vertices of the object.
So I had a quick question. I'm currently making a small game in java and I wanted to experiment with hiding the player behind fake 3D objects on the screen (Isometric drawing). Unfortunately I can't post a picture (Not enough rep). Basically it's a 3D block that is 32 by 48 that gives an illusion that it's 3D by having half of it a lighter color and the other half a darker one. The player is the same size as the block and can move freely around the map of these 'blocks'. If the player moves behind a block, it's bottom part is hidden behind it. The opposite when it moves in front, covering the non-player block. Now I made an example program in GameMaker Studio just to test it out. To make it work in GM, I made a script for each sprite that was one line of code:
depth = y * -1
This causes the bottom part of the player to 'hide' behind the blocks when it moves behind them. I looked into it a bit on GM's wiki and it's pretty much changing the 'depth' of the instances. Now my question is, how would I do something like this in Java?
P.S. This is not in a diamond. It is in a straight 2D world (looking 45 down towards objects from front).
EDIT:
Here are some pictures of the GameMaker version:
Player Outside
Player Inside
Read about drawing isometric worlds.
Read about Java and isometric development.
Thanks to Kayaman for solving the problem:
If you draw your player first, then a wall on the block south of it, the top half of the wall will mask the bottom half of the player. So no, you don't need to draw halves separately. This means of course that you need to draw the player at the same time as the map, so you can't first draw the map and then the player.
Just for future use, layering images in java is determined by the order in which they are added. This was the exact answer I was looking for. The GM code was GameMaker's way of setting the order in which the images were added to the screen.
Thanks to everyone for the help!
Here is my problem,
I have 2 rectangles.
I want to detect collision between these 2 rectangles.
However one rectangle should be able to rotate around a given position(player midpoint,not constant).
My Problem is, that i don't know how to rotate this one Rectangle.
I would be grateful for any help.
Here is a sketch of my problem:
for a simple collision detection I had always rectangles:
playerrect = new Rectangle(playerposition.x,playerposition.y,playersizeX,playersizeY);
enemyrect = new Rectangle(enemyposition.x,enemyposition.y,enemysizeX,enemysizeY);
and this;
if(playerrect.overlaps(enemyrect)){.....}
and this was enough for me.
This time this noob needs the playerrect at various angles, like 5°,10°,15°.....
So I need something like
playerrect.setRotation
which is not available :).
Libgdx Rectangle can't do that unfortunately. If you want that kind of collision detection, the easier way would be using Box2d.