#Override
public void onFrame(Controller arg0) {
Frame frame = arg0.frame();
for (int i = 0; i < frame.gestures().count(); i++) {
Gesture gesture = frame.gesture(i);
if (gesture.type() != Type.TYPE_INVALID)
System.out.println(gesture.type().toString());
}
}
I get no message in console.
If i remove that if, i will get a lot of invalid swipes.
I've tried doing a lot of types of swipes but nothing seems to work.
Example of swipe that i tried:
https://www.youtube.com/watch?v=dj1q8Bjn-uk
The function frame.gesture(id) searches the frame's gesture list for a gesture object with the specified id, i.e. so that you can track a particular gesture across frames. The function returns an invalid frame if it doesn't find one. Change your code to use frame.gestures(), which gives you the gesture list:
#Override
public void onFrame(Controller arg0) {
Frame frame = arg0.frame();
for (int i = 0; i < frame.gestures().count(); i++) {
Gesture gesture = frame.gestures().get(i);
if (gesture.type() != Type.TYPE_INVALID)
System.out.println(gesture.type().toString());
}
}
You shouldn't ever get invalid gestures in the list supplied by the gestures() function, so you don't really need that check in this case.
Related
I've created a number picker with some string values.
public void setValues() {
boolean defaultAvaliable = false;
int defaultRow = 0;
String[] values = new String[pickValues.size()];
for (int i = 0; i < pickValues.size(); i++) {
if (pickValues.get(i).equals("01:00")) {
defaultAvaliable = true;
defaultRow = i;
}
values[i] = pickValues.get(i);
}
timePicker.setMaxValue(values.length - 1);
timePicker.setMinValue(0);
timePicker.setWrapSelectorWheel(false);
timePicker.setDisplayedValues(values);
if (defaultAvaliable) {
timePicker.setValue(defaultRow);
}
}
And when I scroll to edge values (first or last) the picker first jumps to that item in a weird, not smooth way and after that when i try to go back to other values it doesn't scroll. The picker glitches on the edge value and after some time it finally goes back. In some way it looks like I would scroll over the edge value and it needs some scrolling to get back.
Has anyone else had this problem or does anyone have any suggestions what to check?
EDIT 1:
So I've got to he point that I know the problem is when I change the font size in my numberpicker, and don't know why. As soon as I set the font size over 39 it starts to get stuck on first and last item.
private void updateView(View view) {
if(view instanceof EditText){
((EditText) view).setTextSize(39);
((EditText) view).setTextColor(getResources().getColor(R.color.mp_white));
((EditText) view).setFocusable(false);
}
}
Does anyone know what is the row size?
Or if I have to change the size of it, so it detects the scrolling correctly?
I'm trying to make a game i want to be able to press down on my gamePadUI to keep my character walking. Far as I can tell the TouchEvents only get called 1st time I push down on the screen
I have 2 methods called constantly update() which keeps track of my game states and in each state has TouchEvents, so in my Running state it will call updateRunning() and checks for TouchedEvent then map the the x and y points to my gamepadUI
The other is Present() which handles the drawing of each states.
so here is my updateRunning() method that tells the character to walk
public void updateRunning(float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
Input.TouchEvent event = touchEvents.get(i);
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
switch(event.type){
case TouchEvent.TOUCH_DOWN:
gamePad(deltaTime);
case TouchEvent.TOUCH_DRAGGED:
gamePad(deltaTime);
case TouchEvent.TOUCH_UP:
}
}
}
I have tried looping the event but my present then will not get called for there the drawing will not get updated.
what can I do to make it keep TOUCH_DOWN going to call my gamepad method.
Update: I just added a second set of buttons above with no method so the two would not interfere.
To be clear, the following is for a simon says type game, where the computer plays a pattern of buttons and the user must click them in the correct order.
I am calling programmatically a sequence of buttons as a demo to the user, who is expected to press those buttons. But as the demo buttons are pressed their methods are being called which is messing up things for the user.
How can I call just the button animations so that the demo is still presented but the onClick methods are NOT called?
Here is some relevant code:
public void clickBut(View view, int[] list, int level) {
Button redBut = (Button)findViewById(R.id.redBut);
Button blueBut = (Button)findViewById(R.id.blueBut);
Button greenBut = (Button)findViewById(R.id.greenBut);
Button yellowBut = (Button)findViewById(R.id.yellowBut);
for (int i = 0; i < level; i++) {
if (list[i] == 0) {
redBut.setPressed(false);
redBut.performClick();
redBut.setPressed(true);
redBut.invalidate();
redBut.setPressed(false);
redBut.invalidate();
}
else if (list[i] == 1) {
redBut.setPressed(false);
blueBut.callOnClick();
blueBut.setPressed(true);
blueBut.invalidate();
blueBut.setPressed(false);
blueBut.invalidate();
}
else if (list[i] == 2) {
redBut.setPressed(false);
greenBut.callOnClick();
greenBut.setPressed(true);
greenBut.invalidate();
greenBut.setPressed(false);
greenBut.invalidate();
}
else if (list[i] == 3) {
redBut.setPressed(false);
yellowBut.callOnClick();
yellowBut.setPressed(true);
yellowBut.invalidate();
yellowBut.setPressed(false);
yellowBut.invalidate();
}
}
}
Forgive me if the setPressed(boolean) lines are superfluous or erratic I'm trying out different combinations.
I need this to play and click the correct buttons without activating the methods, then open it up to the user so he/she can click buttons and have the appropriate methods called.
Let me know if any more of the code would be helpful.
Replace-
redBut.setPressed(false);
redBut.performClick();
redBut.setPressed(true);
redBut.invalidate();
redBut.setPressed(false);
redBut.invalidate();
by-
following code to appear button clicked for 1 second:-
button.performClick();
button.setPressed(true);
runnable = new Runnable() {
#Override
public void run() {
//called after 1000 millisecond/ 1 second
button.setPressed(false);
}
};
handler.postDelayed(runnable, 1000);
And If you want to show button selected then use-
button.setPressed(true);
The following should do the trick
mButton.setOnClickListener(null);
I'm creating a user interface for a game that I have to do as a class project, and needless to say I'm not experienced with Swing.
I did learn about actionevents and whatnot for simple button pushes, but in those cases I knew how many buttons would be on screen. Here, I need to create a board with an arbitrary number of tiles, which will be represented as buttons in Swing. I need to push a button and "move" my character from one tile to another, so I need to call a method on one tile object to remove the player from that tile, and then add it to another tile.
So my question is, given that the number of buttons is generated at runtime (and stored in a 2d array) how can I make an actionlistener that is able to distinguish between each unique button?
Set all your buttons to the same handler:
ActionListener a = new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == buttons[0][0]) {
}
// etc
// common handling
}
};
for (int i = 0; i < height; ++i)
for (int j = 0; j < width; ++j)
buttons[i][j].addActionListener(a);
I am developing an Android game in java where I will have a sprite that follows the user's finger and is supposed to fire a bullet every second. In other words, I am trying to attach a bitmap that moves up every second. The bitmap starts at the x and y coordinates of the main character sprite. I can't get it to draw more than one missile at a time, and I have run out of ideas of how to do so. I have tried so many things, and I really could use some help.
By the way, my Main Game Panel class extends a surfaceView and implements a SurfaceHolder.Callback:
public class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback{
Thanks!
As far as I understand you want to have the ability to shoot more than 1 bullet at a time? You can use a Vector or Array to do this. With an Array you can set a default amount of visible bullets and in a Vector you could have as mant bullets that your finger is capable of producing.
Here's my code that I use to generate lasers (I store the values in an Array).
public void updatePlayerLaser(boolean shootLaser) {
// Check if a new Laser should be created
if(shootLaser == true) {
if(timeLastCreatedLaser + 100 < System.currentTimeMillis()) {
timeLastCreatedLaser = System.currentTimeMillis();
boolean createdNewLaser = false;
for(int i = 0; i < this.amountOfVisibleLasers; i++) {
if(createdNewLaser == false) {
if(holderLaser[i].isDisposed()) {
this.generateNewLaser(i);
createdNewLaser = true;
}
}
}
}
}
// Update all the other Lasers
for(int i = 0; i < this.amountOfVisibleLasers; i++) {
if(holderLaser[i].isDisposed() == false) {
holderLaser[i].update();
}
}
}
Disposed in this contexts means that the laser is dead, thus making space for a new laser to take the old lasers spot.