In Corona SDK how to add label(text) to images?

心不动则不痛 提交于 2019-12-08 04:10:59

问题


In corona SDK how to add label(text) to images

I have created my image as follow

    local item = display.newImageRect('images/foo.png',70,70);
    item.x = 50;
    item.y = 50;

How to add a text to the image?

Many Thanks


回答1:


To add text to the image, so it appears to "stick" to the image, you could create the object (as you have) and also the text object directly above it. Then, create a group and stick them both in it.

Here is an example of how that could be done:

local myGroup = display.newGroup()

local item = display.newImageRect('images/foo.png',70,70)
item.x = 50
item.y = 50

local text = display.newText( "My Text", 0, 0, "Helvetica", 18 )
text:setTextColor( 0, 0, 0, 255 )

-- insert items into group, in the order you want them displayed:
myGroup:insert( item )
myGroup:insert( text )

Then, to move it around, just modify the x/y of 'myGroup'.

Hope that helps!



来源:https://stackoverflow.com/questions/6408687/in-corona-sdk-how-to-add-labeltext-to-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!