Question

I am trying to move a display object that is hiding over the right side of the screen, into the scene. It works wonderfully with images (i.e. the background), but not with texts (the coords seem correct from debugging them with print(), but they never display, I already tried the obj:toFront). I thought that they may work inside display objects, so I put everything in a display Object: Nothing. Just the text? Neither. Anyone knows why/how to override this?

 function tscreen:init()
    local textGroup = display.newGroup()

    local menuBackground = self:getBtn("src/bgMenu.png")
    menuBackground.isVisible = false
    menuBackground.anchorX = 0.5
    menuBackground.anchorY = 0.5
    self.menuBackground = menuBackground

    local optionsText = {
        parent = textGroup,
        text = "Hello World",     
        x = centerX,
        y = centerY,
        width = 128,     
        font = native.systemFontBold,   
        fontSize = 14,
        align = "center" 
    }
    local workText = display.newText( optionsText )
    workText:setFillColor( 1, 0, 0 )
    setPos(textGroup, W, 0) 
            --setPos() is a custom function that assigns x and y coords
    textGroup.isVisible = false

    self.textGroup = textGroup
  end

 function tscreen:show()
    local menuBackground = self.menuBackground
    local textGroup      = self.textGroup

    local inTime        = 1200

    setPos(menuBackground, 2*W + centerX, centerY)
    menuBackground.isVisible = true

    setPos(textGroup, W, 0)
    textGroup.isVisible = true

    self:cancelTween(menuBackground)
    self:cancelTween(textGroup)

    menuBackground.tween = transition.to(menuBackground, {time = inTime, transition = easing.outExpo, x = centerX,
        onComplete = function()
        tscreen:cancelTween(menuBackground)
    end
    })

    textGroup.tween = transition.to(textGroup, {time = inTime, transition = easing.outExpo, x = 0,
        onComplete = function()
        tscreen:cancelTween(textGroup)
        print(getPos(textGroup), textGroup.width, textGroup.height)
    end
    })

end

I have the starters edition of Corona, so I don't have the recently implemented Composer API. Maybe this isn't the most appropriate site to post this query since there already is a Corona SDK forum, but I'm trying anyway.

Was it helpful?

Solution

I'm not seeing anything wrong, but a group should not be necessary. Verify that the text can be seen ever: in the init(), do

local optionsText = {
    text = "Hello World",     
    x = 0,
    y = 100,
}
local workText = display.newText( optionsText )
workText:setFillColor( 1, 1, 1 )

If you can't see the text then something else is going on, maybe your init() is not being called or such. Once you see it, change the parameters to what you want (fill color etc), and test. If still works, add a transition, right after, in the init():

local easeXto100 = {
     time = 2000, 
     transition = easing.outExpo, 
     x = 100,
     onComplete = function() print('did you see text move from x=0 to 100?') end
}
transition.to(workText, easeXto100)

If you see it move, then move the relevant parts of code to your show(), if now it disappears this will give you clue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top