Whenever i try to store points on drag event ,if i drag a little faster it doesn't store each and every point i drag on screen.
What should i do that it stores each and every point on my touch path?
It is not a problem of Java, or LibGDX. There are two possible causes:
Your touchscreen digitizer has low refresh rate so that it just can't
keep up with your finger's speed.
Your main loop has a performance issue and something inside loop
takes such a long time that you can't get enough number of touch
events.
Either way, the result will be the same.
Related
I'm currently in the process of making a game in Java. I've recently been working on mouse input, and where I'm stuck has to do with the game recognizing when the mouse has moved. I've obviously gotten it to accept mouse input, but I can't make the in-game player rotate correctly based upon mouse position.
What I can come up with to fix it is to take a measurement of the mouse's x position at one point in time, and then compare it to another measurement one millisecond later to see whether or not the mouse has moved, and if so, to get the player to rotate linearly faster with the distance the mouse has translated.
However, I have no idea how to do that without forcing the entire program to wait or yield (which would be bad).
I've tried writing the position to a file and then re-reading it immediately after, but it tends to read from the file at different rates, causing the rotation to be spastic and uneven. But besides that, I'm open to ideas. I can't really post my code because there are many class files that go into the program, but if necessary, I can post the whole project to github for anyone to look at.
GitHub Repository link: https://github.com/isl1/Duplicity
P.S. If it helps, I'm using LWJGL 3, paulscode, and Slick-Util on Eclipse Mars.
I'm writing code which moves the mouse in an applet by sending MouseEvent objects for it to process. In order for my code to move the mouse from one location to another, I need to generate points to fill the path so that my mouse can move through them. However, in order to create the right amount of points (i.e., to mimic movement as if done by physically moving the mouse), I need to determine the physical mouse's polling rate so I know how often it tells my machine about its position.
I looked around for ways to retrieve this value, but the best that I found was the MouseInfo class, but all that it tells me is the number of buttons on the mouse and some information about its pointer - not what I'm looking for. Does anyone know a way (preferably without some sort of external dependency) to read the physical mouse's polling rate?
I'm not sure if there's a solution for this in the API, but I suggest setting up a mouseListener and capture timestamps with System.currentTimeMillis() or System.nanoTime(), then just wave the mouse around for a bit and measure the time between events fireing. While you're moving the mouse, the MouseEvents should fire as fast as the mouse is polled. I think.
I am doing my final Year project on Speed Calculation using webcam. In this project we want to calculate speed of object by taking three sequential images whenever motion is detected. As given here: Raser Abwehr SpeedCam 2012, in this three line RED BLUE and GREEN are made and whenever any vehicle cross it, it takes one snap.
For this I have idea that suppose my camera resolution is 640*480 hence I can divide X-Axis in three parts of 210px each therefore I can have three rectangular screens of size (210*480). Now, I want that whenever any vehicle enters in Screen1 then it click a picture then it start second screen detector and when vehicle enters into second screen it takes second picture and at last it detect in third and click picture. Hence we have three picture and we can calculate Speed by process given here Calculating Speed using a Webcam
Presently, I am using JavaCV as Image Processing Library. It is just like running multiple instance of a single Java program to detect motion in different screen. Please suggest to me how i can do. Can Thread be useful here?
(More like a comment but it doesn't fit)
I'd suggest by starting try making it work by taking three pictures at a fixed interval (which you guess).
Then, if you want to address the issue of detecting speed of objects that are moving at quite different speeds, I'd just suggest by starting with taking as many pictures as possible once you detect any movement, for a sufficiently long time, and then figuring out afterwards which one you should use for the analysis.
I can see what you are trying to do but you should probably start with dumb things first. Just my two cents...
For those of you who have played Madness Interactive, one of the most frustrating things is when the cursor leaves the game area, and you accidentally click. This causes the game to defocus and your character dies in a matter of seconds. To fix this, I'd like to make a java application that I can run in the background that will hold the cursor inside the screen until I press a key, like ESC or something.
I see two ways of implementing this, but I don't know if either of them are workable.
Make an AWT frame that matches the size of Madness Interactive's render area, and control the cursor using that.
Use some out-of-context operating system calls to keep the cursor in a given area.
Advantage of approach #1: Much easier to implement resizing of the frame so that user can see the shape and position of the enclosed area.
Potential Problems with approach #1: The AWT Frame would likely need to steal focus from the browser window the game is running in, making the whole solution pointless.
My question is, are either of these approaches viable? If not, is there a viable option?
EDIT: I am willing to use another programming language if necessary.
EDIT2: I might develop a browser plugin for this, but I've never done that kind of development before. I'll research it.
If you're still interested in working in Java, here's a possible solution for you.
First, in order to limit the cursor within an area, you could use the Java Robot class.
mouseMove(int x, int y);
Then, you could use AWT's MouseInfo to get the position of the mouse cursor.
PointerInfo mouseInfo = MouseInfo.getPointerInfo();
Point point = mouseInfo.getLocation();
int x = (int) point.getX();
int y = (int) point.getY();
Then, whenever the x and y value of the mouse cursor go beyond a certain point, move them back using the Java Robot class.
If this is for a browser-based game, consider writing a greasemonkey script, which acts as a browser extension that can be filtered to only run on the game's site.
In the simplest case, assume the clickable regions are (0,0) - (300,400), then you can add the following event handler to the page:
$(document).on('click', function(event) {
if (event.pageX > 300 || event.pageY > 400) {
return false;
}
});
You can further refine your script to do the following:
resize the browser to be the perfect size for playing the game
instead of checking the absolute x,y coords of the click, check if it is inside an element of the page that you don't want to receive the click
add custom key bindings to umm.. help you at the game
write a javascript bot that can play the game itself
I'm having issues with a java class project. The first step consist in drawing a pattern, so I thought well, this can't be hard. And it isn't, but there one thing that really bothers me. First, check the screenshot below :
Screenshot
My problem is that this was done without releasing the mouse, so the drawing should be continuous. Instead of this, there's holes in it. I'm thinking this is related to the way mouse events are transmitted, But I have no idea how to tweak this.
The drawing zone is a JPanel. There is a set of Points that is used to paint the container on mouse events. Pressing add the first point, dragging the others, released clear the drawing zone.
Hope I was specific enough. Thanks for your time!
edit : Forgot the code. http://pastebin.com/RyXiGsvm
StanislavL's right that mouseMove/mouseDrag events are not generated for every pixel you move the mouse cursor over. Why don't you want to use lines? If the issue is that the result is ugly and jagged, you might consider using cubic splines instead. GeneralPath.curveTo provides an easy way to do this. If getting the control points right is a pain, you can also use GeneralPath.quadTo; this is a quadratic approximation that won't look quite as good, but you can easily just pass in the last three points from mouseDrags.
I guess you store mouse points obtained in mouseDrag processing. Mouse drag happens from after some time interval so if you move mouse relatively fast you just got points. TO drai it you can use drawLine() passing pairs of point. So you'll have lines.