JavaFx Help of animation - java

I have been doing some coding with JavaFx. I am still pretty new to JavaFx and just can't figure out how to do this. I am trying to build a game where the player has to dodge enemies. I was trying to make an animation where the enemies are coming down from the top of the screen to the bottom and a new enemy spawns after one of the other enemies go to a certain part of the screen. I want to make it that these enemies can change their speed after a certain time. For a summary, I want to do an animation that suits these features:
Able to go from one point to the other
speed is changeable
Able to check the position in the middle of the movement
I have tried TranslateTransition and an AnimationTimer but they don't get to a high enough speed or I can't find the position in the middle of the movement.
Actually, Can I also get an explanation on how interpolate works on translateTransition.

Related

Stage is bigger than the screen in LibGDX, how to fit it in the screen?

I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.
I'm using an OrthographicCamera and an ExtendViewport.
I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...
I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.
FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.

LibGDX make the world move and the player not

I'm working on a simple game with libGDX and want to make the main character to be fixed in the center of the screen and the world move when I press a button. I was wondering how to do... I was thinking to add a physicsBody to the world that contains other bodies and apply impulses to it when the button is pressed, is this possible in libGDX? And if it is, can i apply other impulses or forces to the bodies contained in the world's physicsBody? I think this way would be the best for me if it is possible, because i have to work a lot with physics, but if you have other ideas tell me please
There's no need to think about applying forces to all the non-character objects, that's just going to get messy very quickly.
The simple solution is to move your camera so that it always looks at your character. So your game loop may look something like:-
Process input
Update physics, character and other entity positions.
Move camera to point at character's new position.
Render
This way, you can update your game world without having to think about the camera at all. Then, when it comes to rendering, you can position your camera and render your graphics without needing to know anything about the game physics. It keeps the physics and rendering relatively independent, and makes it much easier to change things in the future.
For example, you may later decide that you want the camera to follow your character for the most part, but then follow a baddy whilst it is their turn. This is now easy to do, you just specify the character / entity to look at in your game logic, and then position the camera to look at whatever target that is, before you render.

Sidescroller game with libgdx / Box2D with moving floor instead of moving player

I'd like to write a sidescroller game with libgdx and Box2D.
But instead of the moving the player and the camera to the right, the player should stay at his position and the floor should move to the left. Crates should be placed randomly and move from the right to the left of the screen as well. In addition the player should also be able to move to the left and the right of the screen without the game stopping to scroll the level.
I have no problems with using libgdx or Box2d but I'm not sure what is the best way to achieve my goal. I'd like to use physics because I will also have some bouncing balls etc. in the game which should show a physically correct behaviour and should interact with the player.
I have some ideas how to solve my problem:
Apply constant force or velocity to the floor and the crates which pushes them to the left and apply a counter force to the player so it stays at his position. When pushing the left or right button to move the player the counter force is slighty enhanced or decreased.
(As physic simulation is not 100% percent accurate I'd like to avoid this)
Move the position of the floor, player and crates but this would subvert the whole physics thing.
Use physics for anything but the player and move him directly. Therefor I'd have to do any collission detection by myself
Unforunately I'm not happy with any of these solutions. Has anybody faced a similar problem or has any advice how to solve this problem in an elegant way?
Many thanks in advance.
I recommend you to create two separate cameras: for player and for ground(floor).
Such way you will be able to move your "ground camera" as you want, the player will stay on his position. Then just don't move your player camera, move only the player body ,such way you will get effect of racetrack.
I use 4 cameras on my game (for ground, for player, for HUD and for background) it provides you lots of fixability and you can create cool scrolling effects.

Force Box2D object to stay still over a rotating object

I'm trying to use Box2D in my game but I have a problem with one particular player movement. I have two different objects. The first one is a rectangle with fixed rotation that represent the player. The other one is an octagonal wheel that can rotate and moves from right to left and viceversa.
When the player is over the wheel the user can swipe to let the player run over the wheel. In that moment the wheel start to rotate and the player object should stay over the wheel while running. The problem is that the friction makes the player fall. I tried to remove the friction of the player and reset the contact friction while running but still fall because the linear velocity of the player while the wheel is moving from side to side.
My last attempt to solve it was use setLinearVelocity(0, 0) over both bodies at the beginning of the run movement but doesn't work very well...
So the question is, how can I force a Box2D object to stay over the wheel while this one is rotating and moving?
One way is faking it..... Just keep on resetting the position to intial position....
Other way is to create an invisible weld joint of the player to some other point.
I hope it helps

collision & touch + shoot methods for Android

I really need help. I am making a game app for my final year project. It is a simple game where you have to shoot a ball into a target by rebounding of walls or angled blocks. However i need help in 2 areas:
the shooting mechanism is similar to that of stupid zombies. There is a crosshairs where you touch on the screen to indicate which direction you want the ball to be shot at. On release the ball should move into that direction and hopefully gets into the target and if not gravity and friction causes it to come to a stop.
The problem is how do I code something like this?
I need the ball to rebound of the walls and I will have some blocks angled so that the ball has to hit a certain part to get to the target. The ball will eventually come to a stop if the target is not reached.
How can I make a method to create the collisions of the wall and blocks?
I have spent the last weeks trying to find tutorials to help me make the game but have not found much specific to the type of game I am making. It would be great if sample code or template could be provided as this is my first android app and it is for my final year project and i do not have much time left.
Thank you in advance
akkki
Your question is too generic for stack overflow no one is going to do your project for you. Assuming you have basic programming experience if not get books and learn that first.
Assuming you already chose Android because of your tag, and assuming 2d game as it is easier.
Pre requests:
Install java+eclipse+android sdk if you havent already.
Create a new project and use the lunar landar example, make sure it runs on your phone or emulator.
Starting sample:
The lunar landar has a game loop a seperate thread which constantly redraws the whole screen, it does this by constantly calling the doDraw function. You are then supposed to use the canvas to draw lines, circles, boxes, colours and bitmaps to resemble your game. (canvas.draw....) Lunar landar does not use openGL so its slower but much easier to use.
Stripping the sample:
You probably don't want keyevents or the lunar spaceship!
Delete everything in the onDraw function
Delete the onKeyUp, onKeyDown
Delete any errors what happen
Create a new
#Override
public boolean onTouchEvent(MotionEvent event){
return false;
}
Run it you should get a blank screen, this is your canvas to start making your game... You mentioned balls, break it down to what a ball is: A position and direction, create variables for the balls x,y direction_x and direction_y the touch event will want to change the balls direction, the draw event will want to move the ball (adding the direction x,y to the ball x,y) and draw the ball (canvas.drawCircle(x,y,radius,new Paint())) want more balls search and read about arrays. Most importantly start simple and experiment.
2 collisions
Collisions can be done in the dodraw function and broken down to: moving an object, checking if that object has passed where it is supposed to go and if so move it back before anyone notices.... There are many differently techniques of collision detection:
If your walls are all horizontal and vertical (easiest) then box collisions checks the balls new x,y+-radius against a walls x,y,width and height its one big if statement and google has billions of examples.
If your walls are angled then your need line collision detection, you basically have a line (vector) of where your ball is heading a vector of your wall create a function to check where two lines collide and check if that point is both on the wall and within the radius of your ball (google line intersection functions)
or you can use colour picking, you draw the scene knowing all your walls are red for example, then check if the dot where the new ball x,y is, is red and know you hit
Good luck, hope this helped a little, keep it simple and trial and error hopefully this gets you started and your next questions can be more specific.

Categories

Resources