Change object layout after setting events(XY position).

0 favourites
  • 8 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi,

    I have made a game with 41 events with help of a template. It is drag and drop, shape matching game.

    I am using "Lite Tween" behaviour which uses XY position to drop objects at the correct place and return to the original place if dropped at the incorrect place.

    I wish to change the layout of my scene, like moving the draggable to another position or the drop target to a new place.

    This messes up the game as all the XY positions in events are already set.

    Will I have to change all of them again every time I change the layout or is there a way to do it automatically without manually changing XY of all my events?

    Thanks.

  • Wow...

    If you have to repeat the same event more than twice, you should definitely optimize it.

    Add all sprites to a family, define Drag&Drop behavior on the family. You'll be able to keep just one event "Family on Drop" and remove all duplicates!

    Add instance variables to the family: StartX, StartY, TargetX, TargetY

    On Start of the Layout (or On Family Created) set StartX to Family.x, set StartY to Family.y

    I'm not sure how your game works and where do you get values for TargetX, TargetY. You might need to set them manually per each sprite on the layout.

    On Drop - if dropped on a wrong spot, set object position to (self.StartX, self.StartY)

    If dropped correctly, set object position to (self.TargetX, self.TargetY)

  • Hi, thanks for the reply.

    [quote:l4zhz8c9]I'm not sure how your game works and where do you get values for TargetX, TargetY.

    I have 2 objects for each set of events 1. The draggable and 2. The drop area (which is a duplicate of the draggable with opacity set to 0).

    So, like this, I have around 13 dragables and 13 drop areas.

    I set the XY position by seeing the XY position of the drop area object.

    i.e. if the object is dragged and it overlaps the drop area then it snaps to the XY position of the drop area, if not, then goes back to its original point.

    [quote:l4zhz8c9]If you have to repeat the same event more than twice, you should definitely optimize it.

    Add all sprites to a family, define Drag&Drop behaviour on the family. You'll be able to keep just one event "Family on Drop" and remove all duplicates!

    Add instance variables to the family: StartX, StartY, TargetX, TargetY

    On Start of the Layout (or On Family Created) set StartX to Family.x, set StartY to Family.y

    [quote:l4zhz8c9]On Drop - if dropped on a wrong spot, set object position to (self.StartX, self.StartY)

    If dropped correctly, set object position to (self.TargetX, self.TargetY)

    Sorry, I didn't get these. I humbly request a screenshot or .capx.

    Thanks again.

  • jmg89

    Here you go:

    https://www.dropbox.com/s/28o9bf9o4rmw4 ... .capx?dl=0

    I used one sprite with different frames. You can use a family with multiple sprites if you want.

  • Try Construct 3

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

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

    Here you go:

    https://www.dropbox.com/s/28o9bf9o4rmw4 ... .capx?dl=0

    I used one sprite with different frames. You can use a family with multiple sprites if you want.

    dop2000

    Thank you. But this doesn't work if we use family.

    1. In family correct drop is working fine but the incorrect drop is not.

    Object 1 works correctly i.e. comes back to its place if placed incorrectly but when object 2 is placed incorrectly then object 1 tweens to object 2's position automatically!!!

    Also, set "drag-drop" to "disabled" after correct placement is not working.

    2. The IncorrectDropCounter does not work as expected. It shows the text even if Obj 1 is placed incorrectly twice and obj2 is placed incorrectly once. I think it is counting all objects incorrect placement combined and not individually.

    I sincerely thank you for all your help, you are a great person.

  • 1. I think you missed the condition in my demo where I'm comparing Sprite.ID=Target.ID

    This is how you define the correct drop area for each sprite - using the ID instance varible on both sprites.

    2. Instead of the global variable for incorrectDropCounter you can make it an instance variable on the family.

    Then it'll be counting incorrect placements per instance.

    If you still can't figure this out, please share your capx.

    You can pm it to me if you don't want to post the link here.

  • 1. I think you missed the condition in my demo where I'm comparing Sprite.ID=Target.ID

    This is how you define the correct drop area for each sprite - using the ID instance varible on both sprites.

    2. Instead of the global variable for incorrectDropCounter you can make it an instance variable on the family.

    Then it'll be counting incorrect placements per instance.

    If you still can't figure this out, please share your capx.

    You can pm it to me if you don't want to post the link here.

    I think I've figured out most of it.

    I request you to address these issues with my file:

    1. How to implement IncorrectDropCounter for individual frames/ID?

    2. How to show different text for IncorrectDrop for each frame individually?

    3. How to set the same events while using a family?

    Here's the file:

    nofile.io/f/A9JeMUDSQ9w/DragDropZoomFinal.capx DragDropZoomFinal.capx

    Thank you.

  • (click)

    If you have several DropObj sprites, add them to a family, move all instance variables and behaviors from sprite level to family level and update events. Here is the tutorial:

    https://www.scirra.com/tutorials/535/ho ... o-a-family

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