Text Problem

I have two quick questions:

  1. What is the padding thickness on text? I noticed that when you place it at 0, 0 it still isn’t touching the edge. Also, every time my score gets another place value, it moves over to the left. Is its reference point changing or something? I tried setting its X to 0 every time the game updates, but it didn’t solve the problem.

Edit: I think it’s reference point changes every time you use the method object.x = ?. Am I correct?

  1. How can I get my score to update whenever it’s value is changed? Right now, it stays at 0 the whole time. And if I were to put a timer on it, it creates a memory leak as the text is displaying over itself. – I ANSWERED THIS [import]uid: 103624 topic_id: 18146 reply_id: 318146[/import]

I answered my second question. Here’s the code if anyone is wondering.

[lua]display.setStatusBar(display.HiddenStatusBar)
– local storyboard = require “storyboard”
require (“sprite”)
require(“physics”)

function loadGame()
displayScore()
end

function createPiggyBank()
local piggyBankSheet = sprite.newSpriteSheet(“visuals/game_piggybank.png”, 96, 96)
local piggyBankSet = sprite.newSpriteSet(piggyBankSheet, 1, 6)
sprite.add (piggyBankSet, “pigmleft”, 1, 3, 250, 0)
sprite.add (piggyBankSet, “pigmright”, 4, 3, 250, 0)
piggyBank = sprite.newSprite(piggyBankSet)
physics.addBody(piggyBank, “static”)
piggyBank.x = display.contentWidth / 2
piggyBank.y = 397
function piggyBank:collision(event)
if(event.other.type == “coinsilver”) then
scoreValue = scoreValue + 5
print(“Silver Coin!”)
elseif(event.other.type == “coingold”) then
scoreValue = scoreValue + 10
print(“Gold Coin!”)
elseif(event.other.type == “rock”) then
print(“Rock!”)
end
event.other:removeSelf()
end
piggyBank:addEventListener(“collision”, piggyBank)
end

function displayScore()
scoreValue = 0
scoreText = display.newText("Score: " … scoreValue, 8, 8, native.systemFont, 36)
end

function onUpdate()
scoreText.text = "Score: " … scoreValue
end

loadGame()
timer.performWithDelay(1, onUpdate, 0)[/lua] [import]uid: 103624 topic_id: 18146 reply_id: 69402[/import]

Hey, lKinx, reading up on the following thread may answer your question regarding the text alignment:

https://developer.anscamobile.com/forum/2011/08/27/text-alignment-bug

Once I understood what’s discussed on the thread (i.e., the content of the conversation between hdez and richard9), I’ve had no trouble understanding how dynamically updated text are placed on screen.

In addition, later on, I stumbled across newRetinaText function (in Jonathan Beebe’s awesome beebegames class v1.8), and once I included it to my project, I’ve had no trouble aligning the dynamically updated text.

I hope this helps you somewhat.

Naomi

[import]uid: 67217 topic_id: 18146 reply_id: 69409[/import]

Thanks! That fixed the alignment problem, but my first question still remains.

  1. What is the padding thickness on text? I noticed that when you place it at 0, 0 it still isn’t touching the edge. [import]uid: 103624 topic_id: 18146 reply_id: 69412[/import]

Hey, lKinx, I’m no expert, and I’m just conjecturing – so someone more knowledgeable would have a real answer to your question. That said, I have a feeling that each font/text may have its own padding, and perhaps, padding would vary depending on what character you use (i.e., “A” or “i” or what character are you using to check the padding?) What font/font-style you use might also determine the padding…

Naomi [import]uid: 67217 topic_id: 18146 reply_id: 69420[/import]

So do I just have to guess to make my text have the same distance from the edge as my buttons? Or could I somehow fill the entire text area with a solid color and go from there? [import]uid: 103624 topic_id: 18146 reply_id: 69424[/import]

Anyone know? [import]uid: 103624 topic_id: 18146 reply_id: 69472[/import]

Anyone…? [import]uid: 103624 topic_id: 18146 reply_id: 69504[/import]

I hate to keep bumping, but this is bothering me. :confused: [import]uid: 103624 topic_id: 18146 reply_id: 69551[/import]

Hey IKinx,

I think we’ve previously spoken about this, but as a test user if you have an “urgent” issue (as in, one that you feel requires constant bumping) you should be using this support; http://www.anscamobile.com/corona/support/

If you provide plug and play code you may get more assistance in a thread because users will be able to play with your project/code.

You could line up your text with your button by using a left reference point and establishing the padding being used, supposing there is some padding even if your setting states 0. (I think this may be remedied in a daily build but would have to check notes.)

You would then consistently know how to position to line up with any buttons against the left side of the screen.

Peach :slight_smile:

[import]uid: 52491 topic_id: 18146 reply_id: 69655[/import]