Tracking how much has been "erased"

Ok I don’t like to post this type of question, but I’ve wracked my brain on this one, searched to the ends of the earth and still haven’t come up with anything or even a really good place to start.  So before I just start throwing things at the wall to see what sticks:

I want to create a little “erase all this stuff” mini-game for within an app for a client… But I’m struggling with how to tell when the user is “done” erasing what I want them to erase.

So like a scratch off ticket – how can you sanely track how much the person has erased and determine they’re done and ready to move on?

Thanks for any thoughts, suggestions, links, etc etc.

Best,

~~Kenn

Hey Kenn,

What exactly do you mean by erase?  It could mean several things.  Please walk us through the methods you are using to erase and let us know what is being erased, e.g. display objects, pixels, bitmaps, snapshots, etc.

I’m assuming the erasing is triggered by a “touch” event?

Hey Sporkfin!

The simplest example would be a scratch off ticket.

It uses touch events and I’m looking to use the eraser system as exampled in:

https://github.com/coronalabs/samples-coronasdk/tree/master/Graphics/SnapshotEraser

The video references a “lottery ticket” type of app…

https://www.youtube.com/watch?v=Rg_F2QH0u78&feature=youtu.be

 

It would seem the brute-force approach to this would be tracking all of the coords the eraser uses…  and then somehow figuring out if enough spots have been uncovered but I’m certainly a bit fuzzy on the best way to “figure that out”.

It’s either just really hard … or I’m missing something.  And I’m hoping that I’m missing something. O:-) 

One idea. . . 

Using the code from the SnapshotEraser, try tracking the number of times the draw( ) function is called to figure out when enough of the bottom layer has been revealed

[lua]

local drawCount = 0 – variable for tracking the number of times draw( ) is called

local function draw( x, y )

     local o = display.newImage( “brush.png”, x, y )

     o.fill.blendMode = { srcColor = “zero”, dstColor=“oneMinusSrcAlpha” }

     snapshot.canvas:insert( o )

     snapshot:invalidate( “canvas” ) – accumulate changes w/o clearing

     drawCount = drawCount + 1 – add one to draw count

end

[/lua]

Another idea . . .

Strategically place some invisible objects on the screen ; objects that are removed when touched.  When all the objects are removed (the same touch triggers the above “draw” function) , the bottom object would be considered revealed.

The first idea won’t work because it doesn’t track the area…  so you could go back and forth in the same tiny area and not actually do anything, just increment the counter. :slight_smile:   

Interesting on the smartly placed invisible objects might work…  Hmmm… I might play with this one a bit and see if I get anywhere.

Ok - strategically places images for the win.

I added a print of the coord in the draw function…  And that allowed me to easily create a table of the placed I needed someone to touch in order to be “done”:

 local function draw( x, y ) local o = display.newImage( "brush.png", x, y ) o.fill.blendMode = { srcColor = "zero", dstColor="oneMinusSrcAlpha" } -- this creates a copiable table of the coordinates of the required touches. print ("{" .. x .. ", " .. y .. "},"); snapshot.canvas:insert( o ) snapshot:invalidate( "canvas" ) -- accumulate changes w/o clearing end

And then I used the result in a table to create dots…  And then once all the dots have been touched, we’re done! :slight_smile:

 local myDots = {} local done = 0; local rectTouched = function (e) local t = e.target; if (t and t.removeSelf) then t:removeSelf(); t = nil; done = done + 1; if (done == #myDots) then print ("done!"); end end end local k,v for k, v in pairs (dots) do local tmpCirc = display.newCircle (v[1], v[2], 10); tmpCirc:addEventListener("touch", rectTouched); sceneGroup:insert(tmpCirc) myDots[#myDots+1] = tmpCirc; tmpCirc.myDot = #myDots + 1; end

Thanks for working this out with me.  I really could not see the logs through the trees. :wink:

I’m glad it worked!  It’s similar to a problem I’m working on.

Nice solution @sporky

Hey Kenn,

What exactly do you mean by erase?  It could mean several things.  Please walk us through the methods you are using to erase and let us know what is being erased, e.g. display objects, pixels, bitmaps, snapshots, etc.

I’m assuming the erasing is triggered by a “touch” event?

Hey Sporkfin!

The simplest example would be a scratch off ticket.

It uses touch events and I’m looking to use the eraser system as exampled in:

https://github.com/coronalabs/samples-coronasdk/tree/master/Graphics/SnapshotEraser

The video references a “lottery ticket” type of app…

https://www.youtube.com/watch?v=Rg_F2QH0u78&feature=youtu.be

 

It would seem the brute-force approach to this would be tracking all of the coords the eraser uses…  and then somehow figuring out if enough spots have been uncovered but I’m certainly a bit fuzzy on the best way to “figure that out”.

It’s either just really hard … or I’m missing something.  And I’m hoping that I’m missing something. O:-) 

One idea. . . 

Using the code from the SnapshotEraser, try tracking the number of times the draw( ) function is called to figure out when enough of the bottom layer has been revealed

[lua]

local drawCount = 0 – variable for tracking the number of times draw( ) is called

local function draw( x, y )

     local o = display.newImage( “brush.png”, x, y )

     o.fill.blendMode = { srcColor = “zero”, dstColor=“oneMinusSrcAlpha” }

     snapshot.canvas:insert( o )

     snapshot:invalidate( “canvas” ) – accumulate changes w/o clearing

     drawCount = drawCount + 1 – add one to draw count

end

[/lua]

Another idea . . .

Strategically place some invisible objects on the screen ; objects that are removed when touched.  When all the objects are removed (the same touch triggers the above “draw” function) , the bottom object would be considered revealed.

The first idea won’t work because it doesn’t track the area…  so you could go back and forth in the same tiny area and not actually do anything, just increment the counter. :slight_smile:   

Interesting on the smartly placed invisible objects might work…  Hmmm… I might play with this one a bit and see if I get anywhere.

Ok - strategically places images for the win.

I added a print of the coord in the draw function…  And that allowed me to easily create a table of the placed I needed someone to touch in order to be “done”:

 local function draw( x, y ) local o = display.newImage( "brush.png", x, y ) o.fill.blendMode = { srcColor = "zero", dstColor="oneMinusSrcAlpha" } -- this creates a copiable table of the coordinates of the required touches. print ("{" .. x .. ", " .. y .. "},"); snapshot.canvas:insert( o ) snapshot:invalidate( "canvas" ) -- accumulate changes w/o clearing end

And then I used the result in a table to create dots…  And then once all the dots have been touched, we’re done! :slight_smile:

 local myDots = {} local done = 0; local rectTouched = function (e) local t = e.target; if (t and t.removeSelf) then t:removeSelf(); t = nil; done = done + 1; if (done == #myDots) then print ("done!"); end end end local k,v for k, v in pairs (dots) do local tmpCirc = display.newCircle (v[1], v[2], 10); tmpCirc:addEventListener("touch", rectTouched); sceneGroup:insert(tmpCirc) myDots[#myDots+1] = tmpCirc; tmpCirc.myDot = #myDots + 1; end

Thanks for working this out with me.  I really could not see the logs through the trees. :wink:

I’m glad it worked!  It’s similar to a problem I’m working on.

Nice solution @sporky