|
-
I don't know crap
[help] terrain hit
I'm trying to build a scrolling terrain with a hit test function but it won't work
code:
var tileW = 100;
function buildTerrain() {
_root.attachMovie("empty", "world", 1);
_root.world._y = 0;
_root.world._x = 0;
for (var i = 0; i<6; i++) {
var thename = "t_"+i;
_root.world.attachMovie("terrain", thename, i+1);
_root.world[thename]._y = 350;
_root.world[thename]._x = i*tileW;
var type = math.floor(math.random()*10);
_root.world[thename].gotoAndStop(type);
//trace(type);
_root.world[thename].onEnterFrame = function() {
this._x -= 5;
if (this._x<=-100) {
this._x += 600;
var type = math.floor(math.random()*10);
this.gotoAndStop(type);
}
};
}
}
buildTerrain();
_root.world.onEnterFrame=function(){
_root.world._x-=_root.world.speed
if (_root.world.hitTest(_root.chopper._x,_root.choppe r._y,true)){
_root.world.speed = 0 }}
where is my flaw at?
"http://www.geocities.com/hemightbecreative"
-
n00b
var type = math.floor(math.random()*10);
trace("type "+type);
I do stuff that does stuff...
J-Force
-
I don't know crap
That actually made a window open when I tested it that said output and generated a bunch of what seemed to be random numbers. that just kept generating
"http://www.geocities.com/hemightbecreative"
-
Originally posted by LeechmasterB
var type = math.floor(math.random()*10);
trace("type "+type);
the trace was showing you what "type" came out to be, you were asking for a random number, and so it was giving it to you.
-
I don't know crap
So do I need to change something or what?
"http://www.geocities.com/hemightbecreative"
-
n00b
_root.world._x-=_root.world.speed <--- ? => ;
I do stuff that does stuff...
J-Force
-
n00b
Okay:
math.random:
Method; returns n, where 0 <= n < 1.
(It returns a Integer (element of N)).
math.floor:
Method; returns the floor of the number or expression specified in the parameter x. The floor is the closest integer that is less than or equal to the specified number or expression.
(It floors a Double (element of Q) to an Integer (element of N)).
-> You have an Integer which is element of N which you convert again to an Integer element of N with exactly the same value!
+
code:
var tileW = 100;
function buildTerrain() {
_root.attachMovie("empty", "world", 1);
_root.world._y = 0;
_root.world._x = 0;
for (var i = 0; i<6; i++) {
var thename = "t_"+i;
_root.world.attachMovie("terrain", thename, i+1);
_root.world[thename]._y = 350;
_root.world[thename]._x = i*tileW;
var type = math.random()*10;
_root.world[thename].gotoAndStop(type);
//trace(type);
_root.world[thename].onEnterFrame = function() {
this._x -= 5;
if (this._x<=-100) {
this._x += 600;
var type = math.random()*10;
this.gotoAndStop(type);
}
};
}
}
buildTerrain();
_root.world.onEnterFrame = function() {
_root.world._x -= _root.world.speed;
if (_root.world.hitTest(_root.chopper._x, _root.chopper._y, true)) {
_root.world.speed = 0;
}
};
Last edited by LeechmasterB; 11-07-2004 at 12:34 PM.
I do stuff that does stuff...
J-Force
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
|