AllanR's Recent Forum Activity

  • performance wise I don't think it will make a difference either way - you have to decide which way is better for you to manage. if you do keep them as separate sprites, then put them in a family because you don't want to have to issue 100 tweens! your code should be no longer than Kyatric's.

  • nice ROJOhound! I like the way you did the rotate, and duplicate. I got around the UID issue by not actually deleting the objects - just moving them off-screen. Eventually at save time they would be destroyed and the undo stack purged.

  • here is a start on the Undo/redo...

    at the moment it can only undo the Create actions and the Drag/Drop actions. the undo list is not limited at this point, so you could do (and undo) thousands of actions.

    if you do a bunch of actions, then undo half of them, then start doing new actions, the redo list is truncated at that point since any potential redo's don't make sense anymore...

    any other types of actions you want to be able to undo will each require their own section in the log action function and the undo/redo events...

    for the rotate action, you just want to log the start and end angle, not every 0.35 degree change - it would take forever to undo!

    and the Z-order change will have to get the object back into the original place - I have to think a bit about that one, and I am out of time today...

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

  • 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).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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...

AllanR's avatar

AllanR

Member since 21 Nov, 2013

Twitter
AllanR has 23 followers

Trophy Case

  • 11-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Forum Hero Made 1,000 posts in the forums
  • Popular Game One of your games has over 1,000 players
  • x2
    Coach One of your tutorials has over 1,000 readers
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

20/44
How to earn trophies