AllanR's Forum Posts

  • I will be playing with the undo/redo later...

    the UID is the unique identifier number that every object gets assigned when it is created, or just added to a layout. when you have multiple objects of the same type, it comes in handy to tell them apart. You can also give objects instance variables and use that to keep track of them, or their X and Y position, etc... but UID is the definitive way to make sure you have the right instance. - you will see it a lot in the undo/redo code...

  • ok, the rotate issue was because the buttons still had focus and were intercepting the keyboard, so when a button is pressed, I added a set Unfocus action to fix that.

    and I added a global variable to track which instance the mouse is over. now it works the way you would expect - it doesn't use trigger once.

    https://www.rieperts.com/games/forum/familyflash.c3p

  • OK, the Flash issue is that you can't add the behavior if any of the family members already have it. So, remove it from the other objects and then you can add it to the family.

    that makes having one set of events for the family very easy to do...

    although the rotate doesn't seem to work, and the trigger once condition doesn't work when you have many overlapping objects of the same type (as you move the mouse from one to another - if it is never not over that type, then the trigger once condition doesn't reset).

  • an Undo system will actually take very little memory - small text entries in an array take a negligible amount of room even on old devices.

    and the code will work the same whether you allow 10 undo's or 1000.

    the trickiest part is how to handle deleting objects. The undo array would save the UID of the object that is changing, however when you undo a delete action you would have to create a new instance of the object and that would give it a different UID. Any previous actions in the undo array would have to know they now apply to the new UID. The alternative would be to not actually destroy the object - just move it to an off-screen holding area in case it gets brought back.

    I will take a crack at it later today - starting from the select / drag and drop example I was playing around with yesterday...

  • I would keep the undo list in memory using an array - not save it to local storage.

    since you seem to be building some kind of level editor, you are going to have a lot of objects, and there are lots of things you will be doing to those objects: move, size, z-order, rotate, create, delete, etc.

    every time some action has finished, insert a new entry into the array.

    you will need to store things like: object UID, ObjectTypeName, Action Performed, the old value, the new value for that action.

    since I know you want to have several objects selected, that makes it more complicated because then undo/redo has to apply changes to the whole group, so each entry in the array will have to include all the details from each object and know it was part of a group action.

    the only reason to save the undo list to local storage would be if you want to close the game, open it again later and still be able to undo things you did in the previous session. That is also possible - saving/loading an array is an easier way to do this than any alternatives I can think of...

  • glad to help. over the last few years I have learned a great deal by finding interesting problems in the forums and experimenting with solutions...

    I still say it is not a matter of finding the right actions to make it work, it is understanding that there are ambiguous situations that require further input from the user.

    the key part of my code is where the Mouse_Action is set to Pending. That is where it waits to see if the player moves the mouse more than the minimum threshold, or releases the button.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What you are doing is reverse engineering how Drag and Drop works with multiple objects. Every time you encounter a problem, the solution will get more complex. Eventually you will end up with code that probably looks my example! :) But that's how learning works, and you will fully understand how and why it works, lol.

    so, at this point the only options are to provide reduced functionality, or get more complex...

    the basic problem you are having with deselecting is like I described in the last post - it is IMPOSSIBLE to know what the user is wanting to do when the mouse is first clicked. You either have to guess, or wait until they start to do something. If you try to guess, you will be wrong 50% of the time (and the user will think your game is buggy and not working)... when the mouse button goes down, it could be to unselect the object, or it could be to start dragging the whole group. Since you don't know, you have to save what is happening now (where they clicked, what they clicked on), and then wait to see what happens next, and then act accordingly.

    what your code does right now is basically guess that the user always wants to unselect when they click a selected object (it just toggles its state), but the way C3 event triggers work, the object gets pinned to the Code_Selector at the same time as you are trying to unselect it. In event 4, adding "All_Objects - unpin" fixes that problem by unpinning the object you want to unselect. BUT, that ignores the other 50% of cases where the user wanted to start dragging that object with the rest of the group. You WILL NOT be able to have simple code that works well if it is trying to guess what the user is doing!

  • well, unfortunately, there is no easy way to make it work the way players will expect it to work...

    I tried to use the built-in Drag and Drop behaviour in your sample, but the gymnastics you have to go through to make sure the other selected objects are pinned to the one being dragged doesn't always make sense...

    the problem is that the Drag and Drop behaviour assumes that you will be dragging the object you clicked on as soon as the mouse button goes down, but if you open a folder on your computer and test the subtle nuances of how Drag and Drop works with multiple objects you will see that it can not be determined whether you want to drag or change the selection until after you start moving the mouse or release the mouse button. It goes into a "pending" mode and waits to see what the user will do.

    there are actually two different pending situations - if the CTRL key is down and you click on a selected object it needs to wait to see if you start moving the mouse to drag all the objects, or release the button to unselect the one clicked on. The other situation is if the CTRL key is not down and you click on a selected object - now it has to wait to see if you start moving the mouse to drag all the objects, or release the button to clear the selection and just pick the one clicked on.

    most people never stop to think about rules like that, but if you don't follow them people will notice that it seems broken and not doing what they expect.

    so, I started with your file and basically recreated the example I did earlier - this time without using Touch... There is definitely some complex logic in there but there is no way around it.

    I was going to start adding a pop-up menu, but since I don't have a C3 license yet, I can't edit the All_Objects family. You will need to add a sprite to the family to use as the menu background. You need to do this so that you can isolate the menu functionality from the selection/dragging code. (the Mouse code always picks the top instance in the family, if the pop-up menu is not in the family and happens to be over other objects that are in the family, the code will process the click in ways you didn't want...

    https://www.rieperts.com/games/forum/DragnDrop.c3p

  • WOW!!! that zippy site is TERRIBLE! I tried several times with different browsers and could not get the file. got lots of pop-ups, ads, fake updates, redirected to nasty sites, but no file...

  • first of all, there is no harm in having Touch in there. I am used to using it so the same code will work with a mouse, without a mouse, touch screen, tablet, phone, whatever...

    if you don't have any instances on the layout at the start, then you don't have to worry about disabling the SetColor. If there were instances, then by default, they would look like they are selected...

    in the code you posted, you are checking if the mouse is over Rocks, but in the subevent you are switching to All_Objects, then filtering those to only ones already selected. so you aren't adding anything new to the selection.

    you can get rid of the subevent, and just set Rocks.Selected to true, and enable its SetColor.

    if you have SetColor defined at the family level with the color you want, then you don't have to worry about changing it in code - just enable and disable when selecting and unselecting objects. (unless you want different objects types to have a different selected color)...

  • in the rocks.capx file I made, I added a boolean variable on the object family called "Selected". That is used to know which rocks to drag and drop. you could use that variable to know which objects to modify with your popup menu. that way you could select a bunch and have them all rotate/grow/shrink/etc at the same time... or just click on one to "select" it...

    if you don't want people to have to click to select, then when you right-click over an object, set its UID to a global variable so you know which object to apply any changes to.

  • well, curiosity got the better of me...

    here is a C2 project that can select multiple objects and drag them around...

    it uses my standard multi-touch routines, so it works with mouse or touch. (but I didn't add any logic to prevent you from using a second touch to mess with your selection/dragging)

    you can use CTRL to add or remove objects from the selection... seems pretty bullet-proof, and works the way I would expect.

    https://www.rieperts.com/games/forum/rocks.capx

  • it isn't that pick all isn't working...

    he wants to place a number of objects in his layout, and then have the ability to select a bunch of them and drag them as a group. The drag and drop behaviour will automatically pick the top object and just move that one instance.

    so he needs a expand the functionality using the pin behaviour or making his own custom drag and drop routines...

  • there is no easy way to Drag All. If you use the Drag and Drop behaviour, you would have to have a system to select all the ones you want, and then on Drag Start, pin all those objects to the one being dragged. Then unpin them on Drop. (which is what my quick example above sort of does, but there are plenty of issues that would need to be fixed).

    the other option (which I would probably do) is not use the behaviour and make your own manual drag and drop system... which I have done a couple times, but not quite for what you are doing...

  • you can add another condition to mouse over rock, and choose "Pick Top/Bottom" (it is way down at the bottom of the add condition window).

    I made a quick test to select and move several objects at the same time...

    it is not nearly complete, but shows one approach - but if you are not a programmer, then it will be tricky to make it fully functional. If I have time I might work on it some more in the next day or two...

    https://www.rieperts.com/games/forum/rocks.c3p