To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Games

Reply
 
Thread Tools Search this Thread Display Modes
Old 03-25-2007, 03:27 PM   #1
hamandeggs
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
File Type: zip 1 ball working.zip (6.3 KB, 21 views)
hamandeggs is offline   Reply With Quote
Old 03-25-2007, 04:25 PM   #2
Xploder
CostomJunky
 
Xploder's Avatar
 
Join Date: Jun 2003
Location: Canada
Posts: 634
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.
__________________
Bearambo the Movie
Xploder is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Games

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:17 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.