i was trying around some days and searching in the forum but i cant get buttons made with ld to work
Ho do i set up an onevent for an button made with ld that should delete current lvl and load new one
Jump to content
Best Answer retrofitProductions , 13 November 2016 - 01:41 AM
To load two levels you could try something like;
local myLevel = LD_Loader:new() myLevel:loadLevel("Level01") local myControls = LD_Loader:new() myControls:loadLevel("Controls") myBtn = myControls:getLayerObject("btnLayer","button_1")
To interact with the buttons you first need to obtain the object;
myBtn = myLevel:getLayerObject("Controls","button_1")
Now you associate a function to one of the button events (onPress, onCancel or onRelease);
myBtn.onPress = btnPressed
local function btnPressed(event) print ("button pressed") end
Does this help, also the scroller demo has examples of using buttons?
Also, be careful if you are unloading and reloading a level in the same scene, as your button object for example is a reference from the old level which no longer exists.
Ideally, you would use composer and the button would change scene, which unloads the level and the new scene loads the next level.
If you need to reuse the code for all levels, have a 'switch' scene that you call that allows the unload and the it switches back to your original scene.
thank u very much this helped me much
but i have another question
i cant load 2 levels at same time
i want to load lvl 1 and controls lvl but it always says i am trying to assume loadlevel as nil value
and how can i get reference to an buttonobject if i use two lvls at same time?
tyvm for ure fast and good support
Community Forum Software by IP.Board