How do I check if a sprite is near another sprite image point ?

0 favourites
  • 3 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • My game has a drog and drop function where an Object sprite can be droped on a Document sprite. Document sprite can have many zones. Object changes appearance (ie changes frame) dependong on the zone it is dropped on.

    I have made a system where the Document has 2 images point (0 and 1). When Object is dropped on Document, I check the distance between the Object sprite coordinates and the Document imagepoint.

    I have many objects and many documents so I put all of them in families Objets and Documents.

    My code is :

    + System: distance(Objets.X,Objets.Y,Documents.ImagePointX(1),Documents.ImagePointY(1)) < 100

    -> Objets: Set animation frame to 1

    + System: Else

    -> Objets: Set animation frame to 0

    So I'm testing proximity to Imagepoint 1

    My code works when a Document has ImagePoint 0 and 1.

    Some documents have no Imagepoint 1, only Imagepoint 0, and my code behaves like if Imagepoint 0 was Imagepoint 1.

    Is it Constructs that uses Immagepoint 0 if there is no ImagePoint 1 or something I did wrong ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it Constructs that uses Immagepoint 0 if there is no ImagePoint 1 or something I did wrong ?

    Yes, if an image point doesn't exist, then the origin point (0) will be used.

    Also, if you want to change Objects animation frame only for an instance which is close to any of the Documents, you need to pick Object instances. When you use "System Evaluate expression", it doesn't pick instances, and it only checks the first instance of Objets and the first instance of Documents.

    So the correct usage should be something like this:

    Every tick: Objets: Set animation frame to 0
    
    System for each Documents
    System Pick Objets by evaluate: distance(Objets.X,Objets.Y,Documents.ImagePointX(1),Documents.ImagePointY(1)) < 100
     -> Objets: Set animation frame to 1
    
    
  • dop2000

    Oh, it's a shame about 0 picked if 1 doesn't exist... I did find a work around for Document for which I only need one image Point (the 0) by placing an image point 1 very much outside the image.

    As for instance picking, I already have this just before that perfectly does the job :

    + Objets: Is overlapping Documents

    Thanks for being concerned about that :)

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