phaser2 微信小游戏入手
phaser2小游戏基本没什么什么问题,可以下常开发游戏.如果遇到什么问题, 可以提出来共同讨论.
下面来个例子
import './lib/weapp-adapter';
import Phaser from './lib/phaser'; let systemInfo = wx.getSystemInfoSync();
let {windowWidth, windowHeight, pixelRatio} = systemInfo; var config = {
width: windowWidth * pixelRatio,
height: windowHeight * pixelRatio,
renderer: Phaser.WEBGL,
antialias: true,
multiTexture: true,
resolution:1,
canvas:canvas
} let game = new Phaser.Game(config);
game.state.add("boot", Boot, true); function Boot() { } Boot.prototype.preload = function() {
game.input.scale.x = pixelRatio;
game.input.scale.y = pixelRatio;
this.load.baseURL = "assets/";
game.load.image("crate", "crate.png");
} Boot.prototype.create = function() {
// adding P2 physics to the game
game.physics.startSystem(Phaser.Physics.P2JS);
// setting gravity
game.physics.p2.gravity.y = 250;
// adding event listener for mousedown/touch event
game.input.onDown.add(this.addRemove, this);
} Boot.prototype.addRemove = function(pointer){
// checking for bodies under the mouse
var bodyClicked = game.physics.p2.hitTest(pointer.position);
if (bodyClicked.length==0){
// creation of physics body and its graphic asset
var crate = game.add.sprite(pointer.position.x, pointer.position.y, "crate");
game.physics.p2.enable(crate);
}
else{
// destruction of physics body and its graphic asset
bodyClicked[0].parent.sprite.kill();
}
};
基于一般的全屏小游戏的宽高是640,高度是动态的.这里也是需要做下处理的
import './lib/weapp-adapter';
import Phaser from './lib/phaser'; let systemInfo = wx.getSystemInfoSync();
let {windowWidth, windowHeight, pixelRatio} = systemInfo;
let width = 640;
let height = 640 * windowHeight / windowWidth; var config = {
width,
height,
renderer: Phaser.WEBGL,
antialias: true,
multiTexture: true,
resolution:1,
canvas:canvas
} let game = new Phaser.Game(config);
game.state.add("boot", Boot, true); function Boot() { } Boot.prototype.preload = function() {
game.input.scale.x = config.width / windowWidth;
game.input.scale.y = config.height / windowHeight;
this.load.baseURL = "assets/";
game.load.image("crate", "crate.png");
} Boot.prototype.create = function() {
// adding P2 physics to the game
game.physics.startSystem(Phaser.Physics.P2JS);
// setting gravity
game.physics.p2.gravity.y = 250;
// adding event listener for mousedown/touch event
game.input.onDown.add(this.addRemove, this);
} Boot.prototype.addRemove = function(pointer){
// checking for bodies under the mouse
var bodyClicked = game.physics.p2.hitTest(pointer.position);
if (bodyClicked.length==0){
// creation of physics body and its graphic asset
var crate = game.add.sprite(pointer.position.x, pointer.position.y, "crate");
game.physics.p2.enable(crate);
}
else{
// destruction of physics body and its graphic asset
bodyClicked[0].parent.sprite.kill();
}
};
phaser开发小游戏一点问题都没,笔者已经用phaser开发三款小游戏。没有遇到什么大问题...
声音的话,sound.play方法,然后用wx的播放声音的方法代替.
github: https://gitee.com/redw1234567/phaser-ce
有问题留言或 QQ群 881784250. 谢谢~~~
phaser2 微信小游戏入手的更多相关文章
- pixi.js 微信小游戏 入手
pixi是什么?一款h5游戏引擎 优点:简单简洁性能第一 缺点:大多数用的国产三大引擎,pixi资料少,工具少, 为什么学,装逼 用pixi开发小游戏行吗? 行.但要简单处理下 下载官网上的 weap ...
- 没玩过这些微信小游戏你就out了
你确定没玩过下面这些微信小游戏?是不是有点out了?赶紧添加微信号kangfuyk,回复H5马上畅玩! 当然了,扫一下二维码关注后回复H5更快捷噢! 微信小游戏列表,持续更新中 辨色大比拼!心理游戏 ...
- 【转】微信小游戏接入Fundebug监控
在SegmentFault上看到Fundebug上线小游戏监控,刚好最近开始玩微信小游戏,于是尝试接入试了一下. 接入方法 创建项目的时候选择左下角的微信小游戏图标. 点击继续进入接入插件页面. 第三 ...
- 【转】Fundebug上线微信小游戏错误监控!支持自动截屏!
摘要: Fundebug竭诚为你的小游戏保驾护航. 想必大家都玩过"跳一跳"吧?刷排行榜的感觉是不是很好啊!还有"知乎答题王"呢,在智力上碾压老铁简直太棒了! ...
- 【转】利用 three.js 开发微信小游戏的尝试
前言 这是一次利用 three.js 开发微信小游戏的尝试,并不能算作是教程,只能算是一篇笔记吧. 微信 WeChat 6.6.1 开始引入了微信小游戏,初期上线了一批质量相当不错的小游戏.我在查阅各 ...
- 微信小游戏开发之四:使用three.js引擎
一.前言 微信小游戏中最魔性的'跳一跳'就是基于three.js 引擎开发的 源码放到github上了:GitHub地址 请自行下载. 二.下载 three.min.js 打开页面,复制代码到本地 ...
- 微信小游戏开发Canvas资源汇总
Demo: 微信小程序demo组件:股票分时图 微信小程序小组件:仿直播点赞气泡效果,基于Canvas 优质demo推荐:二维码生成器:使用canvas与纯JS版二维码生成 微信小程序学习用完整dem ...
- 微信小游戏爆款秘笈 数据库MongoDB攻略篇
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB 发表于云+社区专栏 随着微信小游戏的爆发,越来越多开发者关注到MongoDB与小游戏业务的契合度. ...
- Egret 生成 自带EUI 的微信小游戏 踩坑!
1. 首先,再次被网上一大堆屎一样的资料搞得浪费了我一天时间.各种坑. 2. 本文先讲一种正确的方式,然后再列举坑. 去www.egret.com下载最新的引擎,我的最新版本是5.2.2. 然后就会被 ...
随机推荐
- 20155317 王新玮 2006-2007-2 《Java程序设计》第4周学习总结
20155317 王新玮 2006-2007-2 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 继承共同行为 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那 ...
- 238. Product of Array Except Self(对O(n)和递归又有了新的理解)
238. Product of Array Except Self Total Accepted: 41565 Total Submissions: 97898 Difficulty: Med ...
- PHP中的事件处理
看下面的事件类 class Event { protected static $listens = array(); /** * [listen 注册监听事件] * @param [string] $ ...
- Visual Studio设置字体及护眼背景色
打开vs 菜单栏选择: 工具 -> 选择 -> 环境 -> 字体和颜色,如图所示 字体可以如上选择,背景色选择项背景,点击自定义,如下设置即可.
- PHP双向队列
假定队列的左边为头部,右边为尾部 <?php class myDeque { private $deque=array(); /** *头部进队列 */ public function lPus ...
- selenium+python 搭建自动化环境
一.以搭建windows平台为例 准备工具如下: 1)下载Python 2)安装,配置环境变量 3)安装selenium,通过pip安装,命令如下: pip install selenium 方式二 ...
- 天下武功,无快不破,Python开发必备的6个库
01 Python 必备之 PyPy PyPy 主要用于何处? 如果你需要更快的 Python 应用程序,最简单的实现的方法就是通过 PyPy ,Python 运行时与实时(JIT)编译器.与使用普通 ...
- 设置PNG图片DPI 信息,保存为PDF(使用Magick),与OpenCV转换
目录 任务描述 解决方案 Magick++ Talk is cheap, show me the code. 与 Opencv 配合 相关链接 任务描述 我有这样一个需求,读取一张格式为PNG 或者 ...
- Hive中使用sql的注意事项
一.别名的使用 定义别名:columnA as X 不需要使用单引号 使用别名:不与where同时使用 花式报错-->有说hive不支持where后使用别名 二.GROUP BY select ...
- 53. [LeetCode] Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...