Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2018
    Thanked 0 Times in 0 Posts

    hitTest problems

    Hi. I'm new to coding and to this site.
    Having trouble getting hitTest to work. I'm following a pretty simple tutorial for a Pong ame, and I've gotten just about everything to work but I'm stuck on collisions. The weird thing is, the hitTest works for the cpuPaddle consistently, but for the playerPaddle it only works one time and then won't for the rest. Seems like a glitch to me and made me wonder if I need to import something?

    Here's everything I'm importing:

    import flash.events.Event;
    import flash.events.*;
    import flash.display.Stage;

    Here's the the part where I'm using the hitTest:

    if( playerPaddle.hitTestObject(ball) == true){
    		if(ballSpeedX < 0){
    			ballSpeedX *= -1;
    	}else if(cpuPaddle.hitTestObject(ball) == true){
    		if(ballSpeedX > 0){
    			ballSpeedX *= -1;

    playerPaddle, cpuPaddle, and call are all objects on the stage..
    why would one work but not other? and why would it only work one time?

    I greatly appreciate you :)
    Last edited by vinyl-junkie; Oct 21st, 2018 at 02:14 PM. Reason: corrected code tags

  2. #2
    Regular Coder
    Join Date
    Jun 2008
    Thanked 27 Times in 27 Posts
    AS is a long time ago for me, but i would guess that you need to add this function into your onEnterFrame function. Anything else looks good beside you don't need == true. Just if( playerPaddle.hitTestObject(ball)) should be fine
    I never ever read PM's unless it's an job offer. So save your time for regular questions in the forum. I never ever take friendship offers. We are not on facebook here.(It's stupid on facebook too). Friendship? Do i know you? Did we ever had a beer together? Thats really stupid. Sorry.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts