Hit Tests & Collisions With As3 (maze)
Forum Geniuses.I'm working on this for some of my students to learn math, I'm a noob. Your help is beyond appreciated. (The resources currently available for as3 don't address my questions, and I'm stuck - please don't flame me!)I have a bee and a maze.I can control the bee with my keyboard.When the bee collides with the maze I don't want the bee to be able to move.I have it half-working.Here is the .fla - any help is appreciated.~la Swear
KirupaForum > Flash > ActionScript 3.0
Posted on: 10-04-2007, 01:20 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Hit Tests Please Help
I am making a game where i have balls firing and they are to bounce off everything in a movie clip called bg(for background. my hit Zones seem to work when the balls going going straight up or down, but not when hitting side walls, they just get sucked in to the side walls. i will leave the code for my hitzones....what is going on here? any ideas?
you can ignore the part about corner of a box.
if (_level0.bg.hitTest((_parent._x + this._x), (_parent._y + this._y), true)){
_parent.hit = true;
if(this._x == 0){
//bounce vertical
_parent._y = _parent.lastY;
_parent.Vy = -1 *_parent.bounceFactor * _parent.Vy
}
else if(this._y == 0){
//bounce horizontal
_parent._x = _parent.lastX;
_parent.Vx = -1 * _parent.bounceFactor * _parent.Vx
}
else{//this hitzone is on the corner of a box
//trace("corner");
_parent._y = _parent.lastY;
_parent.Vy = -1 *_parent.bounceFactor * _parent.Vy
}
}
else{
_parent.hit = false;
}
thanks, Jon
Better Hit Tests
Hey you must get this all the time, but i am making another game and i getting so anoyed with hit test. I am doing a hit test between two objects say circles. If the two circles are close 2 each other but not touching, in a postion as if they were squares of equal size they would be touching. and the hittest returns true. Is there anyway of getting round this? Is it possible to stop hittest from cutting corners???
[F8] Hit Tests :(
i was making a simple platform game, but i can get only as far as one platform. i just need to know if i should make another hit test, what it should say and where to put it
Hit Tests
I don't know how to use hit tests. Alright, I have a movie clip called Ball which moves around with the arrow keys. I drew a box around it and called the box Wall. How do i make it so that the ball can't go through the wall?
Hit Tests
I have been trying all day to get a hit test to work, without success. I have looked at the tutorials here and in several manuals I have at home. The beginner tutorial doesn't work in my movie and the Intermediate tutorial uses a separate clip for the action script.
I have two movie clips, one of which can be controlled onscreen using the direction keys. The second is static. Both instances are named. I have tried attaching code to the moving clip. I have tried attaching code to the static clip. I have tried appending code to the direction controls. I have tried adding a new layer for scripts. In other words, I am pretty well stuck!
An indication of the correct code, along with where to put it (!), would be fantastic.
Help please!
Hit Tests
Hi
I have a problem with hit tests, if you make a object that is any shape other then a square it createds a invisable square around it and uses the as the edge for hit tests. I have a ship you move around rounded astriods and i need it to be exactly where you see the edge, and not where the edge of the box is.
this is the code im using.
Thanks.
Attach Code
_root.spaceship_mc.onEnterFrame = function() {
if(this.hitTest(_root.astriods_mc)) {
gotoAndPlay("you lose", 1);
} else {
this.gotoAndStop(1);
}
};
Alpha Tests?
I have MX, and when I do an alpha tween, it will do the tween on the stage and when moving the head thru the timeline, although when i do a control > test Movie, my fades never show. Is there an option that that I have to hit in order to see these tween effects? Every other tween works fine, except for the alpha. Like I say its only when testing the movie. On the stage while draging thru the timeline it works fine.
xmaddness
Simple HIt Tests
Hi i have a simple game where a fly runs away from spiders and when they hit the spiders the score increases and a dynamic text field populates with bitten. However I am getting an expected "(" syntax error on line 15 / 17 cant work it out. If any1 could help it would be ace.
stop();
score = 0;
bitten.stop();
//
onEnterFrame = function () {
scoreText.text = score;
if (Score >= 50){
gotoAndStop("Scene3",3);
}
if (1.hitTest(_root.steve)) {
_root.Bite = "Bitten"
_root.score++;
} else {
_root.Bite = " "
}
if (2.hitTest(_root.steve)) {
_root.Bite = "Bitten"
_root.score++;
} else {
_root.Bite = " "
}
if (3.hitTest(_root.steve)) {
_root.Bite = "Bitten"
_root.score++;
} else {
_root.Bite = " "
}
if (4.hitTest(_root.steve)) {
_root.Bite = "Bitten"
_root.score++;
} else {
_root.Bite = " "
}
}
[F8 Pro] Problem With Hit Tests
Hi
I've made a horizontal bar that rotates at its center when the end is dragged up or down
on the bar is a ball and i want to make it so that the ball will try to move vertically downwards until it hits the bar at which point it stops
AND if the bar is rotated upwards the ball is pushed up and if the bar is rotated downwards the ball will move down with it
I'm having the following problems :
1) when the bar is rotated and is at an angle it becomes the diagonal of its bounding box - the ball hit test therefore returns true when the ball isn't even touching the bar
2) I can't figure out the best way of moving the ball along so that when the bar is rotated it always sits on the uppermost surface of the bar
I have attached a simple model as a fla (Flash 8 pro on PC) so that you can see how i'm doing it
i really want to code it so that the ball can drop from the top of the swf onto the bar and then slide down along the bar if the bar isn't horizontal
i have a feeling that i'm going about it all the wrong way and i would appreciate someone with more experience giving me some pointers on another way of approaching the problem
thanks
[CS3] Hit Tests Within A Fuunction
hello,
I am in a multimedia class where we make video games. so now i am making a 2 player tank game with an aerial perspective. I am using a "Master" function to make the tank move and fire around the level. Now the problem i am having is putting in the hit tests to stop movement in any direction. I have tried everything i can think of to make the hit tests i even tried another function within the "master" function, but flash said that their were to 256 recurrences and flash said it was a never ending loop and stopped all the action. here is the script i am using.
PHP Code:
function changeAngle(num) {
ship.angle += num;
ship.angleRad = ship.angle*Math.PI/180;
ship.cosAngle = Math.cos(ship.angleRad);
ship.sinAngle = Math.sin(ship.angleRad);
ship.x_inc = ship.speed*ship.cosAngle;
ship.y_inc = ship.speed*ship.sinAngle;
ship.clip._rotation = ship.angle;
}
function captureKeys() {
if (Key.isDown(Key.RIGHT)) {
changeAngle(5);
} else if (Key.isDown(Key.LEFT)) {
changeAngle(-5);
}
if (Key.isDown(Key.UP)) {
ship.xmov = ship.x_inc;;
ship.ymov = ship.y_inc;
} else if (Key.isDown(Key.DOWN)) {
ship.xmov *= decay;
ship.ymov *= decay;
}
if (Key.isDown(Key.SPACE) && okToShoot) {
okToShoot = false;
var newDepth = ++depth;
var name = "projectile"+newDepth;
var clip = _root.attachMovie("projectile", name, newDepth);
clip._x = ship.x;
clip._y = ship.y;
clip.xmov = speed*ship.cosAngle;
clip.ymov = speed*ship.sinAngle;
clip._rotation = ship.clip._rotation;
clip.onEnterFrame = function() {
this._x += this.xmov;
this._y += this.ymov;
};
} else if (!Key.isDown(Key.SPACE)){
okToShoot=true
}
}
function moveShip() {
ship.x += ship.xmov;
ship.y += ship.ymov;
ship.clip._x = ship.x;
ship.clip._y = ship.y;
}
_root.onEnterFrame = function() {
captureKeys();
moveShip();
};
ship = {};
ship.xmov = 0;
ship.ymov = 0;
ship.angle = 90;
ship.clip = ship_clip;
ship.speed = 3;
ship.x = ship.clip._x;
ship.y = ship.clip._y;
decay = .9;
depth = .1;
speed = .0000000000001;
changeAngle(0)
What ever input anyone can apply will be greatly appreciated
Thank You
Flash Tests
HI everybody,
I am not too new regarding flash, but at least new here so thank you in advance for your warm welcome!
I am looking for flash tests files, where I could basically evaluate my skills (something like beginner - intermediate - expert). Not really a tutorial, more a "can I do it" type of thing.
Thanks a lot in advance and see you soon around!
Penny1
Multiple Hit Tests
I currently have 10 hit tests in a row on the stage. How would I get a hit test to only initiate when the previous hit test has been hit?
So, for example I can’t hit the 2,3,4,5,6,7,8,9,10 hit tests, until the 1st hit test has been hit. And then the 2nd can't hit 3,4,5,6,7,8,9, 10 and so on...
Any ideas???
More Efficient Hit Tests?
I know i raised this issue before, but i didn't get any response, and i still need help with it.
I've been trying to make a few game things where it checks to see if objects have run into each other (as one does in games). However, i seem to always have to have lots of code running each time it enters a frame, which after a few objects appear, make everything slow down and lag lots. If anyone has some tips, it would be much appreciated.
Moving And Hit-tests
Yo,
I need a good way to make a movie clip move in directions when you press the arrow keys and a way to make him not run into walls (the walls will be another movie clip). Need some code and an exlplanation of it.
Preloading In Tests
I've been working on my own website and its going fine but there is one thing still bothering me. Why doesn't my preloader bar move? I have to right click and say "play" for it to advance. Is my preloader messed up or is that just how it is. By the way I have tried the simulate loading, but that didn't work either. Thanks for your time.
Ithaca
Multiple Hit Tests
I have this code that works for a normal hit test that triggers a mc animation in and out. But if i want to add more than one it just plays the last in the chain of events.
Code:
//Navigation
_root.finished = 100;
this.onEnterFrame = function() {
cursor._x = _root._xmouse;
cursor._y = _root._ymouse;
if (cursor.hitTest(nav1_mc) == true and _root.expand == false and _root.finished == 100) {
_root.finished = 0;
_root.expand = true;
_root.nav_mc.gotoAndPlay(2);
}
if (cursor.hitTest(nav1_mc) == false and _root.expand == true and _root.finished == 100) {
_root.finished = 0;
_root.expand = false;
_root.nav_mc.gotoAndPlay(11);
}
};
If anyone can let me know what i'm doing wrong that would be very helpful!
Faulty Hit Tests
here ive been making a little game (no way near finished) but for some reason doesnt like my hit testing half the time. It works more often at the start, but basicly ignors it all the other time. Heres the .fla, feel free to mess about with it, and if you fix it, tell me. Cheers! Btw, its on flash 8. Clik on the left grey block to generate a ball, and its ment to make a little smily face pop up when it hits the right grey block. stupid game.fla
Moving And Hit-tests
Yo,
I need a good way to make a movie clip move in directions when you press the arrow keys and a way to make him not run into walls (the walls will be another movie clip). Need some code and an exlplanation of it.
Preloading In Tests
I've been working on my own website and its going fine but there is one thing still bothering me. Why doesn't my preloader bar move? I have to right click and say "play" for it to advance. Is my preloader messed up or is that just how it is. By the way I have tried the simulate loading, but that didn't work either. Thanks for your time.
Ithaca
Still Some Flash 8 Tests
still testing some bitmap related things...
check them out
http://www.f-for-flash.com.hk/8ball_exp/
kit
Circles And Hit Tests.
Does anyone know of any good way you could do circle collisons with square movie clips? Hit test works sort of... It still lets the area outside the circle in, thus making for an inaccurate detection.
Overlapping Hit Tests
Hey guys, I just read a thread that asked some questions about a problem that I was having as well. But it appeared that he found the solution and unfortunately I couldn't follow the thread very well so I thought it would be best to post a new one.
Here's my layout:
sideMenu = instance of movieClip (menuBar)
|--> option a = instance of movieClip (menuButton)
. |-->BTN = instance of MovieClip (customButton)
. . |-->GLW = instance of MovieClip (button_glw)
. . . |--> simple shape animation
. . |--> LBL = instance of MovieClip (button_lbl)
. . . |--> NAME = instance of text field
. . |--> BG = instance of MoveClip (button_bg)
. . . |--> simple box with border
. . |--> SHD = instance of MovieClip (button_shd);
. . . |--> simple dropshadow shape
|--option b = same as option a...
|--option c ...
Now my logic was this: I created the (customButton) MC to include the logic states, "current" and "currentOver", so it has 5 frames instead of 3 (like a regular button).
buttonStates=["up","over","down","current", "currentOver"]
by creating aninstance of my (customButton) MC in another wrapper called (BTN) mc, I could then place my event handlers and onLoad handlers on the instance of (customButton)
Then I place several instances of the (BTN) MC on the stage, and turn this group into a symbol called "menuBar" and instantiated as "option a...". I plan to handle this all programmatically next, but not until I get past this hurdle.
FINALLY---the problem:
on the "OVER" frame from of the (customButton) mc, I have the drop shadow graphic in a MovieClip called button_shd and instantiated as SHD.
So I figured that when I told the (customButton) MC to swapDepths (overLevel), (where overLevel is defined to be a unique number smaller than any of the normal levels for (customButton) MC), it would put the entire clip above its peers. It does a great job of showing most of the (customButton) mc's pieces above the other (customButton) mcs. Unfortunately, it doesn't raise the dropShadow (SHD). It still appears below everything else.
I have tried placing a script on the (SHD) mc to tell it to set it's level to the highest level of all the MC's but no luck)
I am also having problems managing the overlap (so when the buttn is in state OVER, it gets bigger and overlaps other (customButton)mcs. So when I mouse over option b and then scoot up to where it overlaps option a, it blinks back and forth rapidly.
Is there a better way to do this? I have a tendency to make things much more complicated than need be. Any help, advice, direction, reference, empathy, etc. would be greatly appreciated.
Best wishes, thanks in advance for your help.
jase
Action Script Tests?
Is it possible, and if so how, to test for a sound being done. I am playing an MP3 on the intro to my site and would like to have It forward into the site on the end of the MP3.
Check it out here
http://www.swallowbush.tk
Hit Tests Only Partially Working...
This is in a sort of Arkanoid clone, but not exactly. You control the ball to move horizontally, however hitting a brick on the top or bottom SHOULD rotate the vertical direction but doesn't.
Right now I'm only trying to do the Y-axis Hit Tests. But it only sends the ball downward no matter what. It only recognizes hitting the bottom. I'm guessing it's only executing the second statement as it becomes satisfied. What can I do?
obj1_hwidth = (getProperty(_level0[Ball], _width)/2);
obj1_hheight = (getProperty(_level0[Ball], _height)/2);
obj2_hwidth = (getProperty(_level0[greyBrick], _width)/2);
obj2_hheight = (getProperty(_level0[greyBrick], _height)/2);
obj1_x1 = getProperty(_level0[Ball], _x)-obj1_hwidth;
obj1_x2 = Number(getProperty(_level0[Ball], _x))+Number(obj1_hwidth);
obj1_y1 = getProperty(_level0[Ball], _y)-obj1_hheight;
obj1_y2 = Number(getProperty(_level0[Ball], _y))+Number(obj1_hheight);
obj2_x1 = getProperty(_level0[greyBrick], _x)-obj2_hwidth;
obj2_x2 = Number(getProperty(_level0[greyBrick], _x))+Number(obj2_hwidth);
obj2_y1 = getProperty(_level0[greyBrick], _y)-obj2_hheight;
obj2_y2 = Number(getProperty(_level0[greyBrick], _y))+Number(obj2_hheight);
if ((Number(obj2_x1)<=Number(obj1_x2)) and (Number(obj2_x1)>=Number(obj1_x1))) {
Ball._x += 15;
}
if ((Number(obj2_x2)<=Number(obj1_x2)) and (Number(obj2_x2)>=Number(obj1_x1))) {
Ball._x -= 15;
}
if ((Number(obj2_y1)>=Number(obj1_y1)) and (Number(obj2_y1)<=Number(obj1_y2)))
{
VertMoveSpeed = -4;
}
if ((Number(obj2_y2)>=Number(obj1_y1)) and (Number(obj2_y2)<=Number(obj1_y2)))
{
VertMoveSpeed = 4;
}
Online Tests For Flash MX
I know some recruiters want to test designers on their knowledge of flash MX. Once such website is http://www.proveit.com/default.htm.
I would like to know if there are any free websites that offer such tests to test one's knowledge of flash and action scripting before taking such a test?
Thanks
[CS3] Changing Frames With Hit Tests.
How what is the AS2 code I need to do this?
I've tried the following:
onClipEvent(enterFrame){
if(this.hitTest(_root.otherObject)){
gotoAndStop(2); //Yes I know using the frame numbers is bad.
}
}
Creating Addition Tests
I am creating a test to see whether peple can do simple addition (IT coursework :[) The only way I can think of doing it is having 2 movie clips and have 50 frames and each frame sets the variable to the number that's shown. Then there is an input text box and then a button that checks to see whether the two variables added together equals the number in the input box.
Is this the best way to do it, and how do I make Flash go to a random frame in the two movie clips?
I'm also doing a subtraction and multiplication one, but the code would be similar, wouldn't it? (Something like If (Input== Number1 + Number 2){ Goto frame "correct" else goto frame "Wrong} (Not correct sytax or whatever, but something along those lines, I haven't used if statements for a while)
Selecting Arrayed MCs For Hit Tests
Hi,
I'm trying to make a bubble interface similar to Jonathan Harris' and Sep Kamvar's We Feel Fine. I've successfully got a dynamically generated number of
circular movie clips floating around the stage. Their instance names are stored in an array. They
are set to bounce around the stage indefinitely. Now I want to add some mouse interactivity. When
I use a for loop to access the clips through the array and perform a hit test, the test is sucessful,
but the resulting actions occur to all the bubble clips not just the one hit tested. Is there a way
perhaps using "this" to modify the behavior of just one bubble clip. Here is the code for the hit testing.
I apologize for the verbosity. I am still quite a novice and I'm sure there are more concise ways to
write all of this. Thanks for the help and time.
Attach Code
/* Frame One */
bVar = 0;
bBtn.onRelease = function() {
if (bubbleArray) {
for (i=0; i<_root.bubbleArray.length; i++) {
_root.bubbleArray[i].removeMovieClip();
}
}
bVar = track.text;
bubbulate(bVar);
bubbleMoveVar(true);
};
onEnterFrame = function () {
bubbleRoam();
bubbleBounce();
mouseAttract(true);
};
/* Frame Two*/
stageCenterX = Stage.width/2;
stageCenterY = Stage.height/2;
bubbulate = function (bNum) {
_root.bubbleArray = new Array();
for (i=0; i<bNum; i++) {
scale = random(60)+10;
_root.attachMovie("bubble","bubble"+i,i,{_y:stageCenterY, _x:stageCenterX});
_root.bubbleArray.push(_root['bubble'+i]);
_root.bubbleArray[i]._alpha = random(100)+45;
_root.bubbleArray[i]._xscale = scale;
_root.bubbleArray[i]._yscale = scale;
_root.bubbleArray[i].bXMove = 0;
_root.bubbleArray[i].bYMove = 0;
_root.bubbleArray[i].distanceX = Number;
_root.bubbleArray[i].distanceY = Number;
}
}
bubbleMoveVar = function (randomize) {
for (i=0; i<_root.bubbleArray.length; i++) {
if (randomize == true) {
_root.bubbleArray[i].bXMove = random(10)-5;
_root.bubbleArray[i].bYMove = random(10)-5;
if (_root.bubbleArray[i].bXMove == 0) {
_root.bubbleArray[i].bXMove = _root.bubbleArray[i].bXMove+10;
}
if (_root.bubbleArray[i].bYMove == 0) {
_root.bubbleArray[i].bYMove = _root.bubbleArray[i].bYMove+10;
}
} else {
moveX = random(10)+1;
moveY = random(10)+1;
_root.bubbleArray[i].bXMove = moveX;
_root.bubbleArray[i].bYMove = moveY;
}
}
};
bubbleRoam = function () {
for (i=0; i<_root.bubbleArray.length; i++) {
bubbleArray[i]._x = bubbleArray[i]._x+bubbleArray[i].bXMove;
bubbleArray[i]._y = bubbleArray[i]._y+bubbleArray[i].bYMove;
}
};
bubbleBounce = function () {
for (i=0; i<_root.bubbleArray.length; i++) {
if (_root.bubbleArray[i]._x>=550) {
_root.bubbleArray[i].bXMove = _root.bubbleArray[i].bXMove*-1;
}
if (_root.bubbleArray[i]._x<=0) {
_root.bubbleArray[i].bXMove = _root.bubbleArray[i].bXMove*-1;
}
if (_root.bubbleArray[i]._y>=400) {
_root.bubbleArray[i].bYMove = _root.bubbleArray[i].bYMove*-1;
}
if (_root.bubbleArray[i]._y<=0) {
_root.bubbleArray[i].bYMove = _root.bubbleArray[i].bYMove*-1;
}
}
};
detDistanceMouse = function (object1) {
for (i=0; i<_root.bubbleArray.length; i++) {
_root.bubbleArray[i].distanceX = object1._x-_root._xmouse;
if (_root.bubbleArray[i].distanceX<0) {
_root.bubbleArray[i].distanceX = _root.bubbleArray[i].distanceX*-1;
}
_root.bubbleArray[i].distanceY = object1._y-_root._ymouse;
if (_root.bubbleArray[i].distanceY<0) {
_root.bubbleArray[i].distanceY = _root.bubbleArray[i].distanceY*-1;
}
if (_root.bubbleArray[i].distanceY>5) {
_root.bubbleArray[i].bYMove = _root.bubbleArray[i].bYMove*-1;
}
if (_root.bubbleArray[i].distanceX>5) {
_root.bubbleArray[i].bXMove = _root.bubbleArray[i].bXMove*-1;
}
}
};
/* BEGIN INTERACTIVE FUNCTIONS */
mouseAttract = function (active) {
if (active == true) {
for (i=0; i<_root.bubbleArray.length; i++) {
if (_root.bubbleArray[i].hitTest(_root._xmouse, _root._ymouse)) {
detDistanceMouse(bubbleArray[i]);
}
}
}
};
...
Multi Collision Tests?
Lo everyone (esp Klaut in advance )
I know how to do a hit test for two known objects(or object and mouse), is there a bit of code for checking for collision for any object??
Zen
Need Free Online Flash Tests
Hi, guys!
I desperately need an online free test for flash skills but i could not find any I would be very grateful, if anyone could share some links.
Thanks in advance!
[F8] If Tests On Multiple Movie Clips
Hi,
i need an "if" statement where i can test that the x position of the movie clip is where it should be for 5 different movie clips.
if all x positions of the movie clips are correct then it will go to a certian frame otherwise will go to another frame.
The Five movie clips (red, green, orange, blue, yellow)
i tried this but didnt work
compbut.onRelease = function() {
if(red._x=522 && green._x=313.6 && yellow._x=344.95 && orange._x=484.7 && blue._x=410.1)
gotoAndStop("ballooncomp");
}else{
gotoAndStop("balloonfail");
}
Please help
love me xx
New Tweener Class Help With Tests And Bug Report
Hi!!
I developed a new tweener class with nice special FX support!
See some demos on http://thelaborat.org
On the "Projects" topic of the sidebar click on Light Transition to see some tutorials and download the source!
Help me in the project page in order to find bugs and improve the class even more!
Thanxs!!!
Problem With Multiple HitTestObject Tests.
I'm trying to make a simple dodge objects game, with a twist. You only die if you have a head-on collision with an object, and you can "grind" on the left and right sides of your cube for points.
Unfortunately, I've been struggling with this one bug for about 7 or more hours.
When I try to collide with two objects, where the one I should collide with is underneath, I just die. I have no explanation for it, other than it must be a problem with hitTestObject, but I hope this isn't the case, because I can't think of another way to really do it.
I don't think I could explain it by copying and pasting sections of code, so here's the source...
The FLA: http://file-flow.com/download.php?file=762545
I'd really appreciate any help/suggestions/thoughts, I'm fresh out of ideas
Speed Tests Using Image Bytearrays
This following information is very interesting and not at all what I would have expected.
The following tests were conducted to discover the fastest ways to load in a 1600x1600 px image from the library and alter each pixel color one at a time.
I have times each attempt 10 times and given an average below.
The head code is used to set up the test.
//HEAD CODE
var imgWidth:int = 1600;
var imgHeight:int = 1600;
var libraryImage:BitmapData = new libImg(imgWidth,imgHeight);
var rect:Rectangle = new Rectangle(0, 0, imgWidth,imgHeight);
var libImgByteArray:ByteArray = libraryImage.getPixels(rect)
var pixAlpha:int,pixRed:int,pixGreen:int,pixBlue:int;
//BODY CODE - TEST 1
libImgByteArray.position=0;
while(libImgByteArray.bytesAvailable>0)
{
pixAlpha = libImgByteArray.readByte();
pixRed = libImgByteArray.readByte();
pixGreen = libImgByteArray.readByte();
pixBlue = libImgByteArray.readByte();
}
//Timed results in milliseconds
TOTAL TIME: 12092ms Average:1209.2ms for 10 passes.
//BODY CODE - TEST 2
var pos:int=0;
var len:int=libImgByteArray.length;
while(1)
{
pixAlpha = libImgByteArray[pos];
pixRed = libImgByteArray[pos+1];
pixGreen = libImgByteArray[pos+2];
pixBlue = libImgByteArray[pos+3];
pos+=4;
if(pos==len)
{
break;
}
}
//Timed results in milliseconds
TOTAL TIME: 3828ms Average:382.8ms for 10 passes.
Now forgive me if I am wrong. But shouldn't the first example be faster? or at least just as fast? I would have thought so. Maybe I am missing something here. But most professionally written code I have seen will loop through a byteArray using the .position, .bytesAvailable and .readByte .readInt methods.
How can it be that using readByte is so much slower than accessing the array by direct index. What is the point of even using readByte at all if it is 4 times slower?
Is there a faster way I have not yet found. It seems strange to me that the inbuilt flash functionality such as floodFill and threshold would be required to test evey pixel.. yet those functions can do it in a very small fraction of the time it takes me to simply loop through and read each pixel colour. Is there a way I make this above code faster?
Hit Tests Responding To Movies In Buttons
Hi everyone!
I'm trying to make a little game in Flash 8 and I have two movie clips, one that moves left to right and another one inside a button. When the user clicks on the button or hovers over it, it plays a movie clip that is inside. I want the moving clip to 'die' when it reaches the hit area for the movie clip in the button but not when it hits the unclicked button.
So far, I can get the clip to 'die' when it hits the button itself, but not the clip.
So, can anyone help me? Thanks in Advance.
Sorry, if I accidently put this in the wrong forum, I hadn't noticed the Games section and then I wouldn't have known whether it would fall under commands in Flash 8 or games in general...
Flash App That Tests Connection Speed?
Greetings all...
I have seen a couple examples of companies that are using a Flash app to test the connection speed of cable modems, T1 lines, etc...
Do any of you have an idea of how this could be done? Any sites I can visit to see a tutorial of this created?
One example that I have seen is http://www.houston.rr.com/SpeedTest/speedTest.html
How is this built?
any insight would be greatly appreciated.
cheers,
~cs
Flash Video Comparison Tests
hi all.
i've just finished the first part of a compression comparison test on flash / sorenson standard squeeze
http://www.atomicshed.com/TOYBOX/flashvideo/
i'll be adding more tests when i get the compression suite - will be testing against the same file and will also be adding other types - talking head, slide show etc...
hope this is of use
john cooper
Removing Movie Clips And Hit Tests
We're currently working on a project in class doing a space invaders type of game.
We've gotten all the movement down more or less, we have the collision detection down, when we shoot the aliens the aliens dissapear, but for some reason when we try to make the bullet dissapear well nothing happens.
First we have the collision detection code on the aliens
ActionScript Code:
onClipEvent (load) {
hit = "no";
}
onClipEvent (enterFrame) {
if (_name != "mine") {
setProperty("", _x, this._x+speed);
h = 0;
while (++h<=_root.ship.missile_max) {
if (_root["missile_"+h].hitTest(this) && hit == "no") {
hit = "yes";
this.removeMovieClip();
}
}
}
}
that works to make the aliens dissapear. Now, we're not sure exactly where to place the code to make the bullet dissapear, we tried placing it with the above code, but nothing happened.
On the bullet/missle we have
ActionScript Code:
onClipEvent (load)
{
speed = 8;
}
onClipEvent (enterFrame)
{
if (_name != "missile")
{
setProperty("", _y, this._y - speed);
}
//if (_root["win_1_1"].hitTest(this))
//{
//this.removeMovieClip();
//}
}
some of it is blocked out, left over trial and error stuff we're still trying to figure out.
On the ship itself we have
ActionScript Code:
//this controls the ships tilting animation
onClipEvent (enterFrame){
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("left");
} else
if (Key.isDown(Key.RIGHT))
{ this.gotoAndStop("right");
} else
{ gotoAndStop("center");
}
}
//this controls the speed of side to side movement and fire speed
//also the direction the missile goes
onClipEvent (load) {
_root.score = 0;
speed = 8;
i = 1;
shots = 0;
_root.shots = 0;
missile_max = 3;
xmov = speed;
shoot = "yes";
}
//left and right movement
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x+=xmov;
} else if (Key.isDown(key.LEFT)) {
_x-=xmov;
}
//fire away, this is telling the thing to shoot
if (Key.isDown(key.SPACE))
{
if (shoot == "yes")
{
var missileNew:String = "missile_" + h;
_root.playSound("shoot")
shoot = "no";
duplicateMovieClip(_root.missile, "missile_" + i, i);
_root["missile_"+i]._x=_x;
_root["missile_"+i]._y=_y;
shots = ++shots;
i = ++i;
}
} else {
shoot = "yes";
}
if (i > missile_max) {
i = 1;
}
}
The above works fine as well. So any help on making the bullet/missile dissapear would be appreciated, also, where should we place it?
Thanks in advance
Removing Movie Clips And Hit Tests
I originally posted this on the newbie thread, got 10 reads, but no replies. I thought maybe since it was all actionscript I probably should've put it here, so here's my question from the newbie forum.
We're currently working on a project in class doing a space invaders type of game.
We've gotten all the movement down more or less, we have the collision detection down, when we shoot the aliens the aliens dissapear, but for some reason when we try to make the bullet dissapear well nothing happens.
First we have the collision detection code on the aliens
ActionScript Code:
onClipEvent (load) {
hit = "no";
}
onClipEvent (enterFrame) {
if (_name != "mine") {
setProperty("", _x, this._x+speed);
h = 0;
while (++h<=_root.ship.missile_max) {
if (_root["missile_"+h].hitTest(this) && hit == "no") {
hit = "yes";
this.removeMovieClip();
}
}
}
}
that works to make the aliens dissapear. Now, we're not sure exactly where to place the code to make the bullet dissapear, we tried placing it with the above code, but nothing happened.
On the bullet/missle we have
ActionScript Code:
onClipEvent (load)
{
speed = 8;
}
onClipEvent (enterFrame)
{
if (_name != "missile")
{
setProperty("", _y, this._y - speed);
}
//if (_root["win_1_1"].hitTest(this))
//{
//this.removeMovieClip();
//}
}
some of it is blocked out, left over trial and error stuff we're still trying to figure out.
On the ship itself we have
ActionScript Code:
//this controls the ships tilting animation
onClipEvent (enterFrame){
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("left");
} else
if (Key.isDown(Key.RIGHT))
{ this.gotoAndStop("right");
} else
{ gotoAndStop("center");
}
}
//this controls the speed of side to side movement and fire speed
//also the direction the missile goes
onClipEvent (load) {
_root.score = 0;
speed = 8;
i = 1;
shots = 0;
_root.shots = 0;
missile_max = 3;
xmov = speed;
shoot = "yes";
}
//left and right movement
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x+=xmov;
} else if (Key.isDown(key.LEFT)) {
_x-=xmov;
}
//fire away, this is telling the thing to shoot
if (Key.isDown(key.SPACE))
{
if (shoot == "yes")
{
var missileNew:String = "missile_" + h;
_root.playSound("shoot")
shoot = "no";
duplicateMovieClip(_root.missile, "missile_" + i, i);
_root["missile_"+i]._x=_x;
_root["missile_"+i]._y=_y;
shots = ++shots;
i = ++i;
}
} else {
shoot = "yes";
}
if (i > missile_max) {
i = 1;
}
}
The above works fine as well. So any help on making the bullet/missile dissapear would be appreciated, also, where should we place it?
I had to make a new post on that thread with some stuff I thought might be important, so here it is as well.
ActionScript Code:
soundOn = true;
function playSound(name)
{
if (soundOn)
{
soundFX.gotoAndPlay(name);
}
}
//variables
var invaderwidth:Number = 60;
var spacebetween:Number = 6;
var col_max:Number = 20;
var row_max:Number = 1;
var moveDown:Number = 40;
var enemyA:Array = new Array();
var enemyB:Array = new Array();
var enemyC:Array = new Array();
var enemyD:Array = new Array();
//make enemy rows
for(i = 0; i <= row_max; i++)
{
//make enemy coloumns
for(j = 0; j <= col_max; j++)
{
var name1:String = "iExplorer_"+i+"_"+j;
duplicateMovieClip ("iExplorer","iExplorer_"+i+"_"+j, _root.getNextHighestDepth());
this[name1]._x = 0;
this[name1]._x += invaderwidth + spacebetween * j * 4;
this[name1]._y = invaderwidth + spacebetween + moveDown;
enemyA[j] = eval(name1);
var name2:String = "trash_"+i+"_"+j;
duplicateMovieClip ("trash","trash_"+i+"_"+j, _root.getNextHighestDepth());
this[name2]._x = 0;
this[name2]._x += invaderwidth + spacebetween * j * 4;
this[name2]._y = invaderwidth + spacebetween + moveDown + 25;
enemyB[j] = eval(name2);
var name3:String = "mine_"+i+"_"+j;
duplicateMovieClip ("mine","mine_"+i+"_"+j, _root.getNextHighestDepth());
this[name3]._x = 0;
this[name3]._x += invaderwidth + spacebetween * j * 4;
this[name3]._y = invaderwidth + spacebetween + moveDown + 50;
enemyC[j] = eval(name3);
var name4:String = "win_"+i+"_"+j;
duplicateMovieClip ("win","win_"+i+"_"+j, _root.getNextHighestDepth());
this[name4]._x = 0;
this[name4]._x += invaderwidth + spacebetween * j * 4;
this[name4]._y = invaderwidth + spacebetween + moveDown + 75;
enemyD[j] = eval(name4);
}
}
//show border
var border:String = "border2";
_root.attachMovie("border1", "border2", _root.getNextHighestDepth());
this[border]._x = -22;
this[border]._y = -3;
//make bills head
var name5:String = "bill_";
duplicateMovieClip ("bill","bill_", 0);
this[name5]._y = 65;
/*for(a = 0; a <= 20; a++)
{
enemyD[a]._y = invaderwidth + spacebetween + moveDown + 100;
}*/
Some of this is blocked out as well, we're also working on way to make the aliens move down, but that's not as important at the moment.
The above part is on the timeline, not placed on any movieclips. Hope that makes sense.
Thanks in advance
Maze Help
im making a maze game for my computer science class and i cant seem to figure out how to fix this, when you walk into a wall it stops you (that works) but when i try and make it when you walk onto the teleporter for the next level it doesnt do anything. heres the code:
(just like to remind you that "Walls" is the instance name for the walls you cant go through and "teleporter" is the instance name for the teleporter(who would have guessed)
with (_parent) {
if (Key.isDown(Key.RIGHT)) {
_x += xStep;
} else if (Key.isDown(Key.LEFT)) {
_x -= xStep;
} else if (Key.isDown(Key.UP)) {
_y -= yStep;
_y -= yStep;
_y -= yStep;
} else if (Key.isDown(Key.DOWN)) {
_y += yStep;
_y += yStep;
_y += yStep;
}
//
// detect if edges of the player square
// are colliding with the maze walls
if (_root.Walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= xStep;
}
if (_root.Walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += xStep;
}
if (_root.Walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= yStep;
_y -= yStep;
_y -= yStep;
}
if (_root.Walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += yStep;
_y += yStep;
_y += yStep;
}
if (_root.teleporter.hitTest(getBounds(_root).xMax, _y, true)) {
nextScene();
}
if (_root.teleporter.hitTest(getBounds(_root).xMin, _y, true)) {
nextScene();
}
if (_root.teleporter.hitTest(_x, getBounds(_root).yMax, true)) {
nextScene();
}
if (_root.teleporter.hitTest(_x, getBounds(_root).yMin, true)) {
nextScene();
}
}
gotoAndPlay(2);
if you need any more info just ask
Maze
Hey, my brother is trying to make a maze with as3, but he is having a problem with the walls. How would you make it so that the circle can't go through them? He tried using movieclips with the same instance names in order to represent different sections of walls. An example of this would be all the left side walls named left_wall. This doesn't work however, the first left wall he comes to does stop but all the others he goes straight through. How would this be accomplished? Thanks in advance.
Stephen
A 3D Maze...
First fo all hello and great/usefull things You have here..
At my free time I`m working at a maze game (some kind of multiplayer).. The game won`t be fully in flash, but flash+php. Just two some should be done in flash
The flash thing I`ve already done is the prototype of the maze editor (The magenta one is the starting point (cannot be placed on the borders), the green one is the ending point(can be placed only on the borders). Press "meklēt ceļu" to find the path)
The other thing that has to be made in flash is the maze itself. By now I`m experimenting on myself with a raycasting method 3D maze (move with arrows, click F to see fps, 1-3 to change the quality and 5-9 to change the wall texture. The engine was made by Frederic Heintz). BUT it`s too slow and too low quality, so...
The question is - are there an other ways to make a 3D scene (vectors?) without the raycasting method (or make it more faster)? I really like this one and was wondering if someone knows how something like that could be done....
Maze - Help Please :D
Maze.
Well with the maze that comes in the Flash MX samples folder, ive done everything for the maze, but the player is not moving.
I know the opponent is a motion guide, but the player you control is not moving...
Actionscript is on the maze.
Maze
I have a maze game and want the user to move the object with mouse in the maze.
The object must not cross the walls of maze...
AS2 - Maze
Last edited by :)) : 2008-04-23 at 03:07.
Hi
check here plz: http://www.fredheintz.com/sitefred/main.html (click on maze button at left)
As you see you can download the fla too, but I want to have a button on the walls... and I tried but couldn't make it work...
questions:
1. how I can make this button to work... I think because it makes the all thing in pixel so it can only show the things and won't do the functionality... I'm not sure...
2. can I have a dynamic texts on the wals too... I made a dynamic text in the movieclip but its texts were not readable... can we do that some tricks or something...
3. how I can make it more smooth when we move... with ease or something??
Please clear me thanks
Regards,
Ali
[AS3] How To Perform Hit Tests With Irregular Shaped Objects?
Hello,
I'm attempting to develop a tower defense style game. I don't want the user to place towers on the path that the monsters walk on. So I have this line of code:
if(towerToBePlaced.hitTestObject(Game.main.path))
where towerToBePlaced is the tower movieclip I'm attempting to place (its position follows the cursor) and Game.main.path is a movieclip representing the path that the monsters use to walk on in the stage.
My problem is that the path is "L" shaped, but the hit test is returning true even when the tower is currently position in the upper right hand corner of the "L" (where it is just empty space)
Can anybody please tell me or point me to a tutorial that explains how I can more accurately perform the Hit Test?
Thanks very much and if you need any more information please ask.
Create Tests Using A Data File For Questions
Is it possible to pull questions from a data file into flash without having to create new frames for every question. This would be a multiple choice test. We currently hand type the questions into multiple frames and grade at the end.
Thanks
Edited: 03/15/2007 at 07:30:51 AM by Trainersteve
|