Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-10-2011, 02:16 AM   #1
sbrd122
Registered User
 
Join Date: Nov 2010
Posts: 11
Default [AS3] Having trouble with bullets and enemies

Hello, I was wondering if any of you could clear up a really big confusion I'm having. I simply want to have a player be able to shoot bullets at randomly spawning enemies. I havent been able to do this in days, so I'm finally asking for help.

Everything occurs in my .as file called PlayScreen. PlayScreen creates the player, asteroids, and bullets. My first approach was to create two Arrays in PlayScreen, one for bullets and one for enemies. Then addChild(enemy) and add the enemy object to the Array. Same with the bullets for when you shoot. But I wasn't able to get the hitTesting right, I kept getting errors and didn't understand how to tell a certain asteroid to explode when it gets hit by the bullet.
My second approach was to create a bulletContainer movieclip class in PlayScreen, and do bulletContainer.addChild(bullet), while having enemies appear in PlayScreen. But it seems I'd have to go into the enemy class and try to hitTest it againt the bulletContainer, but I don't understand how to access the bulletContainer class from the enemy class. I thought making it public static var would work, but it doesn't.

How do you access non-static variables in one class from other classes?
sbrd122 is offline   Reply With Quote
Old 11-10-2011, 06:21 AM   #2
groeterud
Go ahead and ask.. DO EET
 
Join Date: Apr 2011
Location: Norway
Posts: 99
Default

you set up inheritage.

For instance:

Public class 50cal extends bullet

this means that a 50caliber bullet is still a bullet, but not all bullets are 50cal.

Only 50cal spesific variables and functions are stored in 50cal whilsts all common variables and functions are stored in bullet.

Hope this helped.
groeterud is offline   Reply With Quote
Old 11-10-2011, 02:39 PM   #3
sbrd122
Registered User
 
Join Date: Nov 2010
Posts: 11
Default

Well there's still the problem of how to hitTest against an enemy from within the bullet OR the 50cal class. It wouldn't make sense to make those children of the main PlayScreen class right?

I'm sure it's something very simple that I'm confused about.
sbrd122 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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. The time now is 01:23 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.