Please Help Thank You!

I have an app where I have 4 icons on the botton of the screen and you press them. How would i make it so I can place more icons that are off the screen and you can swipe the icons and other icons will appear like a side scrolling thing. 

I would probably create a display.newGroup() that is wider than the screen, place my icons in it, and then move the group left/right when swiping.

How would I do that? I’m pretty new to corona Thank you :slight_smile:

Check out the following pages:

https://docs.coronalabs.com/api/library/display/newGroup.html

https://docs.coronalabs.com/api/event/touch/index.html

Something like this…it’s a bit of pseudo-code and not tested, but this should get you started.

local function onMenuBarTouch(event) local phase = event.phase local prevX if event.phase == "began" then display.getCurrentStage():setFocus( self ) self.isFocus = true prevX = event.x elseif event.phase == "moved" then if event.x \> prevX then local direction = 1 else direction = -1 end menuBar.x = menuBar.x + direction prevX = event.x elseif event.phase == "ended" then display.getCurrentStage():setFocus( nil ) self.isFocus = nil end return true end local menuBar = display.newGroup() menuBar:addEventListener("touch", onMenuBarTouch) -- build your menu bar by: -- adding your icons here. -- place tap event listeners on the icons

This should move the menu bar left/right on the x axis. The only problem I could see is if the user touches the menu bar where there is an icon, the icon listener will probably fire first.

You might want a scroll section, or figure out a way to enable/disable icon listeners so they do not interfere with menu bar moves.

Hope this helps,

–john

Thank you so much!!

I would probably create a display.newGroup() that is wider than the screen, place my icons in it, and then move the group left/right when swiping.

How would I do that? I’m pretty new to corona Thank you :slight_smile:

Check out the following pages:

https://docs.coronalabs.com/api/library/display/newGroup.html

https://docs.coronalabs.com/api/event/touch/index.html

Something like this…it’s a bit of pseudo-code and not tested, but this should get you started.

local function onMenuBarTouch(event) local phase = event.phase local prevX if event.phase == "began" then display.getCurrentStage():setFocus( self ) self.isFocus = true prevX = event.x elseif event.phase == "moved" then if event.x \> prevX then local direction = 1 else direction = -1 end menuBar.x = menuBar.x + direction prevX = event.x elseif event.phase == "ended" then display.getCurrentStage():setFocus( nil ) self.isFocus = nil end return true end local menuBar = display.newGroup() menuBar:addEventListener("touch", onMenuBarTouch) -- build your menu bar by: -- adding your icons here. -- place tap event listeners on the icons

This should move the menu bar left/right on the x axis. The only problem I could see is if the user touches the menu bar where there is an icon, the icon listener will probably fire first.

You might want a scroll section, or figure out a way to enable/disable icon listeners so they do not interfere with menu bar moves.

Hope this helps,

–john

Thank you so much!!