How do I do the following?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • I created an event that creates squares in the middle of the screen; I need to know how to make it so that when I press on one and move it to the sides, they swap positions.

    event

    I'll leave you with an example image.

    Could it be done using only variables? In the simplest way possible.

    Tagged:

  • You create two instance variables: Cell_X and Cell_Y (this doesn't represent the x and y of the square in the layout, it represent the possition on the grid you are creating on start of layout).

    When you create the square assign values to Cell_X and Cell_Y using the "loopindex", in this way you have all the squares mapped.

    After, when you are touching over a square compare in wich direction is your touch, so for example if you move your finger or mouse to the left, you can pick the square that has the touched square.cell_X-1.

    Hope it helps

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well to swap the position of two instances of the same object you’d pick one and save the xy to variables. Then you’d pick the second one and save its xy to other variables. Then you’d pick each one again and set the position to the saved variables. However, you could simplify that a bit to use less variables.

    Basic swap logic would be

    Temp=a

    A=b

    B=temp

    But the main busywork would be picking.

    Picking each instance one at a time can be tedious and require a lot of events. However, if you add two instances of a helper sprite on the layout and call it temp, you could do this to swap instances with minimal events. You also need to add a swap instance variable to the blocks.

    Mouse: left is down
    Mouse: is over block
    Block: pick instance 0
    — block: set swap to true
    
    On mouse: left released
    — block: set swap to false
    
    Block: swap is true
    Compare: block.pickedCount = 2
    — temp: set position to block
    — block: set x to temp(1-temp.iid).x
    — block: set y to temp(1-temp.iid).y
    — block: set swap to false
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)