Phaser3让超级玛丽实现轻跳、高跳及加上对应的跳跃声音

mario jumper
mario jumper

在线测试地址:http://www.ifiero.com/uploads/phaserjs3/jumper/

空格键:轻按:跳低 ,长按:跳高
键盘:--> 向右 , <-- 向左

请确保已打开电脑的音乐开关

var config = {type: Phaser.AUTO,width: 650,height: 450, parent: "ifierocom", physics: { default: 'arcade', arcade: { gravity: { y: 350 }, debug: false } }, scene: { preload: preload, create: create, update: update } }; var player; var stars; var bombs; var platforms; var cursors; var score = 0; var gameOver = false; var scoreText; // var jumpTimer = 0; var game = new Phaser.Game(config); var isSmall = true; // small jump music var isSuper = true; // super jump music function init() { this.jumpTimer = 0; this.isCanJump = false; this.isCanLeft = false; this.isCanRight = false; this.isCanStand = true; this.velocityL = 0; this.velocityR = 0; } function preload() { this.load.image('sky', 'assets/sky.png'); this.load.image('ground', 'assets/platform.png'); this.load.image('star', 'assets/star.png'); this.load.image('bomb', 'assets/bomb.png'); // this.load.spritesheet('dude', 'assets/dude.png', { // frameWidth: 32, // frameHeight: 48 // }); this.load.spritesheet('mario', 'assets/mario_mario.png', { frameWidth: 16, frameHeight: 16, margin: 1, spacing: 1 }); //music: small this.load.audio('jumpSmall', 'assets/audio/JumpSmall.mp3'); //music: super this.load.audio('jumpSuper', 'assets/audio/JumpSuper.mp3'); //music: super this.load.audio('coin', 'assets/audio/Coin.mp3'); } function create() { this.spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); // A simple background for our game this.add.image(400, 300, 'sky'); // The platforms group contains the ground and the 2 ledges we can jump on platforms = this.physics.add.staticGroup(); // Here we create the ground. // Scale it to fit the width of the game (the original sprite is 400x32 in size) platforms.create(400, 568, 'ground').setScale(2).refreshBody(); // Now let's create some ledges platforms.create(600, 400, 'ground'); platforms.create(50, 250, 'ground'); platforms.create(750, 220, 'ground'); // The player and its settings // player = this.physics.add.sprite(100, 450, 'dude'); player = this.physics.add.sprite(100, 450, 'mario', 0); player.setScale(2.5); // Player physics properties. Give the little guy a slight bounce. player.setBounce(0.2); player.setCollideWorldBounds(true); // Our player animations, turning, walking left and walking right. this.anims.create({ key: 'run', frames: this.anims.generateFrameNumbers('mario', { start: 1, end: 3 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'shift', frames: [{ key: 'mario', frame: 4 }], frameRate: 20 }); this.anims.create({ key: 'stand', frames: [{ key: 'mario', frame: 0 }], frameRate: 20 }); this.anims.create({ key: 'jump', frames: [{ key: 'mario', frame: 5 }], frameRate: 20 }); // Input Events cursors = this.input.keyboard.createCursorKeys(); // Some stars to collect, 12 in total, evenly spaced 70 pixels apart along the x axis stars = this.physics.add.group({ key: 'star', repeat: 11, setXY: { x: 12, y: 0, stepX: 70 } }); stars.children.iterate(function (child) { // Give each star a slightly different bounce child.setBounceY(Phaser.Math.FloatBetween(0.4, 0.8)); }); bombs = this.physics.add.group(); // The score scoreText = this.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#000' }); scoreText.setScrollFactor(0); // Collide the player and the stars with the platforms this.physics.add.collider(player, platforms, function () { // console.log('hit ground'); // console.groupEnd(); this.isCanJump = false; }, null, this); this.physics.add.collider(stars, platforms); this.physics.add.collider(bombs, platforms); // Checks to see if the player overlaps with any of the stars, if he does call the collectStar function this.physics.add.overlap(player, stars, collectStar, null, this); this.physics.add.collider(player, bombs, hitBomb, null, this); this.cameras.main.setBounds(0, 0, 800, 600); 

转载于:https://www.cnblogs.com/apiapia/p/10057239.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/570095.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux下文件删除不了

在linux系统下当删除文件时提示无法操作&#xff0c;有可能是文件被使用了chattr改变了属性。可以使用lsattr命令来查看 [rootlinux236 root]# lsattr   ---i---------- ./1.txt   -------------- ./weiqi.ldif -------------- ./qi.schema 以上可以看出1.txt文件被添加了…

struts2配置问题

struts2.2.1之后的版本除了commons-fileupload-1.3、commons-io-2.2、freemarker-2.3.19、javassist-3.11.0.GA、ognl-3.0.6、struts2-core-2.3.16、xwork-core-2.3.16之外&#xff0c;还需要commons-lang3-3.1才能正常运行

linux IptabLex 攻击

以下摘自某位老兄的文章&#xff0c;遇到问题一样&#xff0c;不知道是否是新出的病毒IptabLex大家都知道&#xff0c;互联网每时每刻都会存在攻击的可能性&#xff0c;&#xff08;系统频繁发包&#xff0c;SYN攻击&#xff0c;等等&#xff09;安全问题是系统管理员不可忽视的…

MySQL各个版本区别

MySQL 的官网下载地址&#xff1a;http://www.mysql.com/downloads/在这个下载界面会有几个版本的选择:1. MySQL Community Server 社区版本&#xff0c;开源免费&#xff0c;但不提供官方技术支持。2. MySQL Enterprise Edition 企业版本&#xff0c;需付费&#xff0c;可以试…

GIT和GitHub的使用总结

目录 一、GIT初始化设置&#xff1a;创建密钥添加远程仓库用户名邮箱配置Clone远程仓库创建本地仓库代理设置自定义操作二、GIT基本操作添加到暂存区区提交删除版本回退撤销修改三、GIT分支操作创建分支分支合并分支推送分支绑定分支删除stash功能四、GIT标签操作本地操作远程操…

分析MySQL数据类型的长度

分析MySQL数据类型的长度 MySQL有几种数据类型可以限制类型的"长度"&#xff0c;有CHAR(Length)、VARCHAR(Length)、TINYINT(Length)、SMALLINT(Length)、MEDIUMINT(Length)、INT(Length)、BIGINT(Length)、FLOAT(Length, Decimals)、DOUBLE(Length, Decimals)和DECI…

Mysql partition by

一&#xff0c;看原表 select * from user; 二&#xff0c;查询同组年级最大的 select username ,SUBSTRING_INDEX( GROUP_CONCAT(age order by age desc) ,,,1) uuid from ( select uuid ,username ,password ,age from user )b GROUP BY uuid asc; 转载于:https://www.cn…

tomcat内存溢出,修改设置

问题描述&#xff1a; 1. java.lang.OutOfMemoryError: Java heap space JVM堆的设置是指java程序运行过程中JVM可以调配使用的内存空间的设置.JVM在启动的时候会自动设置Heap size的值&#xff0c;其初始空间(即-Xms)是物理内存的1/64&#xff0c;最大空间(-Xmx)是物理内存的…

Mysql导入大容量SQL文件数据问题

mysql在通过导入sql文件可能会出现下面二个问题:1.如果sql文件过大,会出现"MySQL server has gone away"问题;2.如果sql文件数据有中文,会出现乱码 解决问题:问题1:出现MySQL server has gone away"问题,是因为mysql默认的"max_allowed_packet"变量…

电脑的引导启动快捷键

组装机主板品牌笔记本品牌台式机主板品牌启动按键笔记本品牌启动按键台式机品牌启动按键华硕主板F8联想笔记本F12联想台式机F12技嘉主板F12宏基笔记本F12惠普台式机F12微星主板F11华硕笔记本ESC宏基台式机F12映泰主板F9惠普笔记本F9戴尔台式机ESC梅捷主板ESC或F12联想ThinkpadF…

swift 4.2 - 根据字符串 push指定控制器

俩个方法 1. 创建类写成 类方法 import UIKit /** 注释&#xff1a;获得VC* 1.字符串 和使用的控制器&#xff0c;直接跳转* 2.用过字符串获得对应VC*/ class JYGetPushVc: NSObject {/// 指定字符串VC跳转,设置titlestatic func pushVcByVcNameAndTitle(pushVcNameStr:String…

linux下IPTABLES配置详解

如果你的IPTABLES基础知识还不了解,建议先去看看.开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况[roottp ~]# iptables -L -nChain INPUT (policy ACCEPT)target prot opt source destination Chain FORWARD (polic…

centos通过添加chrome源来安装chrome

在google网站下载chrome速度很慢&#xff0c;但是添加了chrome的源之后&#xff0c;就可以在终端通过yum install 来安装chrome了&#xff0c;会快很多。 首先在/etc/yum.repos.d里建立一个名为google.repo文件&#xff0c;然后复制以下代码到其中&#xff0c;然后保存&#xf…

鼠标滑过抖动图标

在线演示 本地下载 转载于:https://www.cnblogs.com/qixidi/p/10079608.html

centos7安装VLC播放器

1.安装eple 下载地址&#xff1a;https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm 2.安装nux-dextop下载地址&#xff1a;http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm3.执行yum update 4.…

每日站立会议 12.06

每日站立会议 今天我们开始了对button按钮中素菜部分代码的编写&#xff0c;我负责编写时代码的复审。转载于:https://www.cnblogs.com/grrd17s/p/10079973.html

CentOS安装五笔输入法

安装五笔需要安装一个 ibus-table-wubi 包 yum install ibus libusb ibus-libs ibus-table-wubi 安装好后注销一下系统&#xff0c;让ibus读取新的配置&#xff0c;然后就可以在ibus的设置界面添加wubi了 右击桌面右上角的输入法图标&#xff0c;选择 Preferences&#xff0c;…

Spring的两种代理方式:JDK动态代理和CGLIB动态代理

代理模式 代理模式的英文叫做Proxy或Surrogate&#xff0c;中文都可译为”代理“&#xff0c;所谓代理&#xff0c;就是一个人或者一个机构代表另一个人或者另一个机构采取行动。在一些情况下&#xff0c;一个客户不想或者不能够直接引用一个对象&#xff0c;而代理对象可以在客…

virtualbox 启动时报Kernel driver not installed (rc=-1908) 的错误

新建虚拟机后启动时出现如下错误&#xff1a;Kernel driver not installed (rc-1908)The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or there is a permission problem with /dev/vboxdrv. Re-setup the kernel module by executing/etc/init.d/vboxdrv …

拒绝推断问题(转)

拒绝推断&#xff08;Reject Inference&#xff09;是金融领域信用评分中的一个术语。对于要向银行借钱的人&#xff0c;我们需要考虑他们赖账的可能性。这样就需要根据他们的各种行为信息和人口统计学特征作为输入&#xff0c;来建立一个信用评分模型&#xff0c;这个建模过程…