Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Add menu buttons — Gideros Forum

Add menu buttons

CreekmonkeyCreekmonkey Member
edited March 2017 in General questions
I am using the Game Master Template posted by ar2rsawseen I believe. While trying to add more buttons to one of the menus it seems that four buttons are all that it will allow. What would I need to modify to allow for more menu buttons?

Comments

  • piepie Member
    @Creekmonkey can you be more specific?
    I suppose that you are trying to add buttons to start.lua (https://github.com/ar2rsawseen/GameTemplate/blob/master/start.lua)
    I didn't try it but you should be able to do it by just copying/pasting a "button snippet" and change its graphics and actions.
    local button =  Button.new(Bitmap.new(Texture.new("images/options_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/options_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("options", 1, conf.transition, conf.easing) 
    	end)
    menu:addChild(button)
    If you did it and you still can't see it maybe it's just outside of the screen:
    you can try changing the menu object position from this line:
    --position menu in center
    menu:setPosition((conf.width-menu:getWidth())/2, (conf.height-menu:getHeight())/2)
    or scaling the menu object (I'd say it's a temp solution to see if your code is working because this would mess up your layout..)
    --just add this line after menu:setPosition...
    menu:setScale(.5)
  • CreekmonkeyCreekmonkey Member
    edited March 2017
    @pie Ive already tried the scale and position but it didn't help. Seems no matter how many buttons I add the last added just replaces the fourth in the list. I guess I could just add another menu but that seems inefficient.
  • talistalis Guru
    edited March 2017
    weird but i was able to add 5th button without changing the code. Just copy paste one of the button code and here it is. I guess either we are misunderstanding your problem either you are terribly doing something wrong:D

    My all start.lua code:
    --[[
    *************************************************************
     * This script is developed by Arturs Sosins aka ar2rsawseen, <a href="http://appcodingeasy.com" rel="nofollow">http://appcodingeasy.com</a>
     * Feel free to distribute and modify code, but keep reference to its creator
     *
     * Gideros Game Template for developing games. Includes: 
     * Start scene, pack select, level select, settings, score system and much more
     *
     * For more information, examples and online documentation visit: 
     * <a href="http://appcodingeasy.com/Gideros-Mobile/Gideros-Mobile-Game-Template" rel="nofollow">http://appcodingeasy.com/Gideros-Mobile/Gideros-Mobile-Game-Template</a>
    **************************************************************
    ]]--
     
    local function randomize(elem)
    	elem:setPosition(math.random(-1000, 1000), math.random(-1000, 1000))
    	elem:setRotation(math.random(0, 360))
    	elem:setAlpha(math.random())
    	elem:setScale(math.random())
    end
    start = Core.class(Sprite)
     
    function start:init()
    	--here we'd probably want to set up a background picture
    	local screen = Bitmap.new(Texture.new("images/gideros_mobile.png", conf.textureFilter))
    	self:addChild(screen)
    	screen:setPosition((conf.width-screen:getWidth())/2, (conf.height-screen:getHeight())/2)
    	self:addEventListener("enterEnd", self.onEnterEnd, self)
    end
     
    function start:onEnterEnd()
    	--create menu
    	--with 20px padding between buttons
    	local menu = VerticalView.new({padding = 20, easing = conf.easing})
     
    	self:addChild(menu)
     
    	local button = Button.new(Bitmap.new(Texture.new("images/start_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/start_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("pack_select", 1, conf.transition, conf.easing) 
    	end)
    	--add menu buttons
    	menu:addChild(button)
     
    	local button =  Button.new(Bitmap.new(Texture.new("images/options_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/options_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("options", 1, conf.transition, conf.easing) 
    	end)
    	menu:addChild(button)
     
    	local button =  Button.new(Bitmap.new(Texture.new("images/help_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/help_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("help", 1, conf.transition, conf.easing) 
    	end)
    	menu:addChild(button)
     
    	local button =  Button.new(Bitmap.new(Texture.new("images/help_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/help_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("help", 1, conf.transition, conf.easing) 
    	end)
    	menu:addChild(button)
     
    	local button =  Button.new(Bitmap.new(Texture.new("images/help_up.png", conf.textureFilter)), Bitmap.new(Texture.new("images/help_down.png", conf.textureFilter)))
    	randomize(button)
    	button:addEventListener("click", function()
    		menu:reverse()
    		--go to pack select scene
    		sceneManager:changeScene("help", 1, conf.transition, conf.easing) 
    	end)
    	menu:addChild(button)
    	--position menu in center
    	menu:setPosition((conf.width-menu:getWidth())/2, (conf.height-menu:getHeight())/2)
     
    end
    ss.png
    417 x 315 - 11K
    ss.png 11.1K
  • piepie Member
    edited March 2017
    @Creekmonkey I think that there's something wrong in your code: attached you can find a "working example" made with copy/paste. I stopped at 6 buttons because others would go out of the screen (they would be there though if you plan to scroll the list later on development) :)
    [edit talis was faster!]
    rar
    rar
    GameTemplate-master-manybuttons.rar
    2M
  • @pie you added 6 buttons i was at 5 only, so you beat me for this one :D

    Likes: pie, antix

    +1 -1 (+2 / -0 )Share on Facebook
  • CreekmonkeyCreekmonkey Member
    edited March 2017
    SOLVED - It was a typo in my code but I wasn't getting errors.

    Likes: talis

    +1 -1 (+1 / -0 )Share on Facebook
  • happy that it is solved :)>-
Sign In or Register to comment.