Change animation of nearest instance to touch position

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • I want to drag and drop a sprite named Menu_House over instances of sprite named Buildings to change the animation frame of Buildings. This is like creating buildings in city builder or strategy games. Instead of spawning sprites, I want to do this because I want this to happen in specific positions. I want to create these buildings in game only in a specific position nearest to Mouse

    Conditon 1

    Menu_House|On DragDrop drop

    Buildings

    Buildings|Pick nearest to (Mouse.X,Mouse.Y)

      Actions for 1 Buildings|Set animation to "House" (play from beginning) Buildings|Set opacity to 50

    Conditon 2

    Buildings

      Actions for 2 Buildings|Set animation to "None" (play from beginning) Buildings|Set opacity to 100
    [ Key for Events: = Sprite

    Menu_House]

    These are the events... But they won't work properly. If two instances of Buildings (of width 200 pixels) are 200 pixels apart and I drag and drop Menu_House over at the middle of the two instances, both the instances change their animation and opacity. But I only want the nearest of them to do so. Please help me.

    Thank you in advance!!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I read this in 2 ways so I’ll approach it in 2 ways:

    1) (the issue occurs on drag)

    A) Don’t use overlap until touch ends. This way when you’re dragging the menu it doesn’t meet your condition

    B) You can also use a timer with the overlap if you really want that touch involved (you can use your current logic to add to a timer for the instance. If that timer reaches a certain value you would change the animation)

    2) (the issue occurs on drop) You could try snapping your menu to the position to the house and use that as the trigger to the animation change (if menu x/y = house x/y change animation).

  • I read this in 2 ways so I’ll approach it in 2 ways:

    1) (the issue occurs on drag)

    A) Don’t use overlap until touch ends. This way when you’re dragging the menu it doesn’t meet your condition

    B) You can also use a timer with the overlap if you really want that touch involved (you can use your current logic to add to a timer for the instance. If that timer reaches a certain value you would change the animation)

    2) (the issue occurs on drop) You could try snapping your menu to the position to the house and use that as the trigger to the animation change (if menu x/y = house x/y change animation).

    Thank you very much for your reply!! I now know I was wrong...

    However I did not write all my events for this. (Well its my fault)

    Actually I want to do the following things:-

    1. Choose the nearest instance of Buildings to mouse (or to Menu_House).

    2. Then if Menu_House is overlapping Buildings change opacity of buildings to 50 and change animation.

    3. If Menu_House is dropped over Buildings change opacity to hundred and set global variable BUILD to 1

    4. Else Buildings change to its initial animation.

    1,2 & 3 are the problems.

    I want it to look like Construct 2 example of Pick Nearest to (Many instances of a man holding a sword or something), and when a sprite is dropped over them, set opacity of the Man to 100 forever.

    The problem is this won't work. Both instances change their opacity when I drop Menu sprite at the middle of two instances.

  • Hey ,

    you need to store the UID of the picked building in a variable:

  • Hey ,

    you need to store the UID of the picked building in a variable:

    Thank very much!! It works beautifully! This is the thing I was trying to do for hours! Thank you kriand.

    I learnt a new lesson!!

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