A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: refer to multiple MCs with one name?

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    9

    refer to multiple MCs with one name?

    Hi, I'm working on a platforming engine, and I have the same movieclip acting as different platforms. So far i'm able to get the character to jump, move and not fall through the ground. Now I'm wondering if there is any easy way to group together a bunch of movieclip instances and refer to them with one name? I dont believe this can be done with an array and then accessed with a hitTest.

    Because it would be incredibly sloppy for me to copy and paste the collision code for each and every platform, and problematic since the condition of gravity enacting is if (!_root.ground.hitTest(this._x,this._y,true))

    ground in this case is one of the movieclips acting as a platform.

    I tried making an array, called platforms, and changing my code to:
    for(i = 0;i < _root.platforms.length;i++){
    if (!_root.platforms[i].hitTest(this._x,this._y,true))


    but that didnt work at all.


    Any advice?

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I assume you are building a tile (isometric) layout for your character. I understand the need to minimize coding, but you should not treat each tile as one, you eliminate the pin-point references for your character. You can use an array, but instead of index number, use something like an associative array, this way you can identify the specific tile when you need it.

    Also when you perform your hitTest, can you do it from the character and pull the tile currently in contact. That would also help. Of course, I may not understand what you're asking, in that case, can you clarify?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    __________ ........................................__________
    |.p1..........|.......................................|.p2..........|
    |_________|.......................................|_________|
    ____________________________________
    .................................................. .......|
    .......................ground..................... ....|
    ___________________________________ |



    Okay, there is a basic premise of what i'm working with. It's a 2d sidescrolling platformer, so the ground, p1 and p2 are all platforms, the same movieclip, with different instance names. My code for gravity/collision of the player is:

    if (!_root.ground.hitTest(this._x,this._y,true)){
    gravity++;
    this._y += gravity;
    _root.vcollision._y += gravity;
    }
    else{
    gravity = 0;
    }
    while(_root.ground.hitTest(this._x,this._y-1,true)){
    this._y--;
    _root.vcollision._y--;
    }

    So basically, I would need to copy this stuff for each platform?

    EDIT: Of course I would have to change the condition entirely.

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    Anyone have any ideas? I'm still stumped about this one.

  5. #5
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Are your platforms instances of a class. That is where you can place the code, so you only have to create it once. Maybe I'm not understanding.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

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