AndEngine - handling touches multiple sprites in a single area - java

This is for a game I'm building where sprites are constantly overlapping since their spawn locations are randomly generated. The player must tap some sprite at a certain time. The problem arrives if the they need to tap the bottom sprite of 2 or more overlapping sprites. The touch is only registered for one of the sprites which makes the game impossible sometimes.
Is it possible to get an array of all sprites in the touch location?

Nevermind I figured it out. I just had to set the return value of onAreaTouched to false.
As soon as a sprite's onAreaTouched returns true, the touch event ends.

Related

Slowing the Move of an Object in a For Loop Java

I am currently working on a project that moves a circle from a space to space when button is pressed. I designed as following: When the button is pressed, it increments the coordinates of circle, in a for loop from 0 to 10.
The problem is, the motion I wanted with for loop doesn't show up on the screen but it only shows the object on the first and the last coordinates, so it doesn't move one by one.
Any suggestion would be appreciated,
Kutay Demireren
You need to set a frame draw length that the human eye can see in order for motion to work properly. The can be achieved in many ways, but the easiest is with a thread.sleep at the end of each for loop iteration for however long you want the different pictures to be visible for.

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

Rotate a triangle polygon according to mouse position?

I'm coding my own multi-player game in Java; I'm in need of help with rotating a triangle polygon according to the mouse position. I have this triangle, which represents the character, the player can click the right mouse button, and a bullet will fire from the top of the ship (which ever point I assign to be the top), but I want the rotation of the player(triangle), for aiming and such, to be controlled by the mouse and where it lies on the screen. How can I go about doing this, and I want to show an animation also of it rotating in respect to where the mouse is, not just appearing there.
Extra:
One more thing, after that, I'm most likely going to want to have the mouse locked to the screen, so that it won't trail off. How can I lock the mouse to the center of the screen?
I'm using the drawPolygon method from java.awt.Graphics, maybe this is the best way?

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