icecube101

Members
  • Content count

    8
  • Joined

  • Last visited

  1. Tween problems / onComplete

    @samme Yeah there's definetely an easier way of coding this. Basically I needed a button to pause/resume everything at a quick click. I did get it to work but I didn't understand why my methods acted like that. @samid737 Well that makes more sense now! I appreciate your detailed message! I'm gonna have to take a second and read your reply several times because I'm not quite familiar with method chaining in Javascript. I might've skipped some basic lessons. Thanks both of you for the replies!
  2. Tween problems / onComplete

    Hello guys, I have 2 'simple questions' (I assume) that kinda bugs me for a while now. I wouldn't want to get too in-depth with this mainly because I'm not good at explaining stuff; but I'll try to keep it simple. 1st question: Is 'fig 1' and 'fig 2' supposed to be the same thing? 2nd question: I got a button that is supposed to pause the game. 'mygamepaused' is a variable that goes true/false on a click. 'mytimepass' is a 3 seconds timer that runs the tween from the first question. 'smiley_tw_pass' is a variable that goes true when the timer is finished (aka my way of telling the program that the tween just started) 'smiley_tw' is the name assigned to the tween (see question 1). After the tween is completed (see question 1) - the sprite (this.smiley) goes to 100 on y axis and changes alpha to 0.1. Here's where I run into problems. 1st: "smiley_tw is not defined" console error when trying to press the button before the timer passess (aka it cannot find the tween) fixed it by assigning a variable (smiley_tw_pass) right after the timer runs out. ...is that a good way of checking if the tween just started?... 2nd: "smiley_tw.pause is not a function" console error when using fig 1 (see question 1) fixed it by using fig 2 (see question 1) ...this bugs me because in my mind the two methods should work the same way, right?... So that's how I solved the problem - by using a variable to detect if the tween just started AND using fig 2 instead of the first one - But WHY? Why does the 2 methods doesn't work the same way here - AND - is declaring a variable (smiley_tw_pass) to check if a tween is running - a good thing? I would really appreciate if someone can figure this 'mistery' and can clear my mind a little. Full code: (480x720) var Test = function (game) {}; var mygamepaused = false; var smiley_tw_pass = false; Test.prototype = { create: function () { //create button this.mybutton = game.add.button(this.world.centerX, 600, 'smiley', this.myfunction, this); this.mybutton.anchor.setTo(.5); this.mybutton.scale.setTo(.2); this.mybutton.inputEnabled = true; //create smiley this.smiley = game.add.sprite(this.world.centerX, this.world.centerY, 'smiley'); this.smiley.anchor.setTo(.5); this.smiley.scale.setTo(.5); //create mytimepass mytimepass = game.time.create(false); mytimepass.add(3000, function () { if (!smiley_tw_pass) smiley_tw_pass = true; smiley_tw = game.add.tween(this.smiley).to({ alpha: 0 }, 1200, Phaser.Easing.Quadratic.InOut, true); smiley_tw.onComplete.add(function () { this.smiley.y = 100; this.smiley.alpha = 0.1; }, this); }, this); mytimepass.start(); }, myfunction: function () { switch (mygamepaused) { case false: mygamepaused = true; mytimepass.pause(); if (smiley_tw_pass) smiley_tw.pause(); break; case true: mygamepaused = false; mytimepass.resume(); if (smiley_tw_pass) smiley_tw.resume(); break; } }, render: function () { game.debug.text('mygamepaused: ' + mygamepaused, 20, 20); game.debug.text('smiley_tw_pass: ' + smiley_tw_pass, 20, 40); game.debug.text('mytimepass: ' + mytimepass.duration.toFixed(0), 20, 80); } };
  3. Arcade overlap doesn't work

    I think the problem here is the beam's hitbox. You see, every sprite has a hitbox and it's basically a rectangle shape; rotating the beam at 45 degrees will not rotate the hitbox. You can change its size but not its shape; unless you take the p2 physics route which will have an impact on the performance due to the complex shape; it will require more cpu power. Granted I might be wrong about this and your problem might be something else...sorry that I can't give you a straight answer but I'm kinda new to Phaser myself. Someone more experienced might help you on this one Take a look here: https://phaser.io/examples/v2/p2-physics/body-debug Try to render the beam's body and see what's going on: update: function () { //stuff }, render: function () { this.game.debug.body(player); this.beams.forEachAlive(function (beams_body) { this.game.debug.body(beams_body); }, this); }
  4. 'Kill' and 'Revive' sprites individually in a Group

    @samid737 Ooohh yeah I get it, that makes sense now. Thanks for the explanation! It works great now, assigning a property did the job. Thank you both very much for your help!
  5. 'Kill' and 'Revive' sprites individually in a Group

    @samme I actually have more than 2 sprites in the group. (but only 2 enemies: red+blue) So what I mean is that I have a loop that creates multiple sprites (e.g. 20 blue enemies and 20 red enemies). They are 'separated' to say by 2 chars and 2 variables: 'b' for blue and 'r' for red + 'e_blue' (variable) / 'e_red' (variable). I also have a two-dimensional array that looks like this: system_var = [ 'bbb00000bbb', '000rrrrr000', 'bbb00000bbb', ]; Basically everytime it sees the letter 'b' it creates a blue enemy and adds it to the group / same goes to the char 'r' for the red enemy. (0 = empty) for (i = 0; i < system_var.length; i++) { for (j = 0; j < system_var.length; j++) { switch(system_var[j]){ case 'b': var e_blue = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_blue); break; case 'r': var e_red = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_red); break; } } } ------------ I thought that I could control these sprites by just using the variables I've provided them with. (e.g. there are 20 blue enemies that uses variable 'e_blue' and 20 red enemies that uses variable 'e_red') (so whenever I want all the blue enemies to move right I say e_blue.x++; and it moves all the 20 sprites I've created)... What is the correct way of doing this? Do I have to create a group for blue and one for red and then place them inside the 'mother' group (aka enemy_wave) ? Wouldn't that create a bigger 'mess'?
  6. Hello, I'm wondering if someone could help me solve this problem I have with 'Groups' in Phaser. So I have a group called 'enemy_wave' and it has 2 sprites attached to it: 'e_blue' and 'e_red'. Now, I want to 'kill' (sprite.kill();) 'e_blue' sprite and 'revive' (sprite.revive();) it later. Everytime I try to do that it also kills 'e_red', no matter how I put it. this.enemy_wave = game.add.group(); this.enemy_wave.enableBody = true; this.enemy_wave.physicsBodyType = Phaser.Physics.ARCADE; for (i = 0; i < system_var.length; i++) { for (j = 0; j < system_var[i].length; j++) { switch(system_var[i][j]){ case 'b': var e_blue = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_blue); break; case 'r': var e_red = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_red); break; } } } This is how I 'kill' sprites: this.enemy_wave.forEachAlive(function (e_blue) { e_blue.kill(); }, this); And this is how I 'revive' sprites: this.enemy_wave.forEachDead(function (e_blue) { e_blue.revive(); }, this); So yeah it doesn't matter if I kill 'e_blue' or 'e_red' because either way it 'kills'/'revives' all sprites attached to this group. How do I go about this? What seems wrong here? ~Thanks!
  7. Create multiple groups - 'for' loop?

    Haha nice! Yeah that was it. I knew something was off but for some reason I couldn't get it. Thanks for the help!
  8. Create multiple groups - 'for' loop?

    Hey guys, I have a quick question about 'Groups' as I'm kinda new to this Phaser HTML5 game dev. So my plan is to create multiple groups and have control over each one of them. First thing that came into my mind is to create a 'for loop' and be done with! Problem is that I don't know how to assign different names for a variable (wave).Example: Instead of doing this: this.wave00 = game.add.group(); this.wave00.enableBody = true; this.wave00.physicsBodyType = Phaser.Physics.ARCADE; this.wave01 = game.add.group(); this.wave01.enableBody = true; this.wave01.physicsBodyType = Phaser.Physics.ARCADE; this.wave02 = game.add.group(); this.wave02.enableBody = true; this.wave02.physicsBodyType = Phaser.Physics.ARCADE; I am trying to do this: for(i=0; i<10; i++){ this.['wave'+i] = game.add.group(); this.['wave'+i].enableBody = true; this.['wave'+i].physicsBodyType = Phaser.Physics.ARCADE; } So I'm sure you got the idea but this (['wave'+i]) is the problem. Can someone help me with this? What is the correct way of writing it? I've been searching but maybe I'm not questioning this correctly. Thanks and sorry for the noob question!