A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [help] terrain hit

  1. #1
    I don't know crap mightbecreative's Avatar
    Join Date
    Oct 2004
    Location
    Out of my mind
    Posts
    172

    [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"

  2. #2
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    var type = math.floor(math.random()*10);
    trace("type "+type);
    I do stuff that does stuff...

    J-Force

  3. #3
    I don't know crap mightbecreative's Avatar
    Join Date
    Oct 2004
    Location
    Out of my mind
    Posts
    172
    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"

  4. #4
    Senior Member
    Join Date
    Jul 2004
    Posts
    140
    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.

  5. #5
    I don't know crap mightbecreative's Avatar
    Join Date
    Oct 2004
    Location
    Out of my mind
    Posts
    172
    So do I need to change something or what?
    "http://www.geocities.com/hemightbecreative"

  6. #6
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    _root.world._x-=_root.world.speed <--- ? => ;
    I do stuff that does stuff...

    J-Force

  7. #7
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center