ldd

Members
  • Content count

    70
  • Joined

  • Last visited

About ldd

  • Rank
    Advanced Member

Profile Information

  • Location
    Montreal
  1. You are making the right type of mistakes! (which is good) try this: let fn = ()=>false; console.log( fn == true && true, fn && true); a function is truthy, but when compared to true with ==, it will return false. This seems voodo magic until you read the specs[0][1] ps: there is a difference between fn, and fn(), just like in your example. You'd need `condition(count)` to make it work [0] http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 [1] http://www.ecma-international.org/ecma-262/5.1/#sec-11.8.5
  2. Adding a parameter where needed[0]: function preload() {...} function create() { ... fun1(this.game, a, b, etc) } function update() { ... fun2(this.game, a, b, etc); fun3(this.game, a, b, etc) } function fun1(game, etc) {...} function fun2(game, etc) {...} function fun3(game, etc) {...} module.exports = { // Calling this file as state object later preload, create, update } Or using IIFE var App = (function(api, game){ api.game = game; function preload() {...} function create() { /* use api.game to access game instead of this.game */ /* read the docs, and see how you can get away with cleaner code that doesn't rely on binding */ } function update() { ... fun2(); fun3() } function fun1() {...} function fun2() {...} function fun3() {...} //expose stuff api.preload = preload; api.create = create; api.update = update; return api; })(App || {}, this.game /* or other stuff that I can't remember*/) In fact, I'd recommend going this route if you want to stick to ES5 because it simplifies your life, AND you are very free to use multiple files to separate concearns, only expose what you want,etc. Lastly, you may consider ES6 and Webpack (which makes everything butter smooth) import 'pixi'; import Phaser from 'phaser'; import BootState from './states/Boot'; import SplashState from './states/Splash'; import MenuState from './states/Menu'; import PlayState from './states/Play'; /** Class representing a game. * @extends Phaser.Game */ class Game extends Phaser.Game { /** * @constructs Create a game. When done, go to the {@link Boot} state. */ constructor() { let width = document.documentElement.clientWidth; let height = document.documentElement.clientHeight; let config = {/*[REDACTED for brevity] */}; super(config); // Add all necessary game states this.state.add('Boot', BootState, false); this.state.add('Splash', SplashState, false); this.state.add('Menu', MenuState, false); this.state.add('Play', PlayState, false); this.state.start('Boot'); } } new Game(); [0] http://pmuellr.blogspot.ca/2010/06/bind-considered-harmful.html Anyways, some suggested readings on the topic: [1] https://github.com/getify/You-Dont-Know-JS/blob/master/scope %26 closures/apC.md [2] https://github.com/getify/You-Dont-Know-JS/blob/master/this & object prototypes/README.md#you-dont-know-js-this--object-prototypes [3] https://codereview.stackexchange.com/questions/49872/using-var-self-this-or-bindthis
  3. Tower Defense, place tower mechanic

    Does this example help? https://phaser.io/examples/v2/input/drag If not, there are other examples here: https://phaser.io/examples/v2/category/input Otherwise, I think trying to list the things you want to accomplish would help. I'd guess you want to do something like 1) click on structure 2) drag structure to map 3) leave structure in map Most of that is just a combination of the tutorials that I linked, so hopefully you figure it out
  4. how to add multiple keys

    const addOnce = (keyString, self) => { const key = game.input.keyboard.addKey(Phaser.Keyboard[keyString]); key.onDown.addOnce(self.start, self); } or maybe even const addKeys = (keyStrings, self) => { keyStrings.forEach( (keyString) => { const key = game.input.keyboard.addKey(Phaser.Keyboard[keyString]); key.onDown.addOnce(self.start, self); }); } //usage addKeys(['W','A','S','D'], something);
  5. functional programmation error ....

    I think they meant const add = (list, item) => list.concat(item) //example add([3,4],5) //output is [3,4,5] otherwise you have a function that returns a function and you'd use it like so: const add = list => item => list.concat(item) //example add([3,4])(5) //output is [3,4,5] (keep in mind that in functional programming you'd rather use `concat` rather than `push` )
  6. Couple of quick pointers: 1) Avoid using function names that closely match reserved words or already existing native code. Array.prototype.forEach already exists, so avoid names like 'forEach' 2) is_exist sounds weird, and can be simplified: const is_defined = (obj) => obj !== undefined just keep in mind that there are better check than this, and consider cases like when obj is null, etc (be careful when doing comparisons and read on the topic) 3) you are trying to use a method that can be accessed by each individual item in an array. If it is always hide, you can simply do const hide_enemies = (enemies) => enemies.forEach( (enemy) => enemy.hide() ); or if you need to call other methods, just use a string to represent a possible method name const hide_enemies = (enemies, actionString) => enemies.forEach( (enemy) => enemy[actionString]() ); In old-school syntax, you could write function hide_enemies(enemies){ enemies.forEach( function(enemy){ return enemy.hide(); }); } If you tell me more about why you are checking is_exist(obj[0]), we could probably avoid awkward checks. Finally, you could check out this quick guide to Array functions that may provide you with more information.
  7. from my experience, and plenty of other people's experience, it is 'bullets against bullets' that is causing your problems. If you can, disable that type of collision. If you absolutely must have bullets against bullets or other things, consider making less collisions anyways (maybe bullets only collide before 1 second has passed away, or only if your level is high, etc) In general, avoid collisions as much as you possibly can.
  8. See an example in localhost

    Phaser examples are in another repository, away from the main phaser project. https://github.com/photonstorm/phaser-examples Just clone and download that repo ;D
  9. AsterWaster Game

    Interesting idea! Some comments: - It should be "Let's Battle". Spellcheck your game. - your UI needs a lot of work
  10. Failed to slice sprite sheet image into frames

    per the documentation: new Phaser.Image(game, x, y, key, frame) so you are missing an argument to specify the frame ps: why is this forum using a rich text editor and not markdown? +.+
  11. Dynamic function calling

    var myArray = []; function doStuff(arr){ for (var i=0; i< 3; i++){ arr[i] = function(){ console.log(i); } } } doStuff(myArray); myArray[0](); //3 myArray[1](); //3 //fix with ES6 let function doStuffImproved(arr){ for(let k=0;k < 3; k++){ arr[k] = function(){ console.log(k); } } } doStuffImproved(myArray); myArray[0](); //0 myArray[1](); //1 //fix with forEach function doStuffOther(arr){ return arr.forEach(function(el,l){ console.log(l); } } doStuffOther(myArray); myArray[0](); //0 myArray[1](); //1 //fix with closure //etc You need to learn a little bit more javascript to avoid these types of errors.
  12. Quick way to disable ALL physics?

    physics are opt-in, not opt-out. If you do not need physics, just don't use them. On the other hand, aer you asking about disabling physics AFTER enabling them before?
  13. Pixel Cave [roguelike]

    is this still under active development?
  14. struggling with tile mapping

    https://github.com/Brad-Chapin/daky-in-monsterland/blob/master/js/main.js Your code doesn't include a tilemap. Follow this example: https://phaser.io/examples/v2/tilemaps/blank-tilemap Additionally, looking at your repo, I cannot find a tileset in https://github.com/Brad-Chapin/daky-in-monsterland/tree/master/assets Are you sure you included it, and pushed to github your latest code?
  15. I usually just reply to people asking questions, but I thought I'd show some open-source tools that you could potentially use in your games: https://github.com/ldd/tech-tree-js (source) minimally display a tech tree (I did this a long time ago, and I don't really know if anybody would want me to continue working on it, but basically it lets you display a tech tree and store it fantasy map generator (source) another thing I've just started working on, which uses the code made by Martin O'Leary and attempts to quickly show the user fantasy maps. you can colour them too! yay! Anyways, those are somewhat interesting ideas that I had for games that I never really ended up using anyways... since they are MIT-licensed, I thought maybe somebody would be interested in using them and giving me feedback.