- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
在这篇文章中,让我们来一起用HTML5制作Flappy Bird。
Flappy Bird是一款非常优秀且容易上手的游戏,可以作为一个很好的HTML5游戏的教程。在这片教程中,我们使用Phaser框架写一个只有65行js代码的简化版Flappy Bird。
提示:你得会JavaScript
设置
先下载我为教程制作的 模板,里面包括:
phaser.min.js, 简化了的Phaser框架v1.1.5
index.html, 用来展示游戏的文件
main.js, 我们写代码的地方
asset/, 用来保存小鸟和管子的图片的文件夹(bird.png和pipe.png)
用浏览器打开index.html,用文本编辑器打开main.js
在main.js中可以看到我们之前提到的Phaser工程的基本结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Initialize Phaser, and creates a 400x490px game
var game = new Phaser.Game(400, 490, Phaser.AUTO,game_div);
?
//Creates a newmainstate that will contain the game
var main_state = {
?
????preload:function() {
????????//Function called first to load all the assets
????},
?
????create:function() {
????????//Fuction called afterpreloadto setup the game???
????},
?
????update:function() {
????????//Function called 60timesper second
????},
};
?
//Add and start themainstate to start the game
game.state.add(main, main_state);?
game.state.start(main);
接下来我们一次完成preload(),create()和update()方法,并增加一些新的方法。
小鸟的制作
我们先来看如何添加一个用空格键来控制的小鸟。
首先我们来更新preload(),create()和update()方法。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
preload:function() {?
????//Change the background color of the game
????this.game.stage.backgroundColor =#71c5cf;
?
????//Load the bird sprite
????this.game.load.image(bird,assets/bird.png);
},
?
create:function() {?
????//Display the bird on thescreen
????this.bird = this.game.add.sprite(100, 245,bird);
?
????//Add gravity to the bird tomakeit fall
????this.bird.body.gravity.y = 1000;?
?
????//Call thejumpfunctionwhen the spacekey is hit
????var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
????space_key.onDown.add(this.jump, this);????
},
?
update:function() {?
????//If the bird is out of the world (too high or too low), call therestart_gamefunction
????if(this.bird.inWorld ==false)
????????this.restart_game();
}
您可能关注的文档
最近下载
- 初中英语语法专项1000题:专题11-时态二(现在进行时)(答案解析).pdf VIP
- 外科学课件:胸部损伤-.ppt VIP
- 2021年1月自考11466现代企业人力资源管理概论试题及答案含解析.pdf VIP
- 营运桥梁变形监测报告.doc VIP
- 防水基本知识的普及雨虹.pdf VIP
- 初中英语语法专项1000题:专题10-时态一(一般现在时)(答案解析).pdf VIP
- 大疆无人机操作教程视频.pdf VIP
- 初中英语语法专项1000题:专题09-动词-专项训练(答案解析).pdf VIP
- 人教版四年级上册道德与法治培优辅差计划.docx VIP
- 东方雨虹聚羧酸减水剂应用.ppt VIP
文档评论(0)