[solved] If a sprite is hidden by another sprite ?

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi.

    I would like to know when my character isn't visible anymore when it is hidden behind a tree or a wall (sometimes more than one if the player is bigger than a single wall). When we actually can't see any pixel of it.

    Any idea how to do that ?

  • One idea is to use a canvas. 1st paste the character and then paste with "destination-out" anything in front of the player. Then loop over all the pixels of the canvas and see if any pixels aren't transparent. The main issue with that is it's very slow.

    If you can treat the player as a square it can be done much quicker.

    For instance to check if a player's bounding box is inside another box you can do this:





    It would become much more complicated if you wanted to know if multiple boxes covered the sprite completely. It would probably require splitting the bboxes up.

    Another idea would be to loop over the positions of the sprite and 1st check if the point overlaps the sprite then see of it's overlapping the object's above the sprite. It could be slow too but you also could do a more coarse check by not checking every point.

  • Thank you for your reply

    Actually my character will be overlapped by some little squares and it takes about 10 squares to cover it entirely.

    I like your canvas suggestion. My character (and its squares) won't be that big so it could fit. I could also iterate every 10 pixels, I think it would work too because of the square shapes.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi !

    I've set up this. It works very well with sprites.

    However, there is an error message when I try to paste a tilemap into the canvas.

    [quote:18bf1g9p]Javascript error!

    Uncaught TypeError: Cannot read property '0' of undefined

    http://localhost:50000/Tilemap_plugin.js, line 204 (col 20)

    Any idea how to fix that ?

    edit : okay I've got this : plugin-canvas_p845147?#p845147

    So, is there any way to know how much a tilemap is overlapping a sprite with webGL on ?

  • A solution that's kind of hacky is to use a paster object as well.

    1. Paste the tilemap to the Paster object

    2. Load the Paster.imageUrl to a sprite

    3. paste that sprite to the canvas.

  • I'm going to try that, thank you so much

  • Last question !

    It seems that I can't paste my freshly loaded (from paster.imageUrl) sprite into a canvas object on the same tick.

    For example, it works if I add

    system -> wait 0.1s


    sprite -> load from paster.imageUrl


    canvas -> paste sprite

    If I don't add a system wait, it won't paste the sprite until I trigger it later.

    How to avoid this ?

    edit : it seems that I should use "sprite -> on url loaded" but I can't find it. Weird.

    edit2 : nevermind, found it. <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes">

    I'll leave this here, in case someone needs to do the same thing one day : https://www.dropbox.com/s/dgjryr0qujw2x ... .capx?dl=1 (needs the canvas and paster plugins)

    (drag'n drop the character and it will show how many pixels from the sprites and the tilemaps are overlapping it)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)