How do I Hold an object position inside another object?

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Since the Slider Bar object has a very basic and non-customizable look, I made one myself, with two sprites: the "line" (slid_line), and the "button" (slid_btn).

    My slid_line is pinned to a popup that goes in and out of the screen (with LiteTween behavior) as I press a button.

    I made the slid_btn always stay inside the slid_line using: slid_btn > Set X to > clamp(self.X,slid_line.X,slid_line.X+slid_line.Width).

    So when the popup moves, the slid_line moves too because it's pinned to the popup. The popup moves horizontally.

    Problem is that the slid_btn do not holds its position inside the slid_line when the slid_line moves with the popup...

    How could I make the Button holds its position inside the Line when the line moves? Is it possible?

    Thanks in advance!!

  • I'm wondering why you're using clamp for a set position? That feels unnecessary. It's possible I'm just not understanding what you're trying to do. Might you be able to post a gif or diagram explaining what you're doing?

  • Yeah, you should share your CAPX, it's hard to understand without it.

    Maybe you should temporary pin the slid_btn to the popup while it moves. Then unpin it once it stops.

  • Hey !

    I'm not sure I understood it well, but have you tried pinning the button to the slider while it's moving and unpinning it when it stops moving?

    Hope this helps. Cheers.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey ultrafop , dop2000 , brunopalermo , Thank you guys!!

    I agree, my explanation wasn't very good :s...

    Ultrafop, I'm using clamp because the Slide Bar tutorial that I found uses it. I think it's the best way of keeping the Slider Button inside the Slider Line, you will understand if you see the .capx.

    A simple example:

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

    Note that the values change when the popup moves, because the buttons do not stay in their position inside the line... I tried pinning, but It don't seems to work <img src="{SMILIES_PATH}/icon_e_confused.gif" alt=":?" title="Confused">

  • Hey ultrafop , dop2000 , brunopalermo , Thank you guys!!

    I agree, my explanation wasn't very good :s...

    Ultrafop, I'm using clamp because the Slide Bar tutorial that I found uses it. I think it's the best way of keeping the Slider Button inside the Slider Line, you will understand if you see the .capx.

    A simple example:

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

    Note that the values change when the popup moves, because the buttons do not stay in their position inside the line... I tried pinning, but It don't seems to work <img src="{SMILIES_PATH}/icon_e_confused.gif" alt=":?" title="Confused">

    Oooooooh. I may actually have a fix for this in a project of mine. but I need to get to class so I hope this works for you as I won't be able t check for a few hours. Here is what I do in my project (with my 'on start' set to every tick for your purposes. I use an array to hold my variable that's being adjusted, which you'll see in my example):

    every tick slider is not in touch -> set slider.x to (sliderbar.bboxright-slider.width) - (sliderbar.width*((5-array.at(your setting here)))/5)

    EDIT: I should add that you can change that 5 to any number you want depending on your variable and your purposes, but the set of 5's needs to be changed to the same number to work correctly.

  • ultrafop, Man, I'm sorry, as a noob I didn't get you... Perhaps you could show me with the .capx? Please? If you would, I have no hurry.

  • Hi, I'm not sure if I understood properly is this what you need?

    https://www.dropbox.com/s/3f5vd0yz9rahvze/SlidePopup1.capx?dl=0

  • tarek2 , Thank you very much! Is kind of that.

    What I need is to bring the popup In and Out without changing the value of the Slider Bar (slid_line).

    Like: If I bring the Popup In and set the value of the first bar to 60, when send the Popup Out of the screen, the value of the bar would remain 60.

    What is happening is that I set the bar value to 60, and when I send the Popup out of the screen, the bar value goes to 0.

  • tarek2 , Thank you very much! Is kind of that.

    What I need is to bring the popup In and Out without changing the value of the Slider Bar (slid_line).

    Like: If I bring the Popup In and set the value of the first bar to 60, when send the Popup Out of the screen, the value of the bar would remain 60.

    What is happening is that I set the bar value to 60, and when I send the Popup out of the screen, the bar value goes to 0.

    I see what you mean, maybe like this?

    https://www.dropbox.com/s/hhsaegcz6vwroy0/SlidePopup2.capx?dl=0

    And also you can do it in less events

    https://www.dropbox.com/s/t9i5b6z7rip1gml/SlidePopup3.capx?dl=0

    you set your minimum value at the start of the layout then it only changes if the value is changed

  • Check out this file:

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

    I had to change your code quite a lot, but it's now much simpler and I think it works as it should.

    The only problem that I didn't fix - when fullscreen scaling in project settings is disabled, touch doesn't work and positioning of text boxes is off in Chrome. It works better in Firefox. But maybe it's just on my computer..

    Oh, and I added drag&drop behavior, you can remove it, it's not actually used.

  • tarek2, Nice, you got it!

    Many thanks!!! Be blessed.

  • dop2000, Yeah!!!

    I see that I need to work with less events.

    Thank you very much!!! Be blessed.

  • No problem!

    Is it just my computer, or are TextAreas behaving really weird when you pin them to your popup? I think they don't like being pinned or moved.

    If you don't need users to enter numbers manually, I recommend you replace them with Text objects.

  • dop2000 All working fine for me, they are moving along with the popup as expected. Yeah, I replaced then in the game, it is better than I thought. Thanks!

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