Z's learning Construct thread

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • I feel bad having so many threads floating around, so I decided to try to condense all my learning into one thread.

    Today's challenge is about positioning an object over another object with a zoom applied. I'm trying to position a listbox over a sprite, which works fine, until a zoom is applied. I've not been able to find the solution on the forums. How can I handle this?

    http://dl.dropbox.com/u/6365460/positioning.cap

  • All the controls objects position themselves in relation to the window, not the layout. Also they are unaffected by zooming or scrolling. This is because they are drawn by the Windows GUI not by DirectX. A solution for your problem would be to calculate the window position of the sprite:

    -> ListBox: Set position to (Sprite.X-ScrollXLeft)*ZoomX/100, (Sprite.Y-ScrollYTop)*ZoomY/100[/code:y08gwiz9]
  • Ah ha, I was close, but was missing the scrollxleft and scrollytop part. Thank you

    Next question: Is it possible to move objects from one layer to another? Say I hypothetically added a whole bunch of objects to the wrong layer, not realizing which layer I was on, since the project tab was visible, instead of the layers tab... hypothetical question ..

  • Just drag and drop a sprite to a layer in the layer list.

  • You can also move objects to another layer during runtime with the Z Order>Move to Layer command.

    Krush.

  • Thanks guys,

    Latest question: Is there a way to have an object follow another object at an image point without having an 'every tick' condition updating the second object's position?

    What I'd like to do is have a vehicle's load be visible in the back, but since it can be one of several resources, it would be nice if it didn't have to be a special animation for each one.

    EDIT: I'm also working out how to destroy only the load of the current vehicle that's dropping off resources, without destroying the loads on the back of the other vehicles. I have a couple ideas for that, but I thought I'd include it here, in case anyone has a slick suggestion.

  • Has the problem with accessing private variables through python been fixed? I've not found a definite answer. If so, maybe I'm doing it wrong.

    object.Value('varname')

    should be correct, yes?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • With the 99.9 release you now can access private variables from python.

  • YAY!! That just made a problem I was facing much easier.

    Next questions:

    1- Can I access a global variable by way of a variable for its name?

    Something like this: global(object.value('somevar')) ?

    2- Is it possible to force an edit box to always scroll to the bottom as text is added?

    3- I have a bunch of text boxes and such on a layer. I'd like to just make them invisible, but turning the layer visibility to invisible doesn't seem to work. I also tried setting the edit box's visibility to invisible at the start of layout, but it still appears. Will I need to destroy them and create them on the fly as I need them?

    Thanks, and happy 4th!

  • Hi. I'm tired, and didn't have much time to test the new build, but I'm getting crashes when trying to access private variables from Python. Perhaps I'm missing something, though.

    In the past, I've handled this by adding my own variables to the Python instances of those objects, instead of using Construct's private variables. They can be read in Construct events by using the System object's Python() command.

    I don't think that your first question is possible in construct events, due to the special notation that Construct uses for variable names. However, it should be fine from python, provided that you use a python string variable containing the global name, possibly using the workaround mentioned above.

    Such as, the python expression: system.globalvar(object.somevar)

    As for your second question, I've only found a bit of a hack that will do that. Either append the text, then set the selection to to the end of the text, or set the selection to the end of the text, then replace the selection with the text to be added. The latter is a bit prettier in practice. The set selection action will force visibility.

    Take a look at the write() method of the PyShell class in my PythonShell. It handles writing of all text to the EditBox that is used as an interactive Python shell. A simpler example, in python:

    text = "Text to add.\n"

    EditBox.SetSelection(len(EditBox.Text), len(EditBox.Text))

    EditBox.ReplaceSelection(text.replace('\n', '\r\n'))

    The EditBox uses '\r\n' as newlines.

    I don't know about your third question. Being Windows objects, I think you may have to move them out of layout or destroy them to get that behavior.

  • Well, you can access private variables from python only with objects that have been recompiled since the fix was added. Initial tests show that accessing private variables in python work in version 99.9 with Sprite, Panel, 3dObject and Light. However it doesn't work with Text, Canvas, 3dBox or TiledBackground. So private variable access from python is about halfway there.

  • Made good progress today

    The only thing I'm having trouble with is the SpriteFont plugin's edit box. I can get SpriteFont to display text no problem, but I'm not getting anything at all when trying to use the edit box. Maybe it's late and I'm not thinking clearly. Could someone give me a quick rundown on how you'd normally set one up, or maybe a sample cap file please? I've been at it for over an hour, and have yet to even see it do anything at all.

    Thanks !

  • Spritefont is unstable and unfinished. I wouldn't recommend using it in a serious project, as there are many random and obscure bugs with it.

  • Ahh, ok. Anything else out there that has more features than the standard edit box?

  • It would appear that I cannot set the color filter on an object during the same tick that it has been created? If I put the code for it right after the creation code, it doesn't work. If I put the same code in a button, it works fine.

    Any ideas on how to solve this without gimicky bandaid code?

    Thanks,

    Z

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