Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Buttons made with LD
Started by juen.philipp Nov 10 2016 04:07 AM

5 replies to this topic
buttons made help eve

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")



[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

juen.philipp

[GLOBAL: userInfoPane.html]
juen.philipp
  • Observer

  • 5 posts
  • Corona SDK

Hi there

 

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

 

 

pls help

 

wfw cloud

 

 



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

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

The function;

local function btnPressed(event)
  print ("button pressed")
end

Does this help, also the scroller demo has examples of using buttons?



[TOPIC: post.html]
#3

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

juen.philipp

[GLOBAL: userInfoPane.html]
juen.philipp
  • Observer

  • 5 posts
  • Corona SDK

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 :)



[TOPIC: post.html]
#5

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

  Best Answer

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")





[TOPIC: post.html]
#6

juen.philipp

[GLOBAL: userInfoPane.html]
juen.philipp
  • Observer

  • 5 posts
  • Corona SDK

ou yeah thank u really much 

 

i was in despair

 

i really love director x will buy it in the next time :D




[topic_controls]
[/topic_controls]