882+ Bug/Changes due to new text handling.

If you set an object text to blank (ie: mytext.text = “”) positioning information for that object appears to be lost as a result of the rendering optimizations from this build.

A workaround is to set text to " " instead, but this adds an indent to text. [import]uid: 41884 topic_id: 30117 reply_id: 330117[/import]

(No way to edit my original post? Weird)

Well, the only real workaround is to save the original X and Y positions manually when you create the text object.

local object = display.newText("", 32, 47) object.originalX = 32 object.originalY = 47

This, on the other hand, does not work (probably because the text command is executing first somehow?)

object.originalX = object.x -- set to zero object.originalY = object.y -- set to zero object.text = "" [import]uid: 41884 topic_id: 30117 reply_id: 120561[/import]

In the Mac Simulator (build 883) this is working:

object = display.newText( "", 32, 47)  
print( "text x,y = ", object.x, object.y )  
  
timer.performWithDelay(500, function()  
 print( "text x,y = ", object.x, object.y )  
 end )  

It displays 32 and 47 both times, which indicates that the position information is still there.

Could you post a full code sample that is not working and what you are testing it on.

Thanks,
Tom [import]uid: 7559 topic_id: 30117 reply_id: 120587[/import]

Hi Tom,

I originally noticed this issue upon upgrading to .883 and running a build I haven’t touched in a few weeks. The build was using my Typer() code, which basically works like this:

  1. Set the string to “”
  2. Use … to add each character to the string in a timed fashion
  3. Reset the reference point, but do not restate the x/y positions.

So as best I can tell, if you do this:

  1. Set an existing string using TopLeft to “”
  2. Set the reference point back to TopLeft
  3. Set the existing string to a real word
    Pre 880 builds: Text string is written using the existing X/Y position and reference point
    883: Text string is written using either a center reference point or some modified position.

Here’s some sample code; in 870 series the text would start from the same reference point.

[code]-- TEST PROJECT: Find out what’s going on with text objects that become empty.
– ? To test, press anywhere on screen to update the text.

– Output to console (needed for SublimeText2 to show print(“statements”))
io.output():setvbuf(“no”)

– Create the background clickable object
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(0, 0, 0)

– Create the text object
local textObject = display.newText(“Hello!”, 30, 30, “HelveticaNeue”, 18)
textObject:setReferencePoint(display.TopLeftReferencePoint)
print(“textObject.x, textObject.y”, textObject.x, textObject.y) – reports 30, 30

– FUNCTION: Prints a new string. (Called by wipeText)
local function newString()
textObject:setReferencePoint(display.TopLeftReferencePoint)
textObject.text = “Tappity tap tap”
textObject:setReferencePoint(display.TopLeftReferencePoint)
print(“textObject.x, textObject.y”, textObject.x, textObject.y) – reports -8, 29 as the new position
end

– FUNCTION: Wipes the text and then displays a new String.
local function wipeText()
textObject.text = “”
textObject:setReferencePoint(display.TopLeftReferencePoint)

timer.performWithDelay(200, newString)
end

– Add wipeText as a touch function
background:addEventListener(“touch”, wipeText)[/code]

(The number of reference point lines is probably excessive; I can get the same result with less, but for troubleshooting sake they are all there to enable/disable at will.)
[import]uid: 41884 topic_id: 30117 reply_id: 120672[/import]

(No way to edit my original post? Weird)

Well, the only real workaround is to save the original X and Y positions manually when you create the text object.

local object = display.newText("", 32, 47) object.originalX = 32 object.originalY = 47

This, on the other hand, does not work (probably because the text command is executing first somehow?)

object.originalX = object.x -- set to zero object.originalY = object.y -- set to zero object.text = "" [import]uid: 41884 topic_id: 30117 reply_id: 120561[/import]

In the Mac Simulator (build 883) this is working:

object = display.newText( "", 32, 47)  
print( "text x,y = ", object.x, object.y )  
  
timer.performWithDelay(500, function()  
 print( "text x,y = ", object.x, object.y )  
 end )  

It displays 32 and 47 both times, which indicates that the position information is still there.

Could you post a full code sample that is not working and what you are testing it on.

Thanks,
Tom [import]uid: 7559 topic_id: 30117 reply_id: 120587[/import]

Hi Tom,

I originally noticed this issue upon upgrading to .883 and running a build I haven’t touched in a few weeks. The build was using my Typer() code, which basically works like this:

  1. Set the string to “”
  2. Use … to add each character to the string in a timed fashion
  3. Reset the reference point, but do not restate the x/y positions.

So as best I can tell, if you do this:

  1. Set an existing string using TopLeft to “”
  2. Set the reference point back to TopLeft
  3. Set the existing string to a real word
    Pre 880 builds: Text string is written using the existing X/Y position and reference point
    883: Text string is written using either a center reference point or some modified position.

Here’s some sample code; in 870 series the text would start from the same reference point.

[code]-- TEST PROJECT: Find out what’s going on with text objects that become empty.
– ? To test, press anywhere on screen to update the text.

– Output to console (needed for SublimeText2 to show print(“statements”))
io.output():setvbuf(“no”)

– Create the background clickable object
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(0, 0, 0)

– Create the text object
local textObject = display.newText(“Hello!”, 30, 30, “HelveticaNeue”, 18)
textObject:setReferencePoint(display.TopLeftReferencePoint)
print(“textObject.x, textObject.y”, textObject.x, textObject.y) – reports 30, 30

– FUNCTION: Prints a new string. (Called by wipeText)
local function newString()
textObject:setReferencePoint(display.TopLeftReferencePoint)
textObject.text = “Tappity tap tap”
textObject:setReferencePoint(display.TopLeftReferencePoint)
print(“textObject.x, textObject.y”, textObject.x, textObject.y) – reports -8, 29 as the new position
end

– FUNCTION: Wipes the text and then displays a new String.
local function wipeText()
textObject.text = “”
textObject:setReferencePoint(display.TopLeftReferencePoint)

timer.performWithDelay(200, newString)
end

– Add wipeText as a touch function
background:addEventListener(“touch”, wipeText)[/code]

(The number of reference point lines is probably excessive; I can get the same result with less, but for troubleshooting sake they are all there to enable/disable at will.)
[import]uid: 41884 topic_id: 30117 reply_id: 120672[/import]