Cocos2d-js02_实现UI流程和场景跳转
/** * Created by chaoge on 15/6/19. */ @H_403_9@var MenuLayer = @H_403_9@cc.@H_403_9@Layer.@H_403_9@extend({ @H_403_9@sprite:@H_403_9@null,@H_403_9@helloLabel:@H_403_9@null,@H_403_9@size:@H_403_9@null,ctor:@H_403_9@function () { @H_403_9@this.@H_403_9@_super(); @H_403_9@size = @H_403_9@cc.winSize; //开始按钮 @H_403_9@var start = @H_403_9@new cc.@H_403_9@MenuItemImage( @H_403_9@res.@H_403_9@start,@H_403_9@res.@H_403_9@start,@H_403_9@function () { @H_403_9@cc.log(@H_403_9@"Menu is clicked!"); @H_403_9@cc.director.runScene(@H_403_9@new GameScene()); },@H_403_9@this); start.attr({ @H_403_9@x: @H_403_9@size.@H_403_9@width/2,@H_403_9@y: @H_403_9@size.@H_403_9@height/2-120,@H_403_9@anchorX: 0.5,@H_403_9@anchorY: 0.5 }); //关于按钮 @H_403_9@var about = @H_403_9@new cc.@H_403_9@MenuItemImage( @H_403_9@res.@H_403_9@about,@H_403_9@res.@H_403_9@about,@H_403_9@function () { @H_403_9@cc.log(@H_403_9@"Menu is clicked!"); @H_403_9@cc.director.runScene(@H_403_9@new AboutGame()); },@H_403_9@this); about.attr({ @H_403_9@x: @H_403_9@size.@H_403_9@width/2,@H_403_9@y: @H_403_9@size.@H_403_9@height/2-280,@H_403_9@anchorY: 0.5 }); @H_403_9@var menu = @H_403_9@new cc.@H_403_9@Menu(start,about); menu.@H_403_9@x = 0; menu.@H_403_9@y = 0; @H_403_9@this.addChild(menu,1); //滚动菜单 @H_403_9@helloLabel = @H_403_9@new cc.@H_403_9@LabelTTF(@H_403_9@"看谁最长",@H_403_9@"Arial",38); // position the label on the center of the screen @H_403_9@helloLabel.@H_403_9@x = @H_403_9@size.@H_403_9@width / 2; @H_403_9@helloLabel.@H_403_9@y = @H_403_9@size.@H_403_9@height-100; // add the label as a child to this layer @H_403_9@this.addChild(@H_403_9@helloLabel,5); // add "HelloWorld" splash screen" @H_403_9@this.@H_403_9@sprite = @H_403_9@new cc.@H_403_9@Sprite(@H_403_9@res.@H_403_9@zhuye); @H_403_9@this.@H_403_9@sprite.attr({ @H_403_9@x: @H_403_9@size.@H_403_9@width / 2,@H_403_9@y: @H_403_9@size.@H_403_9@height / 2 }); @H_403_9@this.addChild(@H_403_9@this.@H_403_9@sprite,0); @H_403_9@this.schedule(@H_403_9@this.LabelMove,0.2); },LabelMove : @H_403_9@function(){ @H_403_9@helloLabel.setPositionX(@H_403_9@helloLabel.getPositionX()-10); @H_403_9@if(@H_403_9@helloLabel.getPositionX() <= -50){ @H_403_9@helloLabel.setPositionX(@H_403_9@size.@H_403_9@width); } } }); @H_403_9@var MenuGame = @H_403_9@cc.@H_403_9@Scene.@H_403_9@extend({ onEnter:@H_403_9@function () { @H_403_9@this.@H_403_9@_super(); @H_403_9@var layer = @H_403_9@new MenuLayer(); @H_403_9@this.addChild(layer); } });
}
2、关于界面的代码,实现网页链接AboutScene.js:
@H_403_9@var labjiumiao = @H_403_9@new cc.@H_403_9@LabelTTF(@H_403_9@"9秒课堂", 38);
@H_403_9@var ketang = @H_403_9@new cc.@H_403_9@MenuItemLabel(labjiumiao,@H_403_9@function(){
@H_403_9@window.@H_403_9@location.@H_403_9@href = @H_403_9@"http://www.9miaoketang.com";
});
ketang.setPosition(@H_403_9@cc.p(@H_403_9@size.@H_403_9@width/2,@H_403_9@size.@H_403_9@height-200));
@H_403_9@var h5kaifa = @H_403_9@new cc.@H_403_9@LabelTTF(@H_403_9@"COCOS2D-HTML5 游戏开发", 38);
@H_403_9@var H5 = @H_403_9@new cc.@H_403_9@MenuItemLabel(h5kaifa,@H_403_9@function(){
@H_403_9@window.@H_403_9@location.@H_403_9@href = @H_403_9@"http://h5.9miao.com";
});
H5.setPosition(@H_403_9@cc.p(@H_403_9@size.@H_403_9@width/2,@H_403_9@size.@H_403_9@height/2));
@H_403_9@var menu = @H_403_9@new cc.@H_403_9@Menu(ketang,H5);
menu.@H_403_9@x = 0;
menu.@H_403_9@y = 0;
@H_403_9@this.addChild(menu,1);
视频地址:http://www.9miaoketang.com/course/37
课程讨论帖地址:http://www.9miao.com/thread-64587-1-1.html
源码地址:https://store.cocos.com/stuff/show/128289.html
QQ交流群:83459374
后期也会把该源码传在群里面去,欢迎大家加入讨论!