How do I Delete all instances even on different layouts

0 favourites
  • 11 posts
From the Asset Store
This music pack covers differents situations for visual novels, anime games and many more!
  • If I press a button to create a new Object (sprite) on layout 1 then move on to layout 2, How would I have a button destroy the instance I created on Layout 1 so that when I go back it's no longer there.

    Thanks for any advice

    *edit* btw, I'm using persistent sprites that i want to choose if they are onscreen on layout 1 or 2 but not both at the same time. thanks

  • I don't think you can.

    Maybe destroy the object on exiting laytout 1 and recreate it later as needed?

  • Wen you leave a layout, everything is destroyed unless it is given the Global property.

  • Wen you leave a layout, everything is destroyed unless it is given the Global property.

    The character is persistent and stays on the layer you drag him out / away from the 'bottom bar' a variable says he's out and lets him stay in that layout when leaving and returning

    I don't think you can.

    Maybe destroy the object on exiting laytout 1 and recreate it later as needed?

    Would these need code for every layout to save a position of a character if the variable for it says it's out (up from the menu bar)

    I'll share this link so you can see what's going on so far:

    http://www.jmkit.com/html5/testproject/index.html

    Things to bare in mind:

    • You can click and drag the character out to one place (say blue) - leave and he's still out, go back to blue and is in the position you put him...

    you can then drag him back to the bottom where he'll pop down and stay there through all the layouts.

    every button goes to a new layout

    However, the problem comes when say you drag him out in the blue place - then go to the green place and click the outline to bring him back down, then immediately drag him out to the green place he'll be in both the green and blue place <img src="{SMILIES_PATH}/icon_e_surprised.gif" alt=":o" title="Surprised"> (that goes for any variation on place to place, you can get him out in all 3 layouts with that method)

    The resetting him from a layout he's not on seems like the only issue i'm having.

    Thanks for your replies so far!

    check out how i'm doing it code wise here: https://www.dropbox.com/s/6w3hkgdfmlf7e ... .capx?dl=0

  • > I don't think you can.

    >

    > Maybe destroy the object on exiting laytout 1 and recreate it later as needed?

    >

    Would these need code for every layout to save a position of a character if the variable for it says it's out (up from the menu bar)

    Depending on how advanced your game is going to get this advice may or may not apply:

    Honestly, if all that you are changing is background colors, you should just use different layers for backgrounds and keep it all on one layout. Then just toggle layer visibility to change the background color using the buttons. That way you won't have to track every sprites positions in a global object (like Array or Hash) and repopulate them every layout swap.

    If you MUST have multiple layouts, I would try making your little rabbit sprite global first. If that doesn't work, then you get to use an array/hash object and track all of the positions on screen of every object that you want to exist on multiple layouts and repopulate the screen each time you change layouts.

  • Can you post a capx or video of the issue in question? This is obviously in need of a more in depth analysis.

  • If you MUST have multiple layouts, I would try making your little rabbit sprite global first. If that doesn't work, then you get to use an array/hash object and track all of the positions on screen of every object that you want to exist on multiple layouts and repopulate the screen each time you change layouts.

    lol yes I MUST! this is just a small isolated element of the overall project, separated so I could focus on it specifically, but ultimately I'm re-creating a game I made in flash ( http://www.jmkit.com/playsets/ ) while also adding new features that Construct will allow, and If you see the video posted below, you'll see its so close to how I'd like it to be it's just one element that seems like a tiny variable / iid or something away from perfect..

    Can you post a capx or video of the issue in question? This is obviously in need of a more in depth analysis.

    I did include the capx in al link in my previous reply, but it'll be clearer with a video (I show the code to the right and a debug view of the variables etc)

    VIDEO:

    Subscribe to Construct videos now
  • Watching the video helped. I am assuming you will be adding more stuff to those layouts. If that's true then I would I would suggest you follow this logic.

    On end of layout set player.x and player.y to two variables called playerPositionX and playerPositionY.

    On Start of new layout set player.x and player.y to their respective variables.

  • On end of layout set player.x and player.y to two variables called playerPositionX and playerPositionY. On Start of new layout set player.x and player.y to their respective variables.

    Seems like that would always have him on screen though, when what i want is that he's only on (when dragged out) one layout at a time - visualise a dolls house with a box of toys, going from room to room with the box, you place a toy from the box into a room, move to the next room, the toy isn't in that room, or the box... That much I can achieve with what I have right now..

    The difference between digital and real life though is that (and this sounds theoretically possible and is what i'm attempting) to find that toy again in the real world, you'd have to look back through all the rooms, to pick it up and put it back in the box, in digital I'd like to not have to go looking for it, but click the placeholder to have it pop back into the 'box' ready for use again without being duplicated in a weird way lol

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • is this what you tried to achieve?

    if so the answer was half way there ... i just moved some actions you did on the button press

    you can also create a function and instead of duplicating all those actions just add 1 action to trigger 1 function then call the function when u want... and will do exactly what i did there

    https://mega.nz/#!wQM0mKKR!Hr0O0-zPx8C3 ... p3FSH9uRjo

    not sure if u want him to be present on the other sides also...

  • not sure if u want him to be present on the other sides also...

    Hi I appreciate you delving in to the code to help out, but no that's not what I'm trying to do, if you read my real world example (see my previous post) and watch the video

    Subscribe to Construct videos now

    , i'm just trying to get the outline button to bring him back (even if he's not on that layout) and be able to bring him out again without it duplicating the sprite

    The problem only comes when you click the outline to bring him back (on a layout he wasn't out in) then strait away drag him out again, then he shows up on more than one layout..

    So basically I could get away with having that outline button completely erasing any instance of the sprite and re-creating it, i just can't find away to remove the persistant sprite from a different layout

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