@@ -81,17 +81,16 @@ public void act(float delta) {
81
81
unprojectTmp .set (posx , posy , 0 );
82
82
World .getInstance ().getSceneCamera ().scene2screen (sceneScreen .getViewport (), unprojectTmp );
83
83
84
- if (currentSubtitle .type == Text .Type .TALK ) {
85
- layout .setText (style .font , currentSubtitle .str , currentSubtitle .color , maxTalkWidth , Align .center , true );
86
- } else {
87
- layout .setText (style .font , currentSubtitle .str , currentSubtitle .color , maxRectangleWidth , Align .center , true );
88
- }
84
+ float maxWidth = currentSubtitle .type == Text .Type .TALK ?maxTalkWidth :maxRectangleWidth ;
85
+
86
+ layout .setText (style .font , currentSubtitle .str , currentSubtitle .color , maxWidth , Align .center , true );
89
87
90
88
if (posx == TextManager .POS_CENTER || posx == TextManager .POS_SUBTITLE ) {
91
89
posx = (sceneScreen .getViewport ().getScreenWidth () - layout .width )/2 ;
92
- fontX = (sceneScreen .getViewport ().getScreenWidth () - maxRectangleWidth )/2 ;
90
+ fontX = (sceneScreen .getViewport ().getScreenWidth () - maxWidth )/2 ;
93
91
} else {
94
92
posx = unprojectTmp .x ;
93
+ fontX = unprojectTmp .x ;
95
94
}
96
95
97
96
if (posy == TextManager .POS_CENTER ) {
@@ -103,6 +102,7 @@ public void act(float delta) {
103
102
}
104
103
105
104
setPosition (posx - PADDING , posy - PADDING );
105
+ setSize (layout .width + PADDING * 2 , layout .height + PADDING * 2 );
106
106
107
107
if (currentSubtitle .type == Text .Type .TALK ) {
108
108
if (style .talkBubble != null ) {
@@ -111,20 +111,21 @@ public void act(float delta) {
111
111
112
112
setX (getX () - layout .width / 2 );
113
113
114
- fontX = posx - maxTalkWidth / 2 ;
115
- }
116
-
117
- setSize ( layout . width + PADDING * 2 , layout . height + PADDING * 2 );
118
-
119
- // check if the text exits the screen
120
- if (getX () < 0 ) {
121
- setX ( 0 );
122
- } else if ( getX () + getWidth () > sceneScreen .getViewport ().getScreenWidth ()) {
123
- setX ( sceneScreen .getViewport ().getScreenWidth () - getWidth ()) ;
124
- }
114
+ fontX = posx - maxWidth / 2 ;
115
+
116
+ // check if the text exits the screen
117
+ if ( getX () < 0 && getX () > - getWidth ()) {
118
+ setX ( 0 );
119
+ fontX = getX () + PADDING ;
120
+ } else if (getX () + getWidth () > sceneScreen . getViewport (). getScreenWidth () &&
121
+ getX () + getWidth () < sceneScreen . getViewport (). getScreenWidth () + getWidth ()) {
122
+ setX ( sceneScreen .getViewport ().getScreenWidth () - getWidth ());
123
+ fontX = sceneScreen .getViewport ().getScreenWidth () - layout . width / 2 - PADDING - maxWidth / 2 ;
124
+ }
125
125
126
- if (getY () + getHeight () > sceneScreen .getViewport ().getScreenHeight ()) {
127
- setY (sceneScreen .getViewport ().getScreenHeight () - getHeight ());
126
+ if (getY () + getHeight () > sceneScreen .getViewport ().getScreenHeight ()) {
127
+ setY (sceneScreen .getViewport ().getScreenHeight () - getHeight ());
128
+ }
128
129
}
129
130
}
130
131
}
@@ -141,14 +142,11 @@ public void draw(Batch batch, float alpha) {
141
142
unprojectTmp .set (subtitle .x , subtitle .y , 0 );
142
143
World .getInstance ().getSceneCamera ().scene2screen (sceneScreen .getViewport (), unprojectTmp );
143
144
144
- float bubbleX = unprojectTmp .x - style .talkBubble .getMinWidth () * scale / 2 ;
145
-
145
+ float bubbleX = unprojectTmp .x - style .talkBubble .getMinWidth () * scale / 2 ;
146
146
float bubbleY = getY () - style .talkBubble .getMinHeight () * scale + 2 ;
147
-
148
- // style.talkBubble.draw(batch, bubbleX, bubbleY, style.talkBubble.getMinWidth() * scale,
149
- // style.talkBubble.getMinHeight() * scale);
150
147
151
- style .talkBubble .draw (batch , bubbleX , bubbleY , style .talkBubble .getMinWidth () * scale ,
148
+ if (bubbleX + style .talkBubble .getMinWidth () * scale < getX () + getWidth () && bubbleX > getX ())
149
+ style .talkBubble .draw (batch , bubbleX , bubbleY , style .talkBubble .getMinWidth () * scale ,
152
150
style .talkBubble .getMinHeight () * scale );
153
151
}
154
152
0 commit comments