在电晕 SDK 中如何为图像添加标签(文本)
我创建了我的图像如下
local item = display.newImageRect('images/foo.png',70,70);
item.x = 50;
item.y = 50;
Run Code Online (Sandbox Code Playgroud)
如何在图片中添加文字?
非常感谢
小智 5
要将文本添加到图像,使其看起来“粘”在图像上,您可以创建对象(如您所愿)以及直接在其上方的文本对象。然后,创建一个组并将它们都放入其中。
以下是如何做到这一点的示例:
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 )
Run Code Online (Sandbox Code Playgroud)
然后,要移动它,只需修改“myGroup”的 x/y。
希望有帮助!