0

I need to develop a Instant Lottery game app.

I need an idea/procedure to implement Scratchable custom widget similar to instant Lottery Tickets in Android.

The requirement is like, the actual content(secret number) should be covered by some image(which indicates scratch area). When the user touch and scratch the image, the image has to disappear slowly and the background content(secret number) should appear accordingly.

Please let me know the best way to implement this. I am in real need of it.

Thanks in advance.

Andhravaala
  • 319
  • 6
  • 18
  • This question appears to be a bit similar to this one, but please see my answer below. http://stackoverflow.com/questions/3021401/making-overlaid-image-transparent-on-touch-in-android – Mathias Conradt Jun 20 '10 at 16:51

2 Answers2

2

Conceptually, you could put your scratch area (image) on top of the number you're initially hiding. When the user performs motions on the scratch area, change the opacity of the scratch area so it fades away with every motion.

Jan K.
  • 1,607
  • 2
  • 13
  • 22
  • Hi, Thanks for the reply. I am trying in the same way as you mentioned. I am using Frame layout with 2 views one top of another. The scratch area is ImageView. I am not getting, how to make the touch area transparent? Can you help me in this? Thanks in advance. Do I need to raise another question for this separately. – Andhravaala Jun 11 '10 at 07:32
  • I'll be honest with you - it's been a while since I did anything with Android and even when I did, I was far from magnificent at it. I'd take a look at this link. http://www.google.com/search?hl=en&q=android+image+opacity&aq=0&aqi=g1&aql=&oq=android+image+opa&gs_rfai= – Jan K. Jun 13 '10 at 22:32
0

Since you don't want the entire View to change its transparency, but only the touched parts of it, you need to draw manually on the Canvas, set the PorterDuff mode on a Paint object:

mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) 

and draw with Color.TRANSPARENT

Also see this thread in the Android developer group: http://groups.google.com/group/android-developers/browse_thread/thread/5b0a498664b17aa0/de4aab6fb7e97e38?lnk=gst&q=erase+transparent#

Raceimaztion
  • 9,494
  • 4
  • 26
  • 41
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192