Andengine sprite touch event on layers - android

I am developing a game using AndEngine in which on the game screen i have 2 layers - backlayer and frontlayer. On the backlayer i have attached 1 player sprite and several baddies sprite. On the frontlayer i have attached a tree sprite. Now what i want is that the baddies move around the screen in a zig-zag way throughout the game and when the user touches the baddie, they will be popped(disappear/detached) but when they go behind the tree they should not be popped when the user touches the tree on the area where baddie is but not visible.
I have transparent background for the image of tree and since there are several region in the tree where there are no leaves so that area is also transparent and the baddies are visible in that region and also they can be popped in that region.
I am done with all the stuffs, only the problem I face is baddies are popped even when they are behind the tree and not visible to the user.
Kindly please help me...

If you know when they are back in the tree, then disable the touch area for that sprite or do nothing when touched if they are back.

You can make use of PixelPerfectSprite where it will return true only if you are touching the tree, and will return false if you are touching in between leaves (i.e in transparent region)
After this if your fingure is colliding with tree as well as your character then don't pop up else if it collides only character then pop up

Related

How can I stop input from registering inside my game when I am dragging status bar from the top?

Basically on newer phones such as the ones with the notch at the top I have been able to play games where I swipe the top of my screen to access the status bar without any input impacting my game.
Games such as Circle and Jelly Jump) are examples that do this.
I basically want a similar sort of thing. Right now when I drag down my status bar from the top, my game ends up activating which is something I don't want.
My code to start the game is upon a very simple mouse down input which also registers as a touch on phones:
if (Input.GetMouseButtonDown(0))
{
Jump();
}
An example of what I want can be shown via this diagram I've
drawn here.
You could have an invisible UI panel in that area and then check using EventSystem.current.IsPointerOverGameObject() to check if the click/touch is over an UI element. Not that for touch, the function is IsPointerOverGameObject(touchID). Also you will need a graphic raycaster attached to the canvas.
Another option would be to check the x/y value (depending on orientation) of the touch position and to only register input if it's above a certain value.
if(Input.GetTouch(0).position.x < 20) return

OpenGL sprite looses focus on fast move

I'm making simple app where user can move squares with finger on screen. First I'm checking if touch coords are on square to allow the move. Then square is moving along GLSurfaceView#onTouchEvent event coordinates.
It works OK. But when finger is moving too quick (like swipe) square looses the focus and stays still. It seems that OpenGL renders square after the move event occurs, so coordinates check fail.
Please point some keywords to figure out the question (googling gives same links again and again) or some docs. Thanks.
You need hold focus on sprite. If sprite got event "down" it holds focus until doesn't get "up" or "cancel" event. So, while sprite holds focus all touch events send to it.

Moving, clickable, rectangle animation

I've searched and searched, but couldn't find what I was looking for...
There are many ways to animate in android and being a newbie I do not know which solution to choose for my app.
Here's what I want to do:
It's an animation of rectangles moving slowly (takes ~10 min to cross the screen) from top to bottom through the screen.
Each and every one of the rectangles is clickable, through some listener, and does something.
Two or three buttons at the bottom of the screen (which I already created as floating action buttons) do not move and float "on top", i.e. the moving rectangles pass underneath them as they move down the screen.
The animation can be stopped and then resumes by the action buttons mentioned above.
Newly appearing rectangles appear on top as they " emerge" slowly from the top of the screen, i.e. when part of them is still outside, as they reveal themself by moving down.
I want this to be simple and robust.
How should I implement this, and please explain why...
As a loop?
A separate thread? Of so how?
I would like to understand the rationale behind every approach...
Thanks,
Julius

Implementing wheel shaped interface navigation tool

I am interested in implementing a user interface navigation control mechanism based on a wheel shaped device (or pie chart shaped or circle shaped) in my Android app.
I would like only half of the wheel to be visible at any time. That is, only the top half of the wheel should be visible since the bottom half should be below the border of the screen. The user can then turn the 'half wheel' to show options hidden by the screen border. The visible top half should then be divided into three parts like a pie chart, so the user can press either one of them to invoke some action. The following pic should explain (it is an example with seven (A-G) options).
http://imgur.com/lNu1F
The rotation itself should not be hard, but I am having a hard time understanding how to position the wheel so that half of it is outside the actual screen. I am thinking that loading the entire wheel (but hiding half of it) is best, since that is that graphics I have and it will also allow a smooth animation when the user swipes to show some other options. How can I make Android show the wheel in this way?
Also. Any comment on how to implement the 'swipe along the wheel shape' would be appreciated.
Thank you.
So for the wheel - you are hving trouble knowing how to position the wheel because you are using XML to align you objects and would like to use something like "Align Object Center To Bottom" which does not exist.
Here is one approach that might work fine: Mask the wheel view.
Is it possible to mask a View in android?
As for swipe the wheel along, I would register the wheel to take touche events, and use only the horizontal componenet of move events to apply to the rotation of the wheel. This setup is common in audio software that uses knobs.
However if you want to have it stick to the users finger in a more realistic fashion, you will need to do the following:
When the user first touches the wheel, calculate the angle from the wheel center to the finger.
Every time the finger moves, check the angle from the wheel center to the finger - and rotate the wheel the amount that the angle has changed from the last touch event.
The formula for getting the angle between two points is this:
Float angleInRadians = Math.atan2(point1.y-point2.y, point1.x-point2.x);

I need to move an image dynamically,depending upon the input from the user..What should i use?

Depending upon the user i may need to move it to right ,left,top or bottom.
Should i use animation for the purpose?
Or is there any method to move image dynamically?
I meant the things in android application
You use animation for a movement that has a distinct start and stop point. For example you might move the image right to left at a button push. It would slide a cross the screen and then appear back at its original position.
If you wanted to move things around this way you could do so by having 2 (or more) copies of the same view.. hiding the view at the old position and showing it again at the new one. You generally won't be stopping this animation between its begin and end point.
If you want some more interactive movement (say move along with the user's finger on the screen), you'll need to make use of the canvas and some touch listeners. In that case I recommend looking up drag and drop samples as they address what is needed for this to happen (and then some).

Categories

Resources