|
-
XRave
[F8] Operation: Random background?
How can a random background function be made?
I mean Im trying - very hard - to make a game like the game "Tanks", currently Im stuck with programming on the background generating.
By that I mean EASY ways to generate random backgrounds which 'ent too impossible.
Now I dont want to generate the Y position for 400 movieclips (1pixel wide) and then getting the proximity and recheck, reposition. Thank you
THx for any help I could get.
<Tongxn>
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
-
heh i dont know that there is a way to randomly generate a background easily.
however you could have an array of several different backgrounds and pick one to use at random.
-
XRave
thx but that's blunt work.
Something else?
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
-
what do you mean blunt work?
-
XRave
well you need to create more than 1000 of those and make AS for them all...
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
-
Senior Member
what do you mean a random bg? i can make you a script for a randomly generated "hilly" bg is that what you mean?
-
XRave
yes please!
p.s.to.everybody. I needed it vectored though, for there could be movieclips that are running on the background.. or do I? Im nonpussed this is something I never attempted before.
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
-
Senior Member
here you go:
Code:
function createBackGround(fc:Number, bc:Number, height:Number, hillSizeRange:Number, hillsAmount:Number):MovieClip {
var cont:MovieClip = _root.createEmptyMovieClip("cont", -10000);
var backGround:MovieClip = cont.createEmptyMovieClip("backGround", 0);
var foreGround:MovieClip = cont.createEmptyMovieClip("foreGround", 1);
var ran:Number = Math.round(Math.random()*100);
var xInc:Number = Stage.width/(hillsAmount*2);
var points:Array = new Array();
for (var z = 0; z<=Stage.width; z += xInc) {
var randH:Number = Math.round(-hillSizeRange+Math.random()*(hillSizeRange*2));
points.push({x:z, y:height+randH});
}
with (backGround) {
beginFill(bc, 100);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
with (foreGround) {
beginFill(fc, 100);
moveTo(0, height);
for (var z = 0; z<points.length-1; z++) {
curveTo(points[z].x, points[z].y, (points[z].x+points[z+1].x)/2, (points[z].y+points[z+1].y)/2);
}
curveTo(points[points.length-1].x, points[points.length-1].y, Stage.width, height);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, height);
endFill();
}
return cont;
}
createBackGround(0x00ff00, 0x0066FF, Stage.height/2, 50, 5);
function parameters are as follows:
fc = foreground colour
bc = background colour
height = the "average" height of the hills
hillSizeRange = the max value the that hills' size varies
hillsAmount = the number of hills to be made
HTH,
zlatan
what you can do, as my function returns a container clip in which the background is contained, is you can draw the BG to a bitmapData, then you can incorporate the BitmapData.hitTest(); method to add the "movie clip running on the BG" functionality you speak of.
-
XRave
interesting.. but wont the hitTest recongnise the BG as a rectangle instead of a ..er.. what Im looking for? coz I need to randomly generate cannons that are exactly ON the background no more no less space in between, by which I meant knowing exactly where is the background and what Y position is the right position on a random X position.
Thanks that looked complicated yet it make sense, or atleast the easy bit to me.
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
-
Senior Member
the "ground" clip is just nested in the returned clip, so if you want to check for a conventional hitTest then just target createBackGround().foreGround;
if you are going to use bitmapData hittest then it will be fine as it works buy checking colour values, check out flash's help files.
zlatan
-
XRave
very interesting....
Thanks dudeqwerty!
When you actually know what "OMG I have so much homework!" means, you won't want to be me.
Xrave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|