Saturday 15 August 2015

android - How to detect single tap on canvas drawings or bitmaps using onTouchListener? -


The object of this game is similar to a bubble popping game. Every time a bubble has touched, there is a conversation / event.

So far I have it. I am new to this, but my professor asked me to use Touch (scene, visual event) and in that method, I will use some events. GetSource (); To be able to contact me for the purposes of tactile drawing / bitmap image.

Any advice or help would be great! thanks a lot.

  The main activity of the public class increases the activity tools OnTouchListener {OurView v; Bitmap icon1, icon2, icon3; Float x, y; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); V = new ours (this); V.setOnTouchListener (this); Icon1 = Bitmapfirenet Decode processing (getResources (), RDWLIC.IC_Luncher); Icon2 = BitmapFireterDiscover Resource (getResources (), R.drawable.ic_launcher); Icon3 = Bitmapfinderator Datasource resource (getResources (), RDWLC_IC_Luncher); X = y = 0; SetContentView (v); } @ Override Protected Zero at Pause () {Super. V.pause (); } @ Override Resume at zero () {super.onResume (); V.resume (); } The public class runs ourView SurfaceView tool Runnable {thread t = zero; Ground holder holder; Boolean IITOK = is incorrect; Public OurView (Reference Reference) {Super (Reference); Holder = holder (); } @ Override Public Wide Run () {While (IITOK == true) {if (! Holder.getsrace (). IsValid ()) {continue; } Canvas C = Holder.Loccanvas (); C.drawargb (255, 100, 120, 10); C.drawBitmap (icon1, x = 50, y = 100, empty); C.drawBitmap (icon2, x = 180, y = 100, empty); C.drawBitmap (icon3, x = 310, y = 100, zero); Holder.unlockCanvasAndPost (c); }} Public Nil Break () {isItOK = false; While (true) {try {t.join (); } Grip (Interrupted e) e.printStackTrace (); } break; } T = Null; } Public resume resume () {isItOK = true; T = new thread (this); T.start (); }} @ Override Public Boolean On Touch (see We, Motion Event Me) {try {Thread Solid (50); } Grip (Interrupted e) e.printStackTrace (); } Me.getSource (); Switch (me.getAction ()) {case MotionEvent.ACTION_DOWN: x = me.getX (); Y = me.getY (); break; Case Motion Event Action_up: break; Case MotionEvent.ACTION_MOVE: Break; } Back true; }   

}

You painted your bitmap on the known coordinates So why not just check a boundary? Like if x & gt; 50 and X & LT; 100 and Y & gt; 100 and Y & lt; 150 then they crowded the tapped icon 1 (assuming their bitmap as 50x50) a few seconds ago

No comments:

Post a Comment