Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:40:59+00:00 2026-06-16T00:40:59+00:00

I’m learning javascript by using the easeljs library to make a simple game, for

  • 0

I’m learning javascript by using the easeljs library to make a simple game, for school lessons.
I want to make a crosshair give some feedback to the player by showing a small animation while you are pointing at your target, using a hittest I made.

However, when the crosshair touches the target, the animation (should be two little triangles pointing to the middle of the crosshair) seems to be stuck on it’s first frame.

Here is a bit of my code, I put both of these functions inside a ticker function. The functions do what they’re supposed to do (I checked by sending a message to the console.log), but I think the animation is reset as soon as the variable “hitTestControle” is set to true, at every tick.
If you want to check out all of the code, here is a link to the “game”:
http://athena.fhict.nl/users/i279907/achtergrond/achtergrond.html

function hitTest() {
    if(distance(crossHair, block) < 60) {
        hitTestControle = true; 
} else {
        hitTestControle = false;
        console.log(hitTestControle);
    }
}

function hitTestControl() {
    if(hitTestControle == true) {
        crossHair.gotoAndPlay("move");
        console.log("hit");
    } else {
        crossHair.gotoAndPlay("stop");
    }
}

PS: There also seems to be something wrong with this hittest I used.

function distance() {
    var difx = blok.x - crossHair.x;
    var dify = blok.y - crossHair.y;
    return Math.sqrt( (difx * difx) + (dify * dify) );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:40:59+00:00Added an answer on June 16, 2026 at 12:40 am

    It looks like you’re starting the animation… setting it to the first frame and starting it… every time hitTestControle is true. Since hitTestControle will be true as long as you’re hovering over the target, the animation will never reach the second frame.

    What you need to do is start the animation when you transition from hitTestControle = false to hitTestControle = true, but once that happens you just let it play automatically.

    Try changing your hitTestControl() function to something like this:

    function hitTestControl() {
        if(hitTestControle == true && alreadyOverHit == false) {
            crossHair.gotoAndPlay("move");
            alreadyOverHit = true;
            console.log("hit");
        } else {
            crossHair.gotoAndPlay("stop");
            alreadyOverHit = false;
        }
    }
    

    In other words, only start the animation once, during the first frame you’re detecting a hit, and then don’t touch it unless you move off the target and back on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.