标签:io os ar 使用 java for sp 文件 on
游戏中很多需要用到ScrollView的情况,也就是需要滚动一片区域。这里有两种实现方法,一种是使用cocos studio的方式,第二种是手写代码。先看第一种
第一种记得在设置滚动区域时选取裁剪项。
var size = cc.winSize; //读取json文件 var root = ccs.uiReader.widgetFromJsonFile(res.listJson); this.addChild(root); //获取在cocos studio里面设定好的scrollView var missionlist = ccui.helper.seekWidgetByName(root, "MissionList"); //设定垂直朝向滚动 missionlist.setDirection(ccui.ScrollView.DIR_VERTICAL); missionlist.setTouchEnabled(true); missionlist.setBounceEnabled(true); missionlist.setVisible(true); //设置大小 missionlist.setSize(cc.size(960, 400)); //设置可以滚动区域 var len = 9; missionlist.setInnerContainerSize(cc.size(960, 80* len)); missionlist.y = size.height/2; missionlist.x = size.width/2; missionlist.setAnchorPoint(cc.p(0.5,0.5)); //设置滚动的项目 for(var i = 0; i < len; i++){ var sprite = new cc.Sprite(res.item_png); missionlist.addChild(sprite); sprite.x = missionlist.width/2; sprite.y = missionlist.getInnerContainerSize().height + 40 - (i+1)*80; sprite.setAnchorPoint(cc.p(0.5,0.5)); } missionlist.jumpToTop();
</pre><pre name="code" class="javascript">第二种,手写代码
<p><pre name="code" class="javascript"> varlistView = ccui.ScrollView.create(); listView.setDirection(ccui.ScrollView.DIR_VERTICAL); listView.setTouchEnabled(true); listView.setBounceEnabled(true); listView.setSize(cc.size(960, 400)); listView.x = size.width/2; listView.y = size.height/2; listView.setAnchorPoint(cc.p(0.5,0.5)); this.addChild(listView); listView.setInnerContainerSize(cc.size(960, 80*9)); for(var i =0; i < 9; i++){ varsprite = new cc.Sprite(res.item_png); listView.addChild(sprite); sprite.x= listView.width/2; sprite.y= listView.getInnerContainerSize().height + 40 - (i+1)*80; sprite.setAnchorPoint(cc.p(0.5,0.5)); } listView.jumpToTop();
标签:io os ar 使用 java for sp 文件 on
原文地址:http://blog.csdn.net/dayday_up2/article/details/40617915