Actionscript MovieClip hitTesting - actionscript-3

So I am making a side scrolling platform game and I have a number of enemies on my stage. I have made separated classes for my each unique type of enemy. My issue is, in order to do scrolling, I have my player movie clip stay at the centre and have everything else move. I pushed my enemies into arrays by enemy type, I could loop through the arrays and move the enemies one by one. However that would be too much calculations to do on the computer, so I tried putting all my enemies inside one collective enemies movieclip so I can move the single movieclip. My issue is, when i have them out by themselves, they can do the hittest against my platform just fine, when I put them into a movieclip they are not able to detect the platforms. Can anyone tell me why is that so? Any help is greatly appreciated. If anyone need to see my codes please ask.
Thank you!

Related

ActionScript: Separating child from parent on Stage

I'm primarily a C++ programmer trying my hand at Flash and ActionScript3 for game development. I'm finding myself a little confused/constricted by the whole Parent/Child relationship, and was wondering if anybody here could give a little insight.
I'm currently making an Astro Panic clone, where each EnemyShip object also contains an array of EnemyShots. My problem is this: when one of the players' shots collides with an EnemyShip, the ship is supposed to disappear. However, at the moment, if the shot collides with one of a ship's shots, this also causes the entire corresponding EnemyShip (as well as all it's previous shots) to disappear. On top of that, it seems that the entire area between an EnemyShip and it's shot(s) trigger a collision. For example, in the following image, if the player's shot reaches anywhere within the red rectangle, the game will register it as the enemy having been hit:
Obviously I can't have this, but I'm unsure how to deal with it. Is there any way to separate child objects from parents on the stage, or is that just not how ActionScript works?
If I were you I would create a clip for all the shots. This means there would be 3 principal clips: the player, the enemies and the shots. This way you could achieve shot-ship and shot-shot interactions.
I hope this helps.
You should separate the model (Ships, Shots, Enemies) from their actual representation. Although a shot might be associated with a ship, the visual representations might share the same parent.
So basically I'm trying to say that you can flat the display hierarchy.

Actionscript 3 starling how to drag and only drop if it is over one of many squares

I am making a tower defense game for a class of mine. I decided to use starling with Flash and I am having a bit of trouble. Is there any was for me to specify that the towers can only be dropped into place if they are with in the bounds of a specific image/ in a 100px range of a specified center point? I would want to be able to store the points to be able to reference as I will have about 10-20 spots to place the towers. I feel like I might just be over thinking this.
Any help or guidance would be great.
Maybe you can try the hitTest method and add some dummies for locate the placing. If your hitTest method returns a dummy object you know that you are on a good place.
see Starling DisplayObject:hitTest();

AS3 for moving a movieclip along a path

I am looking for a simple AS3 script to move/follow a movieclip (arrrow) along a manually drawn path in flash. Like.. it moves for the start point if the line to the end point of the line, also should rotate at curves automatically.
Also is it possible to duplicate this movieclip (arrrow) tho specific distance, like a ground of arrows moving along a path continuously with specific distance from eachother?
I am working on few infoGraphs and need this arrows animation to show the workflow.
I desperately needs this, pls help!
Cheers,
bp
There could be libraries that help with this, as George Profenza mentions in his comment, and it is certainly possible to calculate points along a bezier.
However, a much simpler solution is to do what people have done since Flash 4. Draw the curve in Flash, then create a motion tween along the curve using an empty MovieClip. At runtime, you can use addChild() to insert your MovieClip as a child of the empty one. You will have a lot more manual control this way, compared to the bezier library.

Actionscript 3 I need someon to help me with Collision Detecting(hiTestObject)

I will try to explain the issue as good as possible.
What I want to do is to check for collision between to objects. Also the bullet and the enemy, if it was 1 of the bullet and 1 of the enemy it would be no problem, but after one day on google and tryed like every solutions I can't get it to work, or I find a solution that's absolutely terrible explained.
Im going to make it easyer. I have MainClass.as that document class.
It's one class for the Enemy and one for the Bullet. As I hope everyone understand I wan't to check if the bullet hit's the Enemy. Or the other way. Since the bullet's are been made while clicking for example it is not possible to direct refere to the bullet. What I have tryed is using sprite container, it does work if i place the bullet on the enemy just to check, but if I place one under and on over that's NOT hit the Enemy it's still says that the enemy got hit.
Note, the Enemy are dragged on stage, since im going to have multiple of them. I could also add them with code. Ive tryed to use Array to shuffle between all the enemys but I can't get it to work.
I know this was much text. Hope someon are willing to help me out, it is so frustrating...
Best regards HFherasen!:):)
Well, if you don't use a physics engine, like Box2DFlash, it can be frustrating.
First, you have to know the speed/frame of the bullet, because if it goes beyond the target in one frame, simple detection won't work.
Than, you should have a velocity and direction of the bullet.. For simplicity, lets use one point of it. (the head of the bullet, or the middle)
The bullet usually moves a lot faster than the targets, so you can assume the targets fixed.
The target is a rectangle, or polygon possibly rotated.
Now you have a target, and a line for the bullet (from the point and direction).
http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/
You can use this (converted to as3), with all sides of the target (or only the ones facing to a bullet), and if one matches, the shot will hit a target.
If your bullet is slower, you can have the position change of the frames as your first line. Than you'll know, when it hits a target. This is pretty fast, and works well. Hope it helped.

AS3 Simple AI, find player in viewfield?

Hey guys, I was looking into a simple flash game, and have a few enemies patrolling the area. I made each of them have a view angle of about 35 degrees, and a distance of 150 px. The problem is that they can see through walls. How would I check to see if a wall was in between the guard's view of the player?
I thought of ray tracing, but don't know a way to implement it. I also thought of maybe drawing a rectangle between the player and the guard, and collision check it against the walls, but again don't know how to implement it..
Any ideas?
Thanks,
Max
Just a thought.
Keep your code just as it is, but do a second test.
If it finds a target with your current code run another test to see if there is a wall between them with a ray type test.
This would keep your working code as it is and minimize the field for ray testingto the width of the target.
I think that you are not that far off.
Since your walls will probably be sprites or some other display object, you know their positions ect.
Then you could draw an opaque sprite with alpha 0 that embodies your enemy viewing range and then do a collision test on all walls and all viewing ranges.
This will also enable you to do a collision detection between the player and all enemy viewing ranges.
After a quick search this might be what you need
Cheers