In cocos2d-x + Lua scenarios, we can’t use setonentercallback (func) and other functions to set the callback solution


Cocos2d-x + Lua is not perfect. When using these functions, an error will be reported


as a result oflua_cocos2dx_auto.cppIt didn’t come true at all
In cocos2d-x + Lua scenarios, we can't use setonentercallback (func) and other functions to set the callback solution

A typical scenario of this problem is that a scene does not know when it is loaded or removed, and this requirement is particularly useful. For example, we need to start playing animation after the scene is displayed and stop playing animation when the scene is removed. The solution is to useregisterScriptHandlerMethods like this:

local TestScene = class("TestScene", function()
  return cc.Scene:create()

function TestScene.create()
  local scene =

    if eventType == "enterTransitionFinish" then
      --The scene is loaded
    elseif eventType == "exitTransitionStart" then
      --The scene is about to be removed

  return scene

I don’t know why the eventtype parameter passed in by cocos2d-x 3.2 to the callback function is not a numeric constant, but a string, which is used in other online tutorialscc.NODE_ON_ENTERThe judgment is invalid now. I don’t understand the setting of eventtype as a string, but it doesn’t matter whether it’s a numeric constant or a string. Just use it.

Recommended Today

Array of algorithms — sum of three numbers

Sum of three numbers difficultysecondary Here is an array of N integersnums, judgmentnumsAre there three elements a, B, C in a such that a + B + C = 0? Please find all triples that satisfy the condition and do not careful:The answer cannot contain duplicate triples. Example:Given array nums = [- 1, 0, […]