Z's learning Construct thread

For questions about using Classic.

Post » Fri Jul 02, 2010 7:54 pm

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?

[url:3idvfqj7]http://dl.dropbox.com/u/6365460/positioning.cap[/url:3idvfqj7]
B
3
G
2
Posts: 35
Reputation: 745

Post » Fri Jul 02, 2010 9:12 pm

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:
[code:y08gwiz9]-> ListBox: Set position to (Sprite.X-ScrollXLeft)*ZoomX/100, (Sprite.Y-ScrollYTop)*ZoomY/100[/code:y08gwiz9]
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Fri Jul 02, 2010 9:31 pm

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 .. :roll:
B
3
G
2
Posts: 35
Reputation: 745

Post » Sat Jul 03, 2010 3:32 pm

Just drag and drop a sprite to a layer in the layer list.
B
11
S
2
G
3
Posts: 100
Reputation: 2,150

Post » Sat Jul 03, 2010 5:36 pm

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

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Sun Jul 04, 2010 4:32 pm

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.
B
3
G
2
Posts: 35
Reputation: 745

Post » Sun Jul 04, 2010 11:41 pm

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?
B
3
G
2
Posts: 35
Reputation: 745

Post » Sun Jul 04, 2010 11:50 pm

With the 99.9 release you now can access private variables from python.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Jul 05, 2010 5:00 am

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!
B
3
G
2
Posts: 35
Reputation: 745

Post » Mon Jul 05, 2010 6:42 am

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.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 10 guests