Android - Tracking Real-Time Touch Events to Draw - java

I need your help.
I am trying to implement a paint system with live-tracking, you may think: “Live-tracking? What do you mean?”
So I am implementing a solution to track each touch movement on the display, so I can decide, if I want to paint on a specific spot or not, this decision must be in real-time, right when the user touches the display.
There will be some images where the user should paint the inner white space inside of the respective shape; figure 1 shows an example of this shape.
The user should paint the inside of the shape in a specific direction/order; I still don’t know how I can configure this order/direction in the image. An example of a specific order would be like the one showing on figure 2.
So I want the user to paint starting from the zone 1 to the zone 6, do you understand? I don’t want the user to be able to paint the zone 1 and then zone 3, without painting the zone 2 first…
In the end, I would have the shape filled, like the figure 3 shows. The arrows are there just to show the right direction of drawing.
It’s not just about direction, the specific spots on the image matter, there will be different types of images, and I can’t use only the direction.
How can I determine the specific spots in an image with a specific order to be painted?
The only idea that came to my mind, would be some kind of training mode, where I (the developer) would draw the image with the order I want, and the system behind would create virtual points on the code, with a small distance between each of them. Then I would have an array with all the “spots” saved with the order I draw them, do you understand?
I don’t know if this will work, and if it will be fast enough to travel my array of “spots” when the user is trying to draw on the image? Because I want this to work on real-time, the system should check if it’s a valid spot to draw right when the user touches the display…
Do you think it will work? Do you have some recommendations about this? What are the best structures and stuff like that? I am not asking for written code, I just need some guidelines.
I think I explained my problem well, if you have any question please ask me.
Thank you very much in advance!

if all your shapes are lines you can treat the points you want your users to "touch" as squares, every time an ACTION_MOVE event is happening, check if the finger is touching the next point. You can make the size of the squares whatever suits you, like 48dp or 92dp or the width/height of the shape you are drawing.
You said you don't want any code so I assume you know how to do this (if not reply and I will post code too).
Also you didn't mention what happens if the user goes out of the shape, if you want the user to continue drawing until they lift their finger then this way is good, when the ACTION_UP event happens check if the last point is touched (assuming it can only be touched if all others are touched like explained above).
Here is an image if you'd like to have a visual guide:
Obviously if you it this way you have to calculate the positions of each point you will have, I doubt there is any way to automate this.
If you need any more help or you need some code please reply and I will post some! :D

Related

Draw, Persist and Delete Balls for an Android 2D Graphics Application

Drawing some balls onto the screen that can be manipulated is simple enough (to be honest even persisting some coordinate data and re-drawing is probably not too hard)
The tricky part is that I want the user to be able to long press a given ball to delete it (Note: a restriction would probably be in place to prevent balls overlapping).
I also want to be able to persist some coordinates for these balls and load the data back in when the application is used next. At which point the user should be able to delete any ball they want, close the application and reload it to find that ball is still correctly deleted.
The balls will be drawn over the top of a background (just a simple bitmap image)
Can anyone point me in the right direction here, a suitable example would be very useful, if I am honest I thought this would be quite easy to find information about, but it is actually quite tough.
Thanks for your time.

Andengine Parallax Background

Background:
I am making a 2D side-scroller.
When the player touches the screen, the player moves forward (the camera follows the player).
I cannot find an answer to this question although it seems rather straightforward.
Question:
How can I get my parallax background to scroll only when my player moves?
(example code would make things much easier for me)
I am using autoparallaxbackground but it seems that it simply just scrolls at the rates you pass in, with no regard to the camera. Moreover, I am not fully sure of the difference between autoparallaxbackground and parallaxbackground.
Any help is appreciated!
AutoParallaxBackground extends ParallaxBackground, adding one simple feature: automatically changing mParallaxValue with time. As you may imagine, if you don't need your background constantly moving, you may use ParallaxBackground as your base class, and then use setParallaxValue(final float pParallaxValue) to manually adjust the position.

Are my programming methods for java games sufficient [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
so I'm making a 2d Java game with the slick2d and MarteEngine libraries. This is the biggest project since I made checkers for my Java class. I am still pretty new to programming concepts and using optimal ways to get stuff done.
The basic structure of my game is you are a player/hero in a zombie apocalypse and you can gather survivors to help you. There are a many areas that I'm concerned about in my programming. I'm not sure if my methods are a good choice for what I want. This game also does not currently have a grid/tile system.
I've looked at some open source java games and they don't really answer my questions to my methods. So I'm going to make a list here of what I'm uncertain about and I hope you guys can confirm/deny if my methods are appropriate. Sorry if this list gets too long, I'm thinking of the questions as I type.
Targeting/Attacking - Survivors will automatically attack zombies once they get within the gun's target range. To do this, I have every survivor get the distance (using distance formula) to every zombie and find the closest one to attack. I check for this constantly so if a faster zombie gets closer, the survivor will change targets. For zombies, they acquire a target and stick to it (for now). The zombies constantly check if they are within the attack range (around 50 pixels) using the distance formula. If they are within range, stop and attack, otherwise, move towards the target.
2D Camera - So a camera in a 2D environment moves the world around instead of you. My current method is have my zombies/survivors/any entities on the map stored in array lists. First the background is adjusted, then all the lists are cycled through and every entity's x and y values are modified. This seems to work alright but some stuff you can really notice sliding around on the background. Not really sure how to avoid this.
User Interface - I really have no clue how to work with UI. What I've been doing so far is simply using a background and then generating button objects and manually lining them up. Then, I check if the mouse is over any of the button's areas and if there is a click while moused over the button. I have three different backgrounds and buttons that I switch out with booleans. I'm going to recode that area though, using objects with the background and buttons. Is this the correct way to do UI?
Path Finding - I have no path finding system yet. Do I have to stick to a grid system? I really rather my entities move freely along the terrain and not in a weird square to square motion.
Selecting - I have it so you can select survivors, upgrade them, and other random stuff. My current method for selecting is constantly check where the mouse X and Y is. I get the distance from the mouse to every survivor and check if it is within 30 pixels. Then, I check if there is a click, if so, select the survivor and unselect all others. I'm still trying to figure out how to unselect all survivors if I click on open space. Is there a better way to go about doing this?
Picking stuff up - Same way as said before. I check the distance from the player to every item that can be picked up. If the item is within 30 pixels of the player, it picks it up. It seems to work fine for the moment I suppose. Maybe there really is no other way to do this.
Animations - I understand the how to animate with sprites, but I just want to make sure. So if I have 7 different guns to be shot, do I need to manually make functions that have precise timing on each sprite. Say if I have a shotgun, it needs a recoil, pump forward, brief pause, pump back, and ready again. For a pistol I need just the recoil really. So I'd have to make unique functions for each of these animations?
Sorry to type this long list of questions. I try to gather information on this stuff as much as possible and I haven't been able to find many examples on this stuff. I greatly appreciated any answers, even just a yes or no answer. Thanks in advance!
2D Camera:
Not exactly sure what you are doing when you say you modify each entity's position, but the way I'd do it is have a Camera object that has its own x, y, width, height and methods to move the camera around also, and then in your Draw cycle:
for (every Object on the map)
{
if (Object is within Camera bounds)
{
// Draw the Object at the Object-xy minus the Camera-xy
// This will draw the Object at its position relative to the camera
// and won't waste time drawing things that are not within camera bounds
}
}
Targeting/Attacking
You have the right idea, but checking every zombie against every survivor will take a lot of computing and (depending on how many zombies and survivors) can cause the game to slow down a lot. It's the same deal with collision detection, checking every object against every other object to see if they collide takes a lot. There are ways to not have to check everything against everything, I suggest you read into 'Spacial Partitioning'. I have not used slick2d but perhaps it has such a thing already implemented for you.
Picking stuff up
Same deal as Targeting/Attacking, if there are too many items or things that can pick up items, it will end up slowing frame rate a lot.
Selecting
This isn't way you should be doing selecting, but I myself have not had to use selection much at all so I am not completely sure of the best way, you should probably try searching around for ways to do this. Either way your current way can be improved by only checking on a click, you don't need to check every single frame, only check when there has been a click.
This is all I can help with currently, I hope it has been of some use to you at least.

Differentiate Between Robot mouseclick and human mouse click

I have an applet that I'm running online and I want to make sure people can't use the java Robot class to operate the applet. I know that yahoo does this on several of their game platforms and I was wondering if anyone knew how they accomplished it.
Watch mouse movement, and make sure you're not seeing "jumps" from one place to another, but movement over time instead. Sun/Oracle's J2SE tutorials show how to follow mouse movement events: http://download.oracle.com/javase/tutorial/uiswing/events/mousemotionlistener.html
Keep in mind that this would potentially fail to detect the difference between a robot and a person on something like a touch screen, or tablet input device.
One more thing to watch for is whether the user is clicking the same pixel, or just in the same vicinity. Humans are fairly imprecise, robots generally aren't unless programmed to be.
I would also put in a gesture logger for good measure that compiles this information, and keeps track of the actual movements of your users. If you suspect someone of cheating, you can then look at what their actual mouse movements looked like, and compare that with a known person. That will give you a better idea of what you need to look for than any of us can come up with off the tops of our heads.
keep track of the distribution of mouse positions over time. Humans move the mouse differently than a robot that knows exactly where to position it every single time it is clicked. Of course, a smarter robot can counter this defense.

Suitable widget for drawing a 2D cartesian coordinate system in java

I want to build up a GUI area where users can click randomly. Then I want to retrieve the cartesian (x,y) coordinates of those points where the user clicked. Which GUI component is suitable for my task. Also, I want to have any point as big as a usual dot (maybe 3 pixels or more - does this depend on resolution? And if I change the screen resolution of the monitor during the program execution, does the coordinate change?)
I usually work in web programming and I am totally novice in this area. Any pointers to good background reading would help greatly.
Thanks.
http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html
Is this what you're searching for?
as for changing resolution,
I believe you need a listener which changes/updates the size, though I'm pretty much not familiar with that, sorry.

Categories