Phaser

Flappy Bird

感情迁移 提交于 2020-02-04 17:48:37
在网上学习了下“65行 JavaScript 代码实现 Flappy Bird 游戏”( http://blog.jobbole.com/61842/ ),main.js 如下: // Initialize Phaser, and creates a 400x490px game var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div'); // Creates a new 'main' state that wil contain the game var main_state = { preload:function() { this.game.stage.backgroundColor = '#71c5cf'; this.game.load.image('bird','assets/bird.png'); this.game.load.image('pipe','assets/pipe.png'); }, create:function() { this.bird = this.game.add.sprite(100,245,'bird'); this.bird.body.gravity.y = 1000; this.pipes = game.add.group(); this.pipes

phaser学习笔记1

拈花ヽ惹草 提交于 2020-01-14 02:29:48
移动端全屏 咨询了一个用phaser做过游戏的同学的方案,以及网上查了一下相关资料。全屏的解决方案,基本都是要先读取屏幕的宽高,根据宽高再去设置Game的width和height。 在宽高的获取和使用上,还要考虑屏幕缩放尺寸问题( devicePixelRatio )。这就是屏幕的真实像素和逻辑像素比例,避免出现显示模糊。 加载图片尺寸 这是紧接着上一个问题需要考虑的问题。 当适配不同屏幕时,Game的尺寸发生了变化,那么加载到页面上的图片素材,也是需要进行相应的尺寸调整。 加载图片时,有个方法, setScale , 这可以调整图片的放大缩小尺寸,进而解决问题。 animation/anims动画 这里的动画概念,是多张图/状态的切换。例如sprite图里,多个图块内容切换。 actions actions,在我理解,就是对phaser对象进行的操作,改变x值,y值,放置在圆圈上等等。 Geom几何图形 创建圆,三角形,长方形,椭圆,都要用这个方法。 Tween补间动画 就是一个物体,从一个地方,向另一个地方移动。 来源: CSDN 作者: peade 链接: https://blog.csdn.net/peade/article/details/103940027

Java并发编程中级篇(五):更强大的多阶段并发控制Phaser

纵饮孤独 提交于 2020-01-07 07:46:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Java API还提供了一个强大的同步辅助类Pahser,它可以控制多阶段并发辅助任务。当我们有并发任务,并且需要分阶段执行,每阶段都需要等待所有线程执行本阶段执行完毕才能够继续执行,这种机制就非常好用。Phaser类同样需要一个整形作为初始化参数来确定有几个线程参与执行。 下面我们来看一个例子,在这个例子中我们把一个并发任务分为三个阶段,每一阶段都需要所有线程完成后才能继续执行下一阶段的任务。 我们来定义一个带有Phaser机制的线程类PhaserRunnable,在线程开始运行的时候调用arriverAndAwaitAdvance()方法来代表线程已经进入执行状态,其实这个也可以算作一步,就是等待所有任务线程都启动后大家一起执行。然后开始执行第一步任务,每个线程随机休眠一段时间来模拟任务执行耗时,执行完毕后调用arriverAndAwaitAdvance()来表示任务执行完毕,然后等待其他线程,等所有线程都滴啊用arriverAndAwaitAdvance()方法后,所有休眠的线程都被唤醒然后继续执行第二步。也是随机休眠一段时间后,第二部执行完毕,但是这里有一个不同,如果休眠时间是一个双数那么线程将不再执行第三步操作而是直接返回,这里要调用phaser.arriveAndDeregister(

Phaser

馋奶兔 提交于 2020-01-06 16:47:35
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Phaser是一个类型于CountDownLatch和CyclicBarrier的类,但是要比前两个灵活许多,它可以动态变化增加 先说说使用核心:那就是跟CyclicBarrier类似,也是等待的线程数到达一定值时所有线程才可以往下走,但是要比CyclicBarrier更加灵活,它可以动态的控制这个数值。 然后看看使用的核心方法: 跟CyclicBarrier一样可以初始化的时候指定长度,也可以不指定长度 Phaser phaser = new Phaser(); Phaser phaser = new Phaser(1); 通过arriveAndAwaitAdvance()来等待下一阶段的运行 register()和arriveAndDeregister() 这两个方法是用来增加和减少注册量,这个注册量就相当于CyclicBarrier的固定数值。bulkResgister(int) 这方法是批量增加线程数 getPhaser() 可以获取当前是第几阶段,通俗点说就是当前是第几次等待 getArrivedParties()和getUnarrivedParties()这两个方法可以获取到达和未到达该屏障的线程数 isTerminated() 此方法是判断Phaser有没有结束,意思就是注册数是不是为0

软工项目个人总结

房东的猫 提交于 2020-01-01 05:01:58
这学期软工小组的开发就快结束了,回想整个开发过程,感慨颇多。 首先是刚开学时的组队和选题,我们各自提了好多项目,有的太简单,有的没有价值,有的又太不切实际,最终我们选定付千山同学在高中设计的游戏作为题目,因为这既新颖又有前期调研,而且也比较有趣。 但其实,我之前从来没有游戏开发的经验,组员们也只了解一两门语言,几乎没有大型项目开发经验。所以,这次项目从技术选型到开发都是一边摸索一边做。现在回过头去看,有得有失。首先,Travis CI 的学习和使用是非常正确的决定,因为后端运行环境比较苛刻,不方便在组员自己的电脑上搭建。因此,我们需要快速部署更新的代码,以方便测试和调试。如果按照我以前的方法手动更新,那么效率将大大降低。这个问题还有一个解决方案,即配置一个 docker 镜像,让大家都能迅速搭建服务器。这个方案也很不错,下次可以实践一下;然而,技术选型就有些差强人意了。先说后端,后端的技术是 Scala + Java,效果并不如刚开始以为的那么好,Scala 和 Java 的交互体验并不是那么友好,一是 Scala 的库 Java 用起来很困难,二是 Scala 的常用写法在 Java 没法写,三是 Scala 和 Java 的并行控制也不尽相同,尤其是在 Scala 中使用 Actor 时。不过庆幸的是,Java 部分的代码大部分是无状态的,这方便了单元测试,也方便了并发控制

Understanding phaser in java with an example

夙愿已清 提交于 2019-12-19 04:49:08
问题 I am trying to understand Phaser in java. I wrote an example which is stuck at advance waiting for other parties to arrive. As far as I understand, phaser is used as a reusable thread synchronization (unlike CountdownLatch which is not reusable) barrier with a barrier action (unlike Cyclicbarrier which is used to share state, Phaser doesn't have to share state in barrier action). Correct me if I am wrong. So, in my example, I am trying to execute some random addition and subtraction code in

Java: tutorials/explanations of jsr166y Phaser

六眼飞鱼酱① 提交于 2019-12-17 22:16:29
问题 This question was asked two years ago, but the resources it mentions are either not very helpful (IMHO) or links are no longer valid. There must be some good tutorials out there to understand Phaser. I've read the javadoc, but my eyes glaze over, since in order to really understand the javadoc you kind of have to know how these classes are supposed to be used. Anyone have any suggestions? 回答1: For Phaser I have answered a few questions. Seeing them may help in understanding their applications

Flexible CountDownLatch?

别说谁变了你拦得住时间么 提交于 2019-12-17 22:15:26
问题 I have encountered a problem twice now whereby a producer thread produces N work items, submits them to an ExecutorService and then needs to wait until all N items have been processed. Caveats N is not known in advance . If it were I would simply create a CountDownLatch and then have producer thread await() until all work was complete. Using a CompletionService is inappropriate because although my producer thread needs to block (i.e. by calling take() ) there's no way of signalling that all

Game lobby with socket.io and express

天大地大妈咪最大 提交于 2019-12-12 06:50:02
问题 I'm creating a web game using socket.io and express. I want to let users create their lobby and I want to use socket.io to emit data (position, etc...) only to the lobby that they're connected. How can I do it? For the moment I found this code online but it emit data to all the lobby that are created. index.js var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Create lobby', errors: req

Java: tutorials/explanations of jsr166y Phaser

China☆狼群 提交于 2019-12-11 03:36:30
问题 This question was asked two years ago, but the resources it mentions are either not very helpful (IMHO) or links are no longer valid. There must be some good tutorials out there to understand Phaser. I've read the javadoc, but my eyes glaze over, since in order to really understand the javadoc you kind of have to know how these classes are supposed to be used. Anyone have any suggestions? 回答1: For Phaser I have answered a few questions. Seeing them may help in understanding their applications