creator图片循环显示_Cocos creator 游戏背景循环滚动--Javascript编写
Javascript编写
cc.Class({
extends: cc.Component,
properties: {
near_bg: [cc.Node],//背景云 2幅图
far_bg: [cc.Node],//背景小山 2幅图
near_speed: 5,
far_speed: 0.5,
},
// use this for initialization
onLoad: function () {
this.fixBgPos(this.far_bg[0], this.far_bg[1]);
this.fixBgPos(this.near_bg[0], this.near_bg[1]);
},
fixBgPos: function (bg1, bg2)
{
bg1.x = 0;
var bg1BoundingBox = bg1.getBoundingBox();
// 最大 最小
bg2.setPosition(bg1BoundingBox.xMax, bg1BoundingBox.yMin);
},
// called every frame, uncomment this function to activate update callback
update: function (dt)
{
this.bgMove(this.far_bg, this.far_speed);
this.bgMove(this.near_bg, this.near_speed);
this.checkBgReset(this.far_bg);
this.checkBgReset(this.near_bg);
},
bgMove:function(bgList, speed)
{
for (var index = 0; index < bgList.length; index++)
{
var element = bgList[index];
element.x -= speed;
}
},
/***
* 检查背景是否要重置位置 两个背景图循环切换
*/
checkBgReset:function(bgList)
{
var winSize = cc.director.getWinSize();
var first_xMax = bgList[0].getBoundingBox().xMax;
if (first_xMax <= 0)
{//shift() 删除并返回数组的第一个元素
var preFirstBg = bgList.shift();
bgList.push(preFirstBg);
var curFirstBg = bgList[0];
preFirstBg.x = curFirstBg.getBoundingBox().xMax;
}
}
});
Cocos creator 游戏背景循环滚动也可以参考
https://blog.csdn.net/baidu_38630622/article/details/79074151
平台的随机产生
cc.Class({
extends: cc.Component,
properties: {
platform_list:[],
move_speed:0.1,
platform_prafab: [cc.Prefab],
platform_layer: cc.Node,
gold_group_list: [cc.Prefab],
maxMoveSpeed:8, //平台最大移动速度
},
initPlatforms: function (list) {
this.platform_list = list;
list.forEach(function(element) {
element.setAnchorPoint(0, 0);
}, this);
},
generate: function (last_platform) {
//随机N种平台
//生成随机数,范围在0到1
var random_num = Math.random() * 4;
//Math.floor() 方法可对一个数进行下舍入 例如5.6为5
random_num = Math.floor(random_num);
var platform_temp = cc.instantiate(this.platform_prafab[random_num]);
platform_temp.setAnchorPoint(0,0);
/**
*设置坐标
*/
//x
var layer_size = this.platform_layer.getContentSize();
platform_temp.x = layer_size.width;
//随机Y值(不能太高,所以-100)
platform_temp.y = Math.random() * (layer_size.height - 100);
cc.log(platform_temp.y);
//防止Y对于前面的平台过高,跳不上去
var max_offy = 100;
if (platform_temp.y > last_platform.y + max_offy) {
platform_temp.y = last_platform.y + max_offy;
}
//添加到节点
this.platform_list.push(platform_temp);
this.platform_layer.addChild(platform_temp);
//一定的几率平台添加金币
// if (Math.random() >= 0.5) {
var index = Math.random() * 3;
index = Math.floor(index);
var gold_group = cc.instantiate(this.gold_group_list[index]);
var platform_size = platform_temp.getContentSize();
gold_group.setPosition(platform_size.width / 2, platform_size.height);
platform_temp.addChild(gold_group);
// }
cc.log("产出一个平台,平台数=", this.platform_list.length);
},
// // use this for initialization
// onLoad: function () {
// this.schedule(this.onAddSpeed,10);
// },
// onAddSpeed:function(){
// this.move_speed += 0.1;
// },
// onDestroy: function onDisabled() {
// this.unschedule(this.onAddSpeed);
// },
// called every frame, uncomment this function to activate update callback
update: function (dt) {
var platform;
var remove_count = 0;
var list_new = [];
for (var index = 0; index < this.platform_list.length; index++) {
platform = this.platform_list[index];
platform.x -= this.move_speed;
if (platform.getBoundingBox().xMax > 0) {
list_new.push(platform);
}
else{
platform.removeFromParent();
}
}
this.platform_list = list_new;
if (!platform) {
return;
}
var winSize = cc.director.getWinSize();
var last_platform_bounding_box = platform.getBoundingBox();
var right_x = last_platform_bounding_box.x + last_platform_bounding_box.width;
if (right_x < winSize.width * 0.8) {
this.generate(platform) //如果最后一个已经跑到距离左边长度小于总长度的 0.8 倍,,在产生一个新的。
}
//平台移动速度变更
if (this.move_speed < this.maxMoveSpeed) {
this.move_speed += 0.001;
}
},
});
creator图片循环显示_Cocos creator 游戏背景循环滚动--Javascript编写相关推荐
- creator图片循环显示_CocosCreator背景图循环播放
以前在玩小游戏的时候发现有的小游戏背景图一直再动,视觉效果挺好,给人一种炫炫的感觉,让我这写后台的码农很是羡慕和膜拜.没想到天意弄人,我也开始写游戏前端了刚接触CocosCreator,好多东西都不懂 ...
- cocos creator 游戏源码_Cocos Creator 3D引擎源码阅读之授之以渔 源码阅读
源码阅读 动静之法 静 找到引擎源码的所在 在编辑器的右上角有一个大按钮 在VSCode里开打engine目录 引擎源码就在红色标中的cocos文件夹里,如下图 让我们来看一下引擎的目录结构 可以看到 ...
- php如何循环输出图片,[图片 显示] 缩图循环显示(php,mysql,script)-PHP教程,PHP应用
这几天被这问题折腾了一下,总算可以用了. 也同时给,辛苦工作的兄弟们一个提示吧: 1. .css 增加 .shadow{filter: dropshadow(color=#385370, offx=1 ...
- 循环显示图片、按键抽奖的小工具
一个朋友结婚,让我帮他找一个小工具,网上没有找到,很简单,就自己写了一个,有需要的朋友可以自行下载-_- 作用是这样的:结婚当天会用数码相机拍很多照片,然后在结婚仪式的最后把这些照片导入电脑,用一个小 ...
- QT中循环显示图片和简单的显示图片
请关注我的github https://github.com/linqiaozhou 以下实例代码不久后将会上传到我的github 这是我最近一个项目中的部分代码 //以下是简单的在QT中显示图片的代 ...
- wpf image控件循环显示图片 以达到动画效果 问题及解决方案
1>最初方案: 用wpf的image控件循环显示图片,达到动画效果,其实就是在后台代码动态改变Image.Source的值,关键代码: for (int i = 1; i < 601; i ...
- 【cocos creator 3.x】精灵图片不显示
精灵图片不显示 现象 原因 解决方案 现象 在cocos creator 3.2版本的使用中遇到了精灵图片无法展示的几个场景: 在prefab某个node下Sprite的图片无法显示 动态加载pref ...
- Vue v-for :src 循环显示图片
Vue v-for :src 循环显示图片 <divclass="col-xs-12 col-md-6"v-for="(row, index) in songMen ...
- vue循环渲染本地图片不显示?
teamList: [{title: '大数据拍牌',imgUrl: './img/data.jpg',introduce: '5星服务:强烈推荐',cost: '15000',bail: '3次不中 ...
最新文章
- 微软职位内部推荐-Software Engineer II-News
- mysql案例_MySQL实例crash的案例详细分析
- 如何通过redisTemplate获得key的过期时间
- php入门公开课,【PHP公开课|送你一篇有关laravel入门教程的php菜鸟笔记】- 环球网校...
- 《R语言与数据挖掘最佳实践和经典案例》—— 3.5 将图表保存到文件中
- Halcon PDF文档(hdevelop_users_guide)学习总结之四——关于3D显示模式
- 四川地震,物联网地震预警系统立功了
- 判断手机上是否安装某个APP(iOS)
- 阿里云播放器直播rtsp、rtmp、flv流,flash播放直播流
- Flash CS4 Professional 10.0.2简体中文版下载地址
- 免费服务器+免费域名 【白嫖手册】
- rpx怎么算出来的?
- ruoyi增加导入导出
- 10个Scratch热门作品(1)
- Android输入框下拉列表
- iOS处理语言工具CFStringTransform 的应用
- 如何查看SCI期刊影响因子
- Hexo+buttterfly适合任意主题美化(悬挂动态修饰物)
- 英伟达的DPU,是想在数据中心奇袭英特尔?
- 普华linux证书怎么样,来自一位普华二本学姐的亲述:“四大”真的看重证书么?...
热门文章
- java 跳表_跳表 skiplist
- jpa 原生sql 查询返回一个实体_spring data系列之jpa
- Unity动画系统详解10:子状态机是什么?
- java jws-_为JWS应用程序启动指定JRE位置
- 如何从Microsoft SQL Server生成C#类
- Ubuntu 18.04 与 20.04 LTS 性能测试
- 机器学习和ML.NET简介-第1部分
- ctypealpha php_php中Ctype函数用法详解
- 《Finite-Element Neural Networks for Solving Differential Equations》梳理
- cad批量偏移_永远都不会卸载的几款CAD插件,月入过万不要太轻松。