Skip to main content
Inspiring
December 2, 2021
Answered

mr kglad here i am again, collision and mousemove

  • December 2, 2021
  • 1 reply
  • 712 views

I i try implementing the chiken invaders GUI in my little crappy game, and all went well spachip moves fine, shoots, and kills spaships, but unlike with buttons control, now the hitTest wont execute, unless i clic on the bad spaceship, i try puting it in its own event, switch it to the move event, on top or down of the mousemove code, but execution is the same, if i hover player, over enemy1 nothing happens, unlest i clic on it and then the alert works 😞

 

this.on("tick", moverPlayerMou.bind(this));
function moverPlayerMou(evt) {
var pt = this.enemy1.hit.localToLocal(this.enemy1.hit.dot1.x,
this.enemy1.hit.dot1.y, this.player.box);
if (this.player.box.hitTest(pt.x, pt.y)) {
alert("collision")
this.player.x = -1000
deadenemies++
}
this.player.x = stage.mouseX;
this.player.y = stage.mouseY;
}

 

heres the file 

https://drive.google.com/file/d/1BXvg3b931cB8KKeEjWcmyeVYqUsYwyEF/view?usp=sharing

    This topic has been closed for replies.
    Correct answer kglad

    I love flash as you know and been very loyal, but i havc also try other Devs and the collisions are 10 times simple, the EaseJS tutorial of the hitTest its so raquitic and outdated, i could not get it done untill i found one of some latin american guy, I cant believe adobe wont provide a dedicated tutorial just about these, a mario stomping on a koopa, with fla, and, all like in the flashkit, times 😞


    i'm not sure what you were/are doing that was so difficult, but this is the basic hittest:

     

    createjs.Ticker.on("tick", tick.bind(this));


    function tick(event) {
    this.arm.rotation += 3;

    this.target.alpha = 0.2;
    var pt = this.arm.localToLocal(100, 0, this.target);
    if (this.target.hitTest(pt.x, pt.y)) {
    this.target.alpha = 1;
    }

    stage.update(event);
    }

    1 reply

    kglad
    Community Expert
    Community Expert
    December 2, 2021

    pt looks suspect.  use console.log to see if you're getting what you expect from localToLocal

    Inspiring
    December 2, 2021

    but, the alert, does execute, i am trying to simplify the path like 

     

    this.on("tick", moverPlayerMou.bind(this));
    function moverPlayerMou(evt) {
    var pt = this.enemy1.localToLocal(this.enemy1.x,
    this.enemy1.y, this.player.box);
    if (this.player.box.hitTest(pt.x, pt.y)) {
    alert("collision")
    this.player.x = -1000
    deadenemies++

    }
    this.player.x = stage.mouseX;
    this.player.y = stage.mouseY;
    }

     

    but like this the alert wont work, gonna check the console, why is flash always like this!? 

     

    tyvm legendary master flasher!!

    kglad
    Community Expert
    Community Expert
    December 4, 2021

    use:

     

    this.on("tick", moverPlayerMou.bind(this));
    function moverPlayerMou(evt) {
    var pt = this.enemy1.localToLocal(this.enemy1.x,
    this.enemy1.y, this.player.box);

    console.log(pt.x,pt.y);  // and you might want this.enemy1 and this.player.box info
    if (this.player.box.hitTest(pt.x, pt.y)) {
    alert("collision")
    this.player.x = -1000
    deadenemies++

    }
    this.player.x = stage.mouseX;
    this.player.y = stage.mouseY;
    }