A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: CS3 AS2.0 - Collision problem

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Posts
    13

    CS3 AS2.0 - Collision problem

    Hi Flashkit community,

    I have a small problem I would like your help on today. I know I should be close to the answer, but spending hours trying to figure it out, my mind just crashed... so I'm asking for any help at all.

    Code:
    this.onEnterFrame = function(){
    	moveUpArrow();
    	moveDownArrow();
    	moveLeftArrow();
    	moveRightArrow();
    	if(_root.rootClip.hitBox_mc.hitTest(_root.upArrowMc)) {
    		_root.rootClip.score ++;
    	}
    }
    
    var arrowSpeed = 2.5;
    var arrowReady = true;
    var arrowDelay = 130;
    var arrowArray = [];
    var arrowCount = 0;
    
    function createUpArrow(){
    	var upArrowMc = _root.rootClip.attachMovie("Up", "Up" + arrowCount, 1000 + arrowCount);
    	arrowCount ++;
    	upArrowMc._x = 500;
    	upArrowMc._y = 768
    	arrowArray.push(upArrowMc);
    }
    function moveUpArrow(){
    	if(arrowReady && Key.isDown(Key.UP)){
    		arrowReady = false;
    		currentTime = getTimer();
    		createUpArrow();
    		_root.rootClip.score += random(100) +1;
    	} else{
    		if(currentTime + arrowDelay <= getTimer()){
    			arrowReady = true;
    		}
    	}
    	for (var i = 0; i<arrowArray.length; i++){
    		arrowArray[i]._y -= arrowSpeed;
    	}
    }
    This is what I got right now, I left out the code for Down, Left and Right functions, since they are pretty much the same.
    THE PROBLEM I have is the collision area... for some reason, the collision doesn't detect when there is an array involved with an attached MC. I know there has to be a way to detect this collision, (ie. games that have shooting bullets, damaging enemies, etc)

    So if anyone can modify my code, or even just point me into the right direction, I would be very grateful.

    Thanks in advance!

  2. #2
    Junior Member
    Join Date
    Feb 2008
    Posts
    13

    A better solution, but still need help!

    Sorry for the double post everyone, but I realized, i can achieve what i need with a simple distance formula.

    So if anyone can help me. I don't know where to put this statement:

    if("arrow_object"._y <= 120){
    _root.rootClip.score += random(100) +1;
    }

    I've tried this statement in many places, but i must have screwed up somewhere, it doesn't work correctly. The "arrow_object" is what ever the object should be. I have no clue why it doesn't work. I tried upArrowMc, but that didn't work.

    Anyway, any help would be great
    Thanks

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center