Hello,
I’m trying to port the HelloWorld example template project (automatically created with cocos2d-x scripts) using LUA Binding.
When I try to use the setPosition on label Android app will crash. If I remove the setPosition instruction the label appears at
the bottom-left of the screen. Note that the .cpp version works well.
local winSize = CCDirector:sharedDirector():getWinSize()
local function helloWorldScene()
@ local scene = CCLayer:node()@
@ local menuPopup@
@ local function menuCallbackExitApp()@
@ CCDirector:sharedDirector():endToLua()@
@ end@
@ — add a popup menu@
@ local closeItem = CCMenuItemImage:itemWithNormalImage(“CloseNormal.png”, “CloseSelected.png”)@
@ closeItem:setPosition(winSize.width - 20 , 20)@
@ closeItem:registerScriptHandler(menuCallbackExitApp)@
@ menuPopup = CCMenu:menuWithItem(closeItem)@
@ menuPopup:setPosition(0, 0)@
@ — add a background @
@ local pSprite = CCSprite:spriteWithFile(“HelloWorld.png”)@
@ pSprite:setPosition( winSize.width/2, winSize.height/2 )@
@ — add a label@
@ local pLabel = CCLabelTTF:labelWithString(“Hello World”, “Arial”, 24.0)@
@ — ####### THE FOLLOWING LINE CAUSE ANDROID CRASH ######@
*pLabel:setPosition( winSize.width/2, winSize.height - 50 )*
@ scene:addChild(pSprite)@
@ scene:addChild(menuPopup)@
@ scene:addChild(pLabel)@
@
@ return scene
end