
benjamin
Members-
Posts
10 -
Joined
-
Last visited
Everything posted by benjamin
-
My general rule is you never refactor something just because you wrote it twice. I always put my threshold for refactoring to 3 or more. Flexibility is valuable! That aside I'm assuming you have hard a look and really decided you need to refactor. This is how I would go about it. BasePlayer = function (game, x, y, key) { Phaser.Sprite.call(this, game, x, y, key);};BasePlayer.prototype = Object.create(Phaser.Sprite.prototype);BasePlayer.prototype.constructor = BasePlayer;BasePlayer.prototype.specialMovement = function (arg1, arg2, ... ..) { // ...do your thing!};Human = function (game, x, y) { BasePlayer.call(this, game, x, y, 'human');};Human.prototype = Object.create(BasePlayer.prototype);Human.prototype.constructor = Human;Human.prototype.laugh = function (arg1, arg2, ... ..) { // ...ha ha ha ha ha};Enemy = function (game, x, y) { BasePlayer.call(this, game, x, y, 'enemy');};Enemy.prototype = Object.create(BasePlayer.prototype);Enemy.prototype.constructor = Enemy;Enemy.prototype.laugh = function (arg1, arg2, ... ..) { // ...mwaha ha ha mwaha ha};Both Human and Enemy are capable of 'special movement' because they inherit from BasePlayer. And Human and Enamy can also have their own functions as well!
-
I refactored my code today, without using groups. and debugging seems fine. So i'll have another shot later to see if it's to do with groups... also I found game.debug.body is not required.
-
when i switch to p2js I can't seem to debug physics at all (I dont see any overlays). So here is what i am doing oncreate this.pandas = game.add.group(game.world, 'pandas', false, true, Phaser.Physics.P2JS); this.pandas.createMultiple(28, 'panda');onupdate at certain intervals I fetch a panda! var panda = this.pandas.getFirstExists(false); if (!panda) { return; }...panda.reset(x, y);panda.debug = true;render this.pandas.forEachAlive(function(panda) { game.debug.body(panda); });
-
Just my guess here. collide is meant to be called each time you want to test for collision and trigger reactions. (e.g on every update). Secondly collide expects the two objects that you want to test for collision. so remove your collision stuff from the Enemytank object, and place this in your update callback. (what is 'cat'?) game.physics.arcade.collide(this.tank,cat);and this this.game.physics.arcade.collide(this.tank, enemies);You may also want to add a callback as a third parameter if you want to be notified of the collision.
-
Is there a simple way to lock the x or y axis of a p2js body? I ask because I need to keep a group of objects within columns, I'm hoping I can avoid creating new column-gutter sprites just to separate the columns.
-
I had thought of custom collision handling, but the problem is that by the time arcade calls your collision callback, it's too late, the body may already have overlapped, so if you 'lock' things, it starts to look a little weird. I think you might be right but I'll leave this open until tomorrow incase someone finds a sneaky solution we haven't thought of.
-
I have a scene where blocks fall from the sky onto the ground. As they do, they stack up thanks to collision separation. I noticed however that after the stack reaches a height of two or three blocks the incoming block somehow forces blocks at the bottom to lose their separation. I want to stop that from happening. If two blocks collide they should remain separated. I am using the arcade physics, (hope that's not the problem). here is the code window.onload = function() { 'use strict'; var state = { lastCheckin: 0, pandas: null, preload: function () { game.load.image('panda', 'assets/panda.png'); }, loadUpdate: function () { }, loadRender: function () { }, create: function () { game.physics.startSystem(Phaser.Physics.ARCADE); this.pandas = game.add.group(); }, update: function () { game.physics.arcade.collide(this.pandas, this.pandas); var now = Date.now(), delta = now - this.lastCheckin; if (delta > 1000) { this.lastCheckin = now; var panda = game.add.sprite(Math.random() * game.world.width, 0, 'panda'); this.pandas.add(panda); game.physics.arcade.enable(panda); panda.body.gravity.y = 500; panda.body.collideWorldBounds = true; } }, render: function () { }, paused: function () { }, pauseUpdate: function () { }, shutdown: function () { } } var game = new Phaser.Game(320, 480, null, null, state);};
-
I liked the jumbotron and the graphical fidelity. My only problem was the music. It's not bad at all, it's just that it doesn't fit the game. I think you could get away with sound effects alone on this one. and perhaps make it a tad less challenging to begin with. (that or my hand eye co-ordination is terrible