Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • HOW TO MAKE A MAIN MENU WITH SWIPING EFFECT IN FLASH

    • 0
    • 7
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 696
    Comment on it

    whenever we started to make a game first thing we need is Main menu, its our first screen and we have to make it user friendly, so that user find very easy how to play the game. when we have more than one stage in our game we need a menu so that user can scroll and select the desired stage. so here the starling framework in flash provides the facility through which we can easily make our menu In starling ScrollContainer is a class we just have to instantiate it and the use some methods and then our menu will work like a smooth scrolled menu. the code for scrolled menu is below. (Just embed starling folder in your project)

    1- First we need a layout on which we have to show our menu icons, so we set the layout and also tell that which type of layout we needed, either horizontal or vertical. so addLayout() method will do that part. Here we have taken horizontal layout.

    private function addLayout():void
    {        
        layout = new TiledRowsLayout();
        layout.paging = TiledRowsLayout.PAGING_NONE
        layout.gap = 200; 
        layout.paddingTop = -190; 
        layout.horizontalAlign = TiledRowsLayout.HORIZONTAL_ALIGN_LEFT;
        layout.tileHorizontalAlign = TiledRowsLayout.TILE_HORIZONTAL_ALIGN_CENTER;
        layout.paging = TiledRowsLayout.PAGING_HORIZONTAL;
    }
    

    2- Now we will make a container object of scroll container class, set the properties like its width ,height and layout etc. Here pagesprite is a sprite on which we have added our menu icon simply by addchild on it. Now we have a stack here _layout-->_container-->_pagesprite-->menuIcons. basically this is a pattern for placing these items.

    3- Now the Question arises how the menu will swipe, so no worries, if you drag on the screen if will get the effect.

    public function setPages():void
    {
        _container = new ScrollContainer();
        _container.layout = layout;
        _container.scrollerProperties.snapToPages = TiledRowsLayout.PAGING_NONE;
        _container.scrollerProperties.snapScrollPositionsToPixels = true;
        this.addChild(_container);
    
        _container.width = ModelViewLocator.getInstance().deviceWidth;
        _container.height = ModelViewLocator.getInstance().deviceHeight - 100;
    
        _container.snapToPages = true;
        _container.addChild(pageSprite);
    
        _container.validate();
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: