弹幕示例:Galgame

出自嗶哩嗶哩百科
跳转到: 导航, 搜索
本示例提供制作Galgame的基础函数

目录

建立对话窗口

参数

owner:String ─ Galgame中对话窗口角色
txt:String ─ Galgame中对话窗口信息
onfinish:Function ─ 提示完成时的回调函数

函数定义

 function createGalbox(owner,txt,onfinish,createArrowNow)
 {
 	var ownfsize = 14;  /** 设置对话人文字大小 **/
 	var cboxWidth = Player.width-20; var cboxHeight = 80+ownfsize+4;
 	
 	$G._set("_gal_cboxWidth",cboxWidth);
 	$G._set("_gal_cboxHeight",cboxHeight);
 	
 	var cbox = $.createCanvas({lifeTime:0,x:10,y:Player.height-85-ownfsize-4});
 	$G._set("_gal_cbox",cbox);
 	var box = $.createShape({lifeTime:0,x:0,y:0,alpha:0.4,parent:cbox});
 	box.graphics.beginFill(0x008aff); /** 设置背景色彩 **/
 	box.graphics.lineStyle(2, 0x00649e, 1, false, "vertical","none", "miter", 10);  /** 设置对话人线条色彩 **/
 	box.graphics.drawRoundRect(-2,-8,owner.length*ownfsize*1.5+4,ownfsize+8,20);
 	box.graphics.lineStyle(5, 0x00649e, 1, false, "vertical","none", "miter", 10);  /** 设置对话信息背景色彩 **/
 	box.graphics.drawRect(0,ownfsize+4,cboxWidth,80);
 	box.graphics.endFill();
 	
 	var bown = $.createComment(owner,{x:10,y:-7,fontsize:ownfsize,lifeTime:0,parent:cbox,color:0x0036ff});
 	bown.bold = false; bown.filters=null;
 	
 	vx=txt.substr(0,1);
 	oTxt=$.createComment(vx,{x:10,y:ownfsize+10+4,fontsize:20,lifeTime:0,parent:cbox});
 	$G._set("_gal_galTextObj",oTxt);
 	galTextTmr = $G._("_gal_galText");
 	if (galTextTmr!=undefined)
 	{
 		galTextTmr.stop();
 	}
 	var galTextTmr = interval(function(){ oTxt.text+=txt.substr(oTxt.length,1); 
 		if (oTxt.length==txt.length)
 		{
 			if (onfinish!=undefined) onfinish();
 			if (createArrowNow == undefined || createArrowNow) timer(createGalArrow,300);
 		}
 	}, 50, txt.length-1);
 	$G._set("_gal_galText",galTextTmr);
 }
 function createGalArrow(){
 	var yArrow = $.createShape({lifeTime:0,x:$G._("_gal_cboxWidth")-20,y:$G._("_gal_cboxHeight")-20,parent:$G._("_gal_cbox")});
 	yArrow.graphics.lineStyle(1, 0xff900c, 1, false, "vertical","none", "miter", 10);
 	yArrow.graphics.beginFill(0xffffff);
 	yArrow.graphics.moveTo(0,10);
 	yArrow.graphics.lineTo(-5,0);
 	yArrow.graphics.lineTo(5,0);
 	yArrow.graphics.lineTo(0,10);
 	yArrow.graphics.endFill();
 	$G._set("_gal_yArrow",yArrow);
 
 	if ($G._("_gal_yArrowTimer")!=undefined){
 		yArrowTimer = $G._("_gal_yArrowTimer");
 		yArrowTimer.stop();
 	}
 	var yArrowTimer = interval(function(){ var ya=$G._("_gal_yArrow"); ya.rotationY+=10;},100,0);
 	$G._set("_gal_yArrowTimer",yArrowTimer);
 }

对话窗口信息添加

参数

txt:String ─ Galgame中对话窗口中添加的信息

函数定义

 function appendGalText(txt,onFinish)
 {
 	var oTxt = $G._("_gal_galTextObj");
 	if (galTextTmr!=undefined)
 	{
 		galTextTmr.stop();
 	}
 	s=oTxt.length;
 	var galTextTmr = interval(function(){ oTxt.text+=txt.substr(oTxt.length-s,1); if (onFinish!=undefined && oTxt.length-s == txt.length) onFinish(); }, 50, txt.length);
 	$G._set("_gal_galText",galTextTmr);
 }

按钮信息添加

参数

x:Number ─ 按钮X位置
y:Number ─ 按钮y起始位置
btn:Array ─ 按钮设置
step:Number ─ 按钮垂直间隔 (默认50)

函数定义

 function createGalButton(x,y,btn,step)
 {
 	var galButtons = [];
 	if (step==undefined) step=50;
 	for (var i=0;i<btn.length;i++)
 	{
 		var motion = undefined;
 		var width = 250;
 		if (btn[i].width != undefined) width = btn[i].width;
 		var bx = x;
 		if ($G._("_gal_set_animation"))
 		{
 			bx = (i%2==0 ? 0-width : Player.width+width);
 			motion = {x:{fromValue:bx, toValue:x, lifeTime: 0.5}};
 		}
 		var b=$.createButton({text:btn[i].text,x:bx,y:y+i*step,lifeTime:0,width:width,onclick:btn[i].onclick,motion:motion});
 		if (btn[i].fillColors != undefined) b.setStyle("fillColors",btn[i].fillColors);
 		if (btn[i].fillAlphas != undefined) b.setStyle("fillAlphas",btn[i].fillAlphas);
 		galButtons.push(b);
 	}
 	$G._set("_gal_galButtons",galButtons);
 }

移除对话窗口

函数定义

 function removeGalBox()
 {
 	var cbox = $G._("_gal_cbox");
 	var yArrow = $G._("_gal_yArrow");
 	var yArrowTimer = $G._("_gal_yArrowTimer");
 	var galButtons = $G._("_gal_galButtons");
 	if (yArrow!=undefined) yArrow.remove();
 	if (yArrow!=yArrowTimer) yArrowTimer.stop();
 	$G._set("_gal_yArrowTimer",undefined);
 	if (cbox!=yArrowTimer) cbox.remove();
 	if (galButtons==undefined) return;
 	for (;galButtons.length>0;)
 	{
 		var b=galButtons.pop();
 		b.remove();
 	}
 }

使用示例

 $G._set("_gal_set_animation",true);
 var galbg=$.createCanvas({x:-1,y:-1,width:Player.width,height:Player.height,lifeTime:0});
 var bg_=$.createShape({x:0,y:0,lifeTime:0,parent:bg});
 bg_.graphics.beginFill(0xffffff);
 bg_.graphics.drawRect(0,0,Player.width,Player.height);
 bg_.graphics.endFill();
 
 createGalbox("哔哩哔哩","欢迎来到高级弹幕测试视频...",function(){
 	appendGalText("\n请请在上方选择您要观看的项目...",function(){timer(createGalArrow,300);});
 	createGalButton(150,20,[
 	{text:"基础代码演示",onclick:function(){Player.jump("av120040",2);}},
 	{text:"Idol Master",fillColors:[0xffffff,0xff900c],onclick:function(){Player.jump("av120040",3);}},
 	{text:"魔法少女小圆OP",fillColors:[0xffffff,0xff7777],onclick:function(){Player.jump("av120040",4);}},
 	{text:"キミとふたり",fillColors:[0xffffff,0x00991d],onclick:function(){Player.jump("av120040",5);}},
 	{text:"いとうかなこ - Hacking to the Gate",fillColors:[0xffffff,0x6d2400],onclick:function(){Player.jump("av120040",6);}},
 	{text:"什么都不做",onclick:function(){Player.seek(190500);}}
 	],45);
 },false);
 function timerEvent()
 {
 	if (Player.time > 190500 && $G._("galBadend")==undefined)
 	{
 		$G._set("galBadend",1);
 		removeGalBox();
 		ScriptManager.clearEl();
 		var galbg=$.createCanvas({x:-1,y:-1,width:Player.width,height:Player.height,lifeTime:0});
 		var bg_=$.createShape({x:0,y:0,lifeTime:0,parent:bg});
 		bg_.graphics.beginFill(0x00);
 		bg_.graphics.drawRect(0,0,Player.width,Player.height);
 		bg_.graphics.endFill();
 		var y=0;
 			for (var i=0;i<3;i++){
 				var a=$.createComment("Bad End",{fontsize:72,x:130,y:100+y--*3,lifeTime:6,color:0xff0000,alpha:0,motion:
 				{
 					alpha:{fromValue:0,toValue:1,lifeTime:1}
 				}
 				});
 			};
 		createGalbox("哔哩哔哩","请重新来过...");
 	}else if (Player.time < 190500)
 	{
 		$G._set("galBadend",undefined);
 	}
 }
 interval(timerEvent,500,0);
个人工具
名字空间
变换
动作
导航
更新
工具箱