text object problem

Just started using Construct 2? Post your questions here

Post » Fri Apr 25, 2014 2:14 am

okay so I press enter to make paragraph 1 appear, using "set text". I want to press enter again to change the text to paragrpah 2, however it doesn't erase paragrpah 1, rather paragraph 2 appears OVERTOP of it. how do I fix this?

capx: http://biancagames.com/textbug.capx
screenshot:
Image
B
15
S
2
Posts: 105
Reputation: 1,182

Post » Fri Apr 25, 2014 7:25 am

@DialgaBrite, one thing to take note of is that you can re-use a Text object to display text and you don't need to keep creating the Sprite. So I removed the repeated creation of your Sprite and Text object and put the Text on Layer1 and the Sprite on Layer0. The layers were arranged in the layers tab so that the Text would be displayed on top of the Sprite. The order from bottom to top in the layers list indicates the order of rendering the Objects on each layer. In addition, since you didn't want the Sprite or Text object showing at first, I set the Initial Visibility in the Editor to Invisible for both of them. To support the triggering of making the Sprite and Text Object visible, I added a global variable that was initially set to 0 but then later set to 1 to indicate that the Sprite and Text objects were made visible. I knew that the first message was to be set first so that's where I put the Sub-Event for making the Sprite and Text objects visible. Now just like with visibility, we use that 'paragraph' instance variable on the Text object so that when it is 0 and Return is pressed we set the text to the first message and Add 1 to the 'paragraph' instance variable. 'paragraph' being 1 indicates to us that the first message has been set and that the next time Return is pressed that the text should set to the second message. So we have that additional event that is checking for when 'paragraph' is 1. Now in order to alternate we have to have the second message event subtract 1 from 'paragraph' so that we go back the initial state of waiting to set the text to the first message.
You do not have the required permissions to view the files attached to this post.
B
9
S
2
G
1
Posts: 41
Reputation: 708

Post » Fri Apr 25, 2014 1:06 pm

509Dave16 wrote:@DialgaBrite, one thing to take note of is that you can re-use a Text object to display text and you don't need to keep creating the Sprite. So I removed the repeated creation of your Sprite and Text object and put the Text on Layer1 and the Sprite on Layer0. The layers were arranged in the layers tab so that the Text would be displayed on top of the Sprite. The order from bottom to top in the layers list indicates the order of rendering the Objects on each layer. In addition, since you didn't want the Sprite or Text object showing at first, I set the Initial Visibility in the Editor to Invisible for both of them. To support the triggering of making the Sprite and Text Object visible, I added a global variable that was initially set to 0 but then later set to 1 to indicate that the Sprite and Text objects were made visible. I knew that the first message was to be set first so that's where I put the Sub-Event for making the Sprite and Text objects visible. Now just like with visibility, we use that 'paragraph' instance variable on the Text object so that when it is 0 and Return is pressed we set the text to the first message and Add 1 to the 'paragraph' instance variable. 'paragraph' being 1 indicates to us that the first message has been set and that the next time Return is pressed that the text should set to the second message. So we have that additional event that is checking for when 'paragraph' is 1. Now in order to alternate we have to have the second message event subtract 1 from 'paragraph' so that we go back the initial state of waiting to set the text to the first message.


You really lost me there, but I suppose I will download it. I think putting the box on a different layer is uneccessary. And why do we need a global value to tell if it's visible if we can just make it visible?

edit: your edit fixes the problem, but can you PLEASE explain why much more simply?


also why are we subtracting 1 from the paragraph value? won't we need to only add to it if there are 3 or more paragraphs?
B
15
S
2
Posts: 105
Reputation: 1,182

Post » Fri Apr 25, 2014 1:12 pm

You don't need a global variable to check for visibility !

From the manual :

Is visible
True if the object is currently visible. Invert to test if invisible. This only tests the visibility set by the Set visible action; it is not affected by the object being offscreen, having 0 opacity, or being on an invisible layer.
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Fri Apr 25, 2014 1:19 pm

http://biancagames.com/textbug3.capx
this one is almost identical to the first, but it doesn't produce the problem. what gives? I really would like to understand what you did, @509dave16. I took out the use of another layer as well as having a global value for "has pressed return", and also the "subtract 1 from paragraph". those clearly had nothing to do with it and were completely uneccessary. I also have no idea why you wanted to subtract when normally there will be more than two paragraphs and we will want to add.

edit: added back in the "set to bottom of layer" every tick. that's not the problem either. Why did you change so much stuff unneccessarily?


edit 2: the problem was creating the objects in the same event where I show paragraph 1. why?
B
15
S
2
Posts: 105
Reputation: 1,182

Post » Fri Apr 25, 2014 2:19 pm

You're right @Granpa. I was just trying to quickly fix @DialgaBrite .capx and explain it. @DialgaBrite, I didn't know that you were going to have multiple paragraphs. But if that is the case then yes you don't need the 'subtract 1 from paragraph'. As to why there was a problem creating objects every time, I'm not sure. I'd have to look back at your original .capx and look again. Sorry if I caused more confusion than help.
B
9
S
2
G
1
Posts: 41
Reputation: 708

Post » Fri Apr 25, 2014 3:16 pm

509Dave16 wrote:You're right @Granpa. I was just trying to quickly fix @DialgaBrite .capx and explain it. @DialgaBrite, I didn't know that you were going to have multiple paragraphs. But if that is the case then yes you don't need the 'subtract 1 from paragraph'. As to why there was a problem creating objects every time, I'm not sure. I'd have to look back at your original .capx and look again. Sorry if I caused more confusion than help.


I found the problem. It's creating the objects in the same event as where paragraph 1 is set. You fixed it by creating them at start of layout instead. I am still wondering though why this made a difference. Sorry if I seemed rude btw. I just thought a lot of your other changes were unneccessary.
B
15
S
2
Posts: 105
Reputation: 1,182

Post » Fri Apr 25, 2014 3:53 pm

Yes. Quite a few of the changes were un-necessary and very badly done. Oh I just thought of why the one problem was persisting due to repeated object creation. The first message 'paragraph 1' is being drawn on top of message 'paragraph 2! more text here!'. And that's because the Red Box Sprite is always drawn first on the bottom layer, because that's the layer you had it originally set to through that 'Every tick' Event. So the Red Box Sprite never get's drawn over the Text objects to provide a surface if you will on which to render a new Text object. But the Text Objects get drawn over each whenever they are created. So that's how you see the text of the longer message.
B
9
S
2
G
1
Posts: 41
Reputation: 708

Post » Fri Apr 25, 2014 9:23 pm

509Dave16 wrote:Yes. Quite a few of the changes were un-necessary and very badly done. Oh I just thought of why the one problem was persisting due to repeated object creation. The first message 'paragraph 1' is being drawn on top of message 'paragraph 2! more text here!'. And that's because the Red Box Sprite is always drawn first on the bottom layer, because that's the layer you had it originally set to through that 'Every tick' Event. So the Red Box Sprite never get's drawn over the Text objects to provide a surface if you will on which to render a new Text object. But the Text Objects get drawn over each whenever they are created. So that's how you see the text of the longer message.



Sorry, but I really didn't understand what you just said. The every tick action moves it to Z-order bottom of the same layer, not a different layer.
B
15
S
2
Posts: 105
Reputation: 1,182

Post » Fri Apr 25, 2014 9:40 pm

Oh sorry you're right. There is a z-order on every layer sorry about that. I haven't been using Construct 2 for very long so I mix z-order and layers up pretty frequently. Anyways on that layer the Red Box Sprite is always drawn first then you have the a Text objects drawn over the top. However you keep having Text objects drawn on top of each other, so if one has longer text than the other then you'll see it. Like in the case of your 'paragraph 2' message it's longer so when you have the Text object that has the 'paragraph 1' text created it is drawn on top only covering a portion of the 'paragraph 2' message below it.
B
9
S
2
G
1
Posts: 41
Reputation: 708

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest