Search Unity

transparent parts of image

Discussion in 'Getting Started' started by littlewombat, Oct 3, 2015.

  1. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    Hello, I want to create game for mobile (android). In this game are two other images (have the same width and height) and the first covers the second. How can I get the effect that when you click on the first one, the clicks place becomes transparent (only this place) and you can see the second image that on stage is located behind the first?

    Thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well, it's not as easy as you might think. You'll have to dynamically update a texture — see Texture2D.SetPixel.

    Or, this is the sort of thing being demonstrated in my PixelSurface demo, which I expected to generate some excitement, but which has so far been met with only chirping crickets. :(
     
  3. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    I mean just about getting such an effect, doesn't matter how. So the only way is dynamically update a texture or have you got other ideas?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Nope, that's the only way (unless there are some special constraints you haven't mentioned, like the click regions are organized into a grid or some such).
     
  5. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    Then what do you think about that solution:
    First image (invisible from game start) in background and second (visible from game start) between first image and camera. If click on second image, for example pixel (x,y) get the same pixel from invisible image (in background) then change this pixel on second image. Do you think that should it work? How can I get the value of x and y when touched?
     
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    So it is like a puzzle game with the top picture broken into shapes/grids & when you click on a bit of it that bit disappears & you can see a bit of the one under it?

    If so why not have the bottom picture as just a normal picture on a plane with the top one (shaped/segmented one) in front of it. When you click on one of the blocks just destroy it & you will see the bit of the picture that is uncovered. If the camera is set to orthographic that should help prevent any shadowing around the edges.
     
    jhocking likes this.
  7. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    yeah that's a good solution. In game development you often don't need/want to do things for "real", you just want to fake things so that it looks like it.
     
  8. MurDocINC

    MurDocINC

    Joined:
    Apr 12, 2013
    Posts:
    265
    You can also use Render Texture to make an alpha mask then apply it to the top image. More complex method but more flexible.
     
  9. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    So on scene I have a image A (Texture Type - Sprite (2D and UI) and in my assets image B (Texture Type - Advanced, read/Write Enabled = true), image A got script
    public Texture2D mainimage; <- image B
    Color px_col;
    px_col = mainimage.GetPixel(x, y);

    For example RGBA(0.698, 0.702, 0.698, 0.706)
    Actually i want to set this pixel to image A on position x1,y1. Can I do it in the same script? How?