phaser实现一个跳跃类小游戏代码
代码语言:html
所属分类:游戏
代码描述:phaser实现一个跳跃类小游戏代码,按住键盘上下左右键控制跳跃及方向。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/phaser.2.0.5.js"></script> <script> var Jumper = function() {}; Jumper.Play = function() {}; Jumper.Play.prototype = { preload: function() { this.load.image( 'hero', '//repo.bfw.wiki/bfwrepo/images/phaser/dude.png' ); this.load.image( 'pixel', '//repo.bfw.wiki/bfwrepo/images/phaser/pixel_1.png' ); }, create: function() { // background color this.stage.backgroundColor = '#6bf'; // scaling this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.maxWidth = this.game.width; this.scale.maxHeight = this.game.height; this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; this.scale.setScreenSize( true ); // physics this.physics.startSystem( Phaser.Physics.ARCADE ); // camera and platform tracking vars this.cameraYMin = 99999; this.platformYMin = 99999; // create platforms this.platformsCreate(); // create hero this.heroCreate(); // cursor controls this.cursor = this.input.keyboard.createCursorKeys(); }, update: function() { // this is where the main magic happens // the y offset and the height of the world are adjusted // to match the highest point the hero has reached this.world.setBounds( 0, -this.hero.yChange, this.world.width, this.game.height + this.hero.yChange ); // the built in camera follow methods won't work for our needs // this is a custom follow style that will not ever move down, it only moves up this.cameraYMin = Math.min( this.cameraYMin, this.hero.y - this.game.height + 130 ); .........完整代码请登录后点击上方下载按钮下载查看
网友评论0