日历翻页动态效果

 

AnimationAltas.as
package game.calendar.widget
{

import laya.display.Animation;
	import laya.display.Stage;
	import laya.maths.Rectangle;
	import laya.net.Loader;
	import laya.utils.Browser;
	import laya.utils.Handler;
	import laya.webgl.WebGL;
	import game.constant.MyConstant;
	import laya.events.Event;
	import game.logger.LogUtil;
	import game.calendar.widget.McB;
	import laya.ui.Box;
	import laya.ui.Button;
	import game.calendar.NumTool;
	import laya.media.SoundManager;

	public class AnimationAltas {
		private var year:Number = NumTool.year;
		private var ani:Animation;
		private const AniConfPath:String = MyConstant.getAssetsRoot() + "res/atlas/game2204ani.atlas";
		// 文本框,月份和日期
		private var sp_b:McB;

		// 起始位置月份和日期
		private var beginMonth:Number = 1;
		private var beginDate:Number = 1;
		// 终止时间,月份和日期
		private var endMonth:Number = 1;
		private var endDate:Number = 1;

		// 翻转的日期值
		private var currenMonth:Number = 1;
		private var currenDate:Number = 1;
		
		// 开始时间
		private var date:Date;
		
		public var box_a:Box;//翻转结束显示box_a
		public var box_donext:Box;//正在翻转日历,显示继续经营页面,box_donext

		public function AnimationAltas() {
			// 不支持WebGL时自动切换至Canvas
			Laya.init(Browser.clientWidth, Browser.clientHeight, WebGL);

			Laya.stage.alignV = Stage.ALIGN_MIDDLE;
			Laya.stage.alignH = Stage.ALIGN_CENTER;

			Laya.stage.scaleMode = "showall";
			Laya.stage.bgColor = "#232628";

			Laya.loader.load(AniConfPath, Handler.create(this, createAnimation), null, Loader.ATLAS);
		}


		/**
		 * 播放动画
		 */
		public function playFlip(box_a:Box,box_donext:Box,oM:Number, oD:Number,m:Number, d:Number):void {
			this.box_a = box_a;			
			this.box_donext = box_donext;			
			this.beginMonth = oM;
			this.beginDate = oD;
			this.endMonth = m;
			this.endDate = d;

			// 格式化当前时间(0-11 代表1到12月)
			date = new Date(year, beginMonth - 1, beginDate);

			sp_b.label1.text = "" + beginDate;
			sp_b.label2.text = beginMonth + "月";

			currenMonth = beginMonth;
			currenDate = beginDate;

			if(endMonth == 1 && endDate == 1){
				hiddenCalendar();
			}else{
				showCalendar();
				ani.play();
			}
		}

		public function hiddenCalendar():void {
			ani.visible = false;
			this.box_a.visible = true;
			this.box_donext.visible = false;
			sp_b.visible = false;
			// SoundManager.destroySound(MyConstant.SOUNDS_CALENDER);
		}
		public function showCalendar():void {
			ani.visible = true;
			this.box_a.visible = false;
			this.box_donext.visible = true;
			sp_b.visible = true;
		}

		// 隐藏日历动画
		public function hiddenAni():void {
			ani.visible = false;
			sp_b.visible = false;
		}
		
		private function createAnimation(_e:*=null):void {
			ani = new Animation();
			ani.loadAtlas(AniConfPath);			// 加载图集动画
			ani.interval = 8;					// 设置播放间隔(单位:毫秒)
			ani.index = 0;						// 当前播放索引
			// ani.play();						// 播放图集动画
			
			// 获取动画的边界信息
			var bounds:Rectangle = ani.getGraphicBounds();
			ani.pivot(bounds.width / 2, bounds.height / 2);
			
			ani.pos(286, 340);
			Laya.stage.addChild(ani);
			// 显示月份和天数
			sp_b = new McB();
			sp_b.label2.text = beginMonth + "月";
			sp_b.label1.text = "" + beginDate;
			Laya.stage.addChild(sp_b);
			setListener();
		}

		public function setListener():void{
			// 	动画播放完毕后调度。
			ani.on(Event.COMPLETE, this, function (e:Event):void {
				
				//时间增加天数操作
				operationDate();

				// 翻一页一次声音
				SoundManager.playSound(MyConstant.SOUNDS_CALENDER);
				
				if(currenMonth == endMonth && currenDate == endDate){
					ani.stop();
					Laya.timer.once(380,this,hiddenCalendar);
				}
			}
		}
		// 时间格式化操作等
		private function operationDate():void{
			// 增加一天
			var time:int = date.getTime() + 1*24*3600*1000;
			//格式化
			var mDate:Date = new Date(time);
			date = mDate;
			currenMonth = mDate.getMonth() + 1;
			currenDate = mDate.getDate();
			sp_b.label2.text = currenMonth + "月";
			sp_b.label1.text = currenDate + "";
		}
 
		
	}
}




McB.as
package game.calendar.widget
{
	import laya.display.Sprite;
	import laya.ui.Label;
	import laya.ui.Clip;
	import game.constant.MyConstant;
	import laya.ui.Image;

	/**
	 * 日历的月份日期
	 * @author
	 */
	public class McB extends Sprite{
		public var label1:Label;//日期
		public var label2:Label; //月份

		public function McB(){
			// Sprite宽高默认为0,并且不会随着绘制内容的变化而变化,如果想根据绘制内容获取宽高,可以设置本属性为true
			this.autoSize = true;

			label2 = new Label();
			// label2.font = "Microsoft YaHei";
			label2.bold = true;
			label2.fontSize = 28;
			label2.color="#000000";
			label2.align = "center";
			label2.valign = "middle";
			label2.wordWrap = false;
			label2.mouseEnabled = false;
			label2.overflow = "hidden";
			label2.rotation = -25;
			label2.x = 266;
			label2.y = 370;
			label2.width = 80;
			label2.height = 50;
			this.addChild(label2);

			label1 = new Label();
			label1.bold = true;
			label1.fontSize = 60;
			label1.color="#ff6060";
			label1.align = "center";
			label1.valign = "middle";
			label1.wordWrap = false;
			label1.mouseEnabled = false;
			label1.overflow = "hidden";
			label1.rotation = -25;
			label1.x = 292;
			label1.y = 416;
			label1.width = 80;
			label1.height = 50;
			this.addChild(label1);

		}
	}

}

资源请私信;

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码~小~哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值