Note that there are some explanatory texts on larger screens.

plurals
  1. POonGesturePerformedListener with SurfaceView and animation Thread
    primarykey
    data
    text
    <p>I am working on a children's game for Android that uses gestures and 2d animation. I have three classes in the game: the main activity, the SurfaceView (for the animation), and a thread to control the animation. Pretty simplistic stuff. I have gestures working the way I want. And I have the scene working the way I want. The problem is, I would like the scene to react as the user performs the gesture. So, there is a star on the scene. I would like the child to trace the star (preloaded as a gesture) but as he traces it, I would like to animate the star. I have put a number of logs to see if the thread is firing, but it is not receiving messages. So, basically, I want the the two to work in tandem - I want to the onGesturePerformedListener to grab the touch event, and I want the surfaceView to grab the same touch event. Both need to react to it. Like I said, I have them working independently brilliantly, but I need them to work at the same time. What am I missing?</p> <p>Main Activity:</p> <pre><code>mGameView = (GameView)findViewById(R.id.gamearea); mGameView.setStatusView((TextView)findViewById(R.id.text)); mGameView.setScoreView((TextView)findViewById(R.id.score)); mGestureView = (GestureOverlayView)findViewById(R.id.gestures); mGestureView.addOnGesturePerformedListener(this); </code></pre> <p>This class also holds the onGesturePerformed method.</p> <p>SurfaceView: (This is the method that sets the thread.)</p> <pre><code>public void setThread(GameThread newThread) { thread = newThread; setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if(thread!=null) { Log.d(TAG, "Touched the screen"); return thread.onTouch(event); } else return false; } }); setClickable(true); setFocusable(true); } </code></pre> <p>Thread:</p> <pre><code> //Finger touches the screen public boolean onTouch(MotionEvent e) { if(e.getAction() != MotionEvent.ACTION_DOWN){ Log.d(TAG, "onTouch Fired"); return false; } if(e.getAction() == MotionEvent.ACTION_DOWN) { dotX = e.getX(); dotY = e.getY(); Log.d(TAG, "Updating Dot by touch."); return true; } if(mMode == STATE_READY || mMode == STATE_LOSE || mMode == STATE_WIN) { doStart(); Log.d(TAG, "doStart Loaded"); return true; } if(mMode == STATE_PAUSE) { Log.d(TAG, "mode is paused"); unpause(); return true; } synchronized (mSurfaceHolder) { Log.d(TAG, "synchronized"); this.onTouch(e); } return false; } </code></pre> <p>My working theory is that everything hinges on the placement of the overlayview - this is where I have a breakdown in understanding. The main.xml, which is what the Main activity is set to (seen above) looks like this:</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;android.gesture.GestureOverlayView android:id="@+id/gestures" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0"/&gt; &lt;com.trial.game.test.GameView android:id="@+id/gamearea" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;RelativeLayout android:id="@+id/gameLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/score" android:text="@string/score_text" android:visibility="visible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="top" android:textColor="#ff0000ff" android:textSize="24sp" android:layout_marginTop="3px" android:layout_centerHorizontal="true"/&gt; &lt;TextView android:id="@+id/text" android:text="@string/mode_ready" android:visibility="visible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center_horizontal" android:textColor="#ff0000ff" android:textSize="20sp"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p></p> <p>Based on the placement of the gestureoverlay or the gameview one or the other will fire, but not both at the same time. What I am overlooking or misunderstanding here. Anyone?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload