A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] Webcam Game Help!

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    2

    [F8] Webcam Game Help!

    Hello everybody, i was wondering if anybody would be able to help me.

    I am creating a webcam game where balls from the sky and it is your idea to hit the ball using your hands. I have implemented a script to generate more than 1 ball but for some reason the hit detection is not working. No matter what i have tried i have not managed to be able to include a script that generates more balls based from one movie clip whilst retaining the hit detection. I thought i had this cracked months ago but it appears i was wrong.

    I have implemented various different methods of generating falling balls which is fine as i have the balls populating the screen but it is the hit detection i am having issues with. No matter what i do i just cannot get it to work. I am convinced it is something minor that needs changing but i just cannot figure it out at all!

    I have included the fla in this post.

    '1 ball working' demonstrates a technique i used to generate multiple balls. Code is placed on the ball_mc movie clip itself and code is also placed within the actions layer under hit detection setup. This generates balls but again only the first main ball works.

    If anybody could help me figure out why only 1 ball is being hit it would be muchly appreciated

    Cheers

    Cheers
    Attached Files Attached Files

  2. #2
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635
    You're only checking collision on one ball.
    Here's the fixed hit function:
    Code:
    function hitDetect() {
    	for (var c:Number = 0; c<25; c++) {
    		ball_mc = _root["ball_mc"+c];
    		var ballX:Number = (ball_mc._x-videoX)/sizeDif;
    		var ballY:Number = (ball_mc._y-videoY)/sizeDif;
    		now.draw(video_vobj);
    		// hit detection based on detecting colour red
    		ball_mc.valBefore = ball_mc.valNow;
    		ball_mc.valNow = (now.getPixel(ballX, ballY) >> 16 & 0xFF);
    		// if red is found then there is a 'hit'
    		if (ball_mc.valNow>ball_mc.valBefore+30 || ball_mc.valNow<ball_mc.valBefore-30) {
    			trace("hit");
    			if (ball_mc._currentframe == 1) {
    				ball_mc.gotoAndPlay(2);
    			}
    		}
    		before.draw(video_vobj);
    	}
    }
    Btw, I don't like your style of coding. I used to code like that, and now regret it. I prefer to put everything on a single actionsframe or inside classes, and I really don't like duplicate movie clip. The best method is attach movie clip.

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