Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / use finger to scratch open a card

Author
Message
Jo Bach
9
Years of Service
User Offline
Joined: 22nd Dec 2014
Location:
Posted: 16th Dec 2015 21:30
Hi,

How to make a scratch card?

I mean, scratch with your finger on the screen (normaly with a penny on a silver layer) to remove the 'silver' an get tho see the image beneath it?

Has to do somthing with alpha blending? like with a dot. Is it to do with basic AGK2, or have I do it with the c++ sided AGK2??

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 16th Dec 2015 21:52
Unfortunately AppGameKit doesn't support direct GL BlendFunction operations which would be the easiest route to achieve this. You would have to use RenderImage operations in conjunction with shaders to 'erase' portions of the foreground object and show the background. I know there have been some threads posted here about that with some examples. Check this thread in particular:

https://forum.thegamecreators.com/thread/212671
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Dec 2015 21:58 Edited at: 16th Dec 2015 21:59
Edit: I wrote this just as Xcept was posting their answer

I'm sure this can be done in tier 1.

I think I would use a separate sprite to hold the silver and then position this over whatever is to be revealed. The you could use any of the following.

1: use multiple images. The first image being the unscratched "silver" and then have progressively less "silver" with subsequent images. The just swap images the more the player scratches the screen. You could then get realistic looking scratches.

2: Simply increase the transparency - ie reduce it's alpha value - of the silver sprite.

3: rather than using a single sprite for the silver, use multiple sprites to cover whatever is being revealed and then simply hide the silver sprites and the player scratches the screen. This would probably work better for a large area of silver.

For 1 and 2 I don't immediately know how I would detect the scratches. For 3 it would be as simple as hiding the sprite as the player's finger moved over it, using the GetSpriteHit( x, y ) and the pointer or touch coordinates.
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Jo Bach
9
Years of Service
User Offline
Joined: 22nd Dec 2014
Location:
Posted: 16th Dec 2015 21:58
thank you for the info and link.

I can use it to figer out!

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Dec 2015 09:13 Edited at: 17th Dec 2015 09:13
It can be done using image memblocks

1. Make a memblock from the silver image
2. As the user scratches the panel, set the alpha byte on the areas scratched to 0, in the memblock
3. Copy the memblock back to the screen image/sprite.

You should do some pre-calculations of how to navigate the memblock to speed things up at runtime. For example, how to traverse from pixel to pixel both horizontally and vertically.
You only need to createImageFromMemblock(), you don't need to keep copying the image back into a memblock after the first creation.

If you aren't doing anything else, you could make life really easy for yourself. You can create/delete 200x200 pixel memblocks and images at over 700FPS (code below used to test this). This way you can paste a black circle onto a white offscreen image where they scratch. Convert this to a memblock each cycle. Use it as a template to find the pixels you want to make transparent (the black pixels) in the silver image memblock.

You can also alternate to double+ the speed. In cycle 1, create the memblock. In cycle 2, calculate the transparent pixels and move the memblock back to the onscreen image. Or...
In cycle 1, create the memblock. In cycle 2, calculate the transparent pixels. In cycle 3 move the memblock back to the onscreen image.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-11-21 20:51:27
Your offset time is: 2024-11-21 20:51:27