Just made a simple helicopter game, but it won’t work online for some reason.
First up here is the collision code I’m using:
[SIZE="1"]/**
* GTween by Grant Skinner. Aug 1, 2005
* Visit www.gskinner.com/blog for documentation, updates and more free code.
*
*
* Copyright (c) 2005 Grant Skinner
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Rectangle;
class com.gskinner.sprites.CollisionDetection {
static public function checkForCollision(p_clip1:MovieClip,p_clip2:MovieClip,p_alphaTolerance:Number):Rectangle {
// set up default params:
if (p_alphaTolerance == undefined) { p_alphaTolerance = 255; }
// get bounds:
var bounds1:Object = p_clip1.getBounds(_root);
var bounds2:Object = p_clip2.getBounds(_root);
// rule out anything that we know can't collide:
if (((bounds1.xMax < bounds2.xMin) || (bounds2.xMax < bounds1.xMin)) || ((bounds1.yMax < bounds2.yMin) || (bounds2.yMax < bounds1.yMin)) ) {
return null;
}
// determine test area boundaries:
var bounds:Object = {};
bounds.xMin = Math.max(bounds1.xMin,bounds2.xMin);
bounds.xMax = Math.min(bounds1.xMax,bounds2.xMax);
bounds.yMin = Math.max(bounds1.yMin,bounds2.yMin);
bounds.yMax = Math.min(bounds1.yMax,bounds2.yMax);
// set up the image to use:
var img:BitmapData = new BitmapData(bounds.xMax-bounds.xMin,bounds.yMax-bounds.yMin,false);
// draw in the first image:
var mat:Matrix = p_clip1.transform.concatenatedMatrix;
mat.tx -= bounds.xMin;
mat.ty -= bounds.yMin;
img.draw(p_clip1,mat, new ColorTransform(1,1,1,1,255,-255,-255,p_alphaTolerance));
// overlay the second image:
mat = p_clip2.transform.concatenatedMatrix;
mat.tx -= bounds.xMin;
mat.ty -= bounds.yMin;
img.draw(p_clip2,mat, new ColorTransform(1,1,1,1,255,255,255,p_alphaTolerance),"difference");
// find the intersection:
var intersection:Rectangle = img.getColorBoundsRect(0xFFFFFFFF,0xFF00FFFF);
// if there is no intersection, return null:
if (intersection.width == 0) { return null; }
// adjust the intersection to account for the bounds:
intersection.x += bounds.xMin;
intersection.y += bounds.yMin;
return intersection;
}
}[/SIZE]
Now, the code I use in my flash:
stop();
import com.gskinner.sprites.CollisionDetection;
function onEnterFrame() {
if (CollisionDetection.checkForCollision(helicopter_mc,wall_mc,255)) {
_root.nextFrame();
}
}
This works fine both online and offline, but I’m using walls that I’ve manually created and have to be motion tweened. But the problem here is I wanted randomly generated walls. So I used this script to generate the wall_mc instead of manually making it.
var wallY:Number = 475;
createEmptyMovieClip("wall_mc", getNextHighestDepth());
for (i=0; i<999; i++) {
holder.attachMovie("walls", "wall"+i, i);
_root.wall_mc["wall"+i]._x = i*50;
_root.wall_mc["wall"+i]._y = wallY;
if (wallY>550) {
down = true;
}
if (wallY<400) {
down = false;
}
if (down) {
wallY -= Math.round(Math.random(1)*99+1);
} else {
wallY += Math.round(Math.random(1)*99+1);
}
};
and to move the wall to the left I added a simple:
wall_MC._x = wall_MC._x-10;
After adding the randomly generated walls code, I tested it and it worked fine. THEN, I uploaded it, and suddenly I test it on my server and it’s not working anymore?
I can’t understand what could possibly be wrong because there is no php/sql/asp or anything involved, the .swf file doesn’t have any online functionality like high scores or anything, it works fine offline.
If anyone has any suggestions as to why this would be happening it would be much appreciated.