Skip navigation
Raestloz
Currently Being Moderated

Scratch card effect for Graphics? (not with Bitmap)

May 16, 2012 2:51 AM

Tags: #flash #graphics #actionscript3

I know that we can create "scratch card effect" with clever use of transparent drawRect, but it only works with BitmapData. Is it possible to do that with the Graphics data? I'm talking about Graphics as in Shape.graphics and Sprite.graphics (a.k.a. the Graphics with which you define beginFill, drawRect, etc)

 

I'm asking because in my situation the bitmap looks pixelated. Not exactly the best image quality.

 
Replies
  • Currently Being Moderated
    May 16, 2012 7:45 AM   in reply to Raestloz

    Is the graphic you're revealing set to "allow smoothing" in its properties in the library? Bitmaps shouldn't look pixelated unless they're scaled without that option enabled or are in 3D with no antialiasing enabled.

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 9:33 AM   in reply to Raestloz

    If you want to make a scratch-off game you really need to use Bitmaps. You might be able to do some of it using vector shapes, but I think you'd have problems when you wanted to know if enough of the graphic had been scratched off... with bitmapData you can use a threshold test to know how many pixels are remaining and therefore if enough have been removed.

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 10:11 AM   in reply to Raestloz

    You could always do the drawing and/or scaling with the graphics API's and then use BitmapData.draw() to draw it to a bitmapdata object and do your effects that way. Check out this article, it may help:

    http://www.piterwilson.com/personal/2008/05/07/bitmapdata-erasing-in-a s3-with-custom-brush-shape/

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 10:38 AM   in reply to Raestloz

    Have you experimented with the mask property at all? Maybe you have a graphic on top that you're drawing to but it is set as a mask to the image below. I don't know if this would work as I haven't always been able to get the mask property to do what I ask it to

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 11:35 AM   in reply to Raestloz

    The mask is "show only this area" but you may be able to get creative with your layering and duplicating objects on the fly. However I don't see that being easy if possible. I don't even know how much of that can be done so I wouldn't recommend spending a lot of time on it.

     

    If you are drawing on top of images you load in at runtime and cannot control their resolution, I am not sure of another way. You might just have to live with the bitmaps and the quality you get from smoothing them.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points