LokisHood

Members
  • Content Count

    5
  • Joined

  • Last visited

About LokisHood

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Location
    UK

Contact Methods

  • Twitter
    TinTopHat
  1. I've been programming for 15yrs and I can't believe I made that basic logical error!! Of course the first if stops any others! I feel like SUCH an idiot. Thank you for the help - also the extra info on checking the direction of the player before doing the animation. That was my next problem. Very much appreciated. Thank you for your patience.
  2. The specific source where keys are defined are availble as part of game.js on my Github here: https://github.com/OdinsHat/drac/blob/master/js/game.js The important bits where I try using the hotkey method is here: this.key_c = this.game.input.keyboard.addKey(Phaser.Keyboard.C);this.key_c.onDown.add(this.castSpell, this);Then the traditional if else method: if (this.cursors.left.isDown){ this.player.body.velocity.x = -100; this.player.animations.play('left'); }else if(this.cursors.right.isDown){ this.player.body.velocity.x = 100; this.player.animations.play('right'); }else if(this.cursors.up.isDown && this.cursors.left.isDown){ this.player.animations.play('cast-large-right'); }else if(this.key_c.isDown){ this.player.animations.play('cast-large-left'); }else{ this.player.animations.stop(); this.player.frame = 78; }This is my animation initialisation: this.player.animations.add('left', [117, 118, 119, 120, 121, 122, 123, 124, 125], 10, true); // Row Jthis.player.animations.add('right', [143, 144, 145, 146, 147, 148, 149, 150, 151], 10, true); // Row Lthis.player.animations.add('cast-small-left', [65, 66, 67, 68, 69, 70, 71, 72], 10, false); // Row Fthis.player.animations.add('cast-small-right', [91, 92, 93, 94, 95, 96, 97, 98], 10, false); // Row Hthis.player.animations.add('cast-large-left', [221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233], 10, false); // Row Rthis.player.animations.add('cast-large-right', [247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259], 10, false); // Row T0If I stop walking I can press "c" and the character will animate casting the spell. But I can't hold a key and press C. You'll also notice I've tried adding "UP" cursor key as a casting method but the same problem exists there. So I don't think its down to key combinations. Apologies for the messy code - I'm experimenting a LOT at the moment. Left + C - just walks Left + Up - just walks Left -stop- then C - Walks -stops- then casts. I want to use two keys at once to move and fire.
  3. Apologies if this is screamingly obvious but I've been Googling and searching this forum to no avail. This is only my second basic game so I've not much experience either. I have a character who walks about (left & right animations) and I want him to cast spells as he walks (another 2 animations). What I want to happen: 1. Hold left cursor key down. 2. Press C while left cursor key STILL held down. 3. Character immediately stops moving does "cast-left" animation. 4. Immediately continues walking left as you're still holding the button down. Tried So Far (but not worked): 1 - Using the hotkey method from the examples where you add an event handler to a key. 2 - Using a if (left key down && C key down){ do cast animation } I can get it to work if I stop pressing left to cast a spell but no one does that. Its always "move & fire" to use a common phrase. I can never get more than 1 key to register at the same time. Is this even possible or am I barking up the wrong tree? Hope someone can help.
  4. Some really. really helpful answers. Thank you so much to sleekdgital, george and Videlais! You've been more than helpful. Strangely enough I find classes (in Java, PHP, Python) easy to grasp. But when I start using Javascript I'm completely thrown by the use of "prototype" and insistance that JS isn't class-based although it can behave like it. I'm giving your link a read George as it looks to answer some of my biggest questions on JS in general - thank you. Once more into the breach!
  5. As someone whose main job is a web dev using jQuery I'm struggling to decide on the best approach to structuring my code now I'm onto states . I appreciate Richard not forcing you to use any particular method but I'd really appreciate being told what method to use right (best practice). I've seen 2 major ways of creating states: 1. In the Examples Repo: Rox.MainMenu = function (game) { this.music = null; this.playButton = null;};// Use of "prototype" indicates "prototype pattern"?Rox.MainMenu.prototype = { create: function () { this.add.image(390, 360, 'photonstorm'); this.input.onDown.addOnce(this.startGame, this); }, update: function () { }, startGame: function (pointer) { this.state.start('Game'); }};2. In LessMilks Flappy Bird Tutorial: // "Object literal notation"?var menu_state = { create: function() { var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); space_key.onDown.add(this.start, this); var style = { font: "30px Arial", fill: "#ffffff" }; var x = game.world.width/2, y = game.world.height/2; var text = this.game.add.text(x, y-50, "Press space to start", style); text.anchor.setTo(0.5, 0.5); if (score > 0) { var score_label = this.game.add.text(x, y+50, "score: " + score, style); score_label.anchor.setTo(0.5, 0.5); } }, start: function() { this.game.state.start('play'); }}My ultimate question (without starting a 'religious' war) is: Which of these is best practice way of structuring a game with multiple states like this? Secondly - what are the relative advantages/disadvantages to using either of these methods? Really hoping you can help - I've been reading "Learning JavaScript Design Patterns" by Addy Osmani as well as checking SO to get some insight but the book is just confusing me with even more JS possible patterns so I'm looking to you guys for some prodding in the right direction.