cocos2d-js中的ccui創建的api


//ccui圖片創建
    this.img=new ccui.ImageView(res.box);
    this.addChild(this.img);
    this.img.setPosition(winSize.width/2,winSize.height/2);

    //滑動條創建
    this.slider=new ccui.Slider();
    this.addChild(this.slider);
        //背景
    this.slider.loadBarTexture(res.whitetiao);
        //滑塊
    this.slider.loadSlidBallTextures(res.black,res.black,res.black);
        //滑過后的
    this.slider.loadProgressBarTexture(res.graytiao);
    this.slider.setPosition(winSize.width/2,winSize.height/3);

    //按鈕創建
    this.btn=new ccui.Button();
    this.addChild(this.btn);
    this.btn.loadTextures(res.box,res.black,res.box);
    this.btn.setPosition(winSize.width/2,winSize.height/6);
    this.btn.setTouchEnabled(true);

    //文本的創建
    this.text=new ccui.Text("789",res.white,40,50,"0");
    this.text.setPosition(winSize.width/5,winSize.height/2);
    this.addChild(this.text);

    //復選框的創建
    this.check=new ccui.CheckBox();
    this.check.loadTextures(
        // 未選中常態紋理
        res.box,
        // 背景選中狀態紋理
        res.black,
        // 勾選選中狀態紋理
        res.black,
        // 背景禁用狀態紋理
        res.box,
        // 勾選禁用狀態紋理
        res.box
        // 紋理類型
    );
    this.check.setTouchEnabled(true);
    this.check.setPosition(winSize.width/2,winSize.height/2-100);
    this.addChild(this.check);

    //加載條的創建
    this.loading=new ccui.LoadingBar();
    this.addChild(this.loading);
    this.loading.loadTexture(res.whitetiao);
    this.loading.setDirection(ccui.LoadingBar.TypeFloat);
    this.loading.setPercent(50);
    this.loading.setPosition(winSize.width/2,winSize.height-150);

    //創建一個Layout布局
    this.layer=new ccui.Layout();
    this.layer.setContentSize(100,100);
    this.layer.x=10;
    this.layer.y=10;
    this.layer.setBackGroundColor(cc.color(128,128,128));
    this.layer.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
    this.addChild(this.layer,1);

    //滾動視圖
    this.scroll=ccui.ScrollView.create();
    this.scroll.setDirection(ccui.ScrollView.DIR_VERTICAL);//滑動條方向
    this.scroll.setTouchEnabled(true);//觸摸開啟
    this.scroll.setBounceEnabled(true);//彈性開啟
    this.scroll.setSize(cc.size(960,400));
    this.scroll.x=winSize.width/2;
    this.scroll.y=winSize.height/2;
    this.scroll.setAnchorPoint(cc.p(0.5,0.5));
    this.addChild(this.scroll,10);
    this.scroll.setInnerContainerSize(cc.size(960, 80*9));
    for(var i =0; i < 9; i++){
        var sprite = new cc.Sprite(res.box);
        this.scroll.addChild(sprite);
        sprite.x= this.scroll.width/2;
        sprite.y= this.scroll.getInnerContainerSize().height + 40 - (i+1)*80;
        sprite.setAnchorPoint(cc.p(0.5,0.5));
    }
    this.scroll.jumpToTop();
    //創建一個分頁視圖
    this.PageView=new ccui.PageView();
    this.PageView.setTouchEnabled(true);
    this.PageView.setContentSize(cc.winSize);
    this.addChild(this.PageView);
    this.PageView.x=winSize.width/2;
    this.PageView.y=winSize.height/2;

    for(var i=0;i<3;i++){
        var layout=new ccui.Layout();
        this.PageView.addPage(layout);
        var imageView=new ccui.ImageView(res.box);
        layout.addChild(imageView);
        imageView.x=this.PageView.width/2;
        imageView.y=this.PageView.height/2;
    }

    this.PageView.addEventListener(function () {
        switch (type){
            case ccui.PageView.EVENT_TURNING;
            var index=this.PageView.getCurrentPageIndex()+1;
            cc.log("當前第"+index+"頁");
            break;
            default:
                break;
        }
    });

    //列表視圖
    this.ListView=new ccui.ListView();
    this.addChild(this.ListView);
    this.ListView.setTouchEnabled(true);
    this.ListView.setContentSize(cc.size(240,120));
    this.ListView.setDirection();






    //編輯框的創建
    this.textfield=new ccui.TextField("請輸入賬號","Arial",30);
    this.addChild(this.textfield);
    this.textfield.setPosition(winSize.width/2,winSize.height-100);

    this.textfield.addEventListener(this.ontext,this);
    //可以在case:ccui.TextField.EVENT_ATTACH_WITH_IME中添加一個Action,讓textField向上moveTo
    //在case:ccui.TextField.EVENT_DETACH_WITH_IME:中添加一個moveTo回來
    //可以解決在手機上鍵盤可能遮擋住textField控件的問題
    //textField控件密碼模式:node.setPasswordEnabled(true);   //啟用密碼模式
    //node.setpasswordStyleText("*")                        //設置密碼樣式
},
ontext:function (textField,type) {
    switch(type){
        case ccui.TextField.EVENT_ATTACH_WITH_IME:
            cc.log("掛載到輸入法編輯器");
            break;
        case ccui.TextField.EVENT_DETACH_WITH_IME:
            cc.log("輸入法編輯器失去掛載");
            break;
        case ccui.TextField.EVENT_INSERT_TEXT:
            cc.log("輸入法輸入器輸入");
            break;
        case ccui.TextField.EVENT_DELETE_BACKWARD:
            cc.log("輸入法編輯器刪除");
            break;
        default:
            break;
    }
    cc.log("編輯框中內容 ",textField.getString());
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM