User Tag List

Results 1 to 8 of 8

Thread: Handling Multiple Instances of the Same Enemy Effeciently?

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module
    Megabeard's Avatar
    Join Date
    Sep 2015
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Handling Multiple Instances of the Same Enemy Effeciently?

    Hello, I'm having an issue in my game where I'd like to have randomly spawning enemies acting independent of each other. Normally, this isn't a problem. I can just spread a value or use the ForEach object. But in my case, I have two separate objects for the enemy: The enemy hit box, and the enemy sprite. I attach the enemy sprite to the invisible hit box as I feel it makes for better game play.

    My initial strategy was to spread values for both the sprite and the hit box's values "ID", but the problem with this came with events that came afterwards.

    It would go something like:

    ID of enemysprite = 0
    ID of enemy = 0
    > Set position of enemysprite to (0,0) enemy

    But I would have to do this for each number. At points in the game, there can be upwards of 20+ enemies on screen due to random generation. With the above method, animations in particular would be very cumbersome to add in. I figured there had to be some quicker way to do this, but everything I've tried so far hasn't worked.

    Here's what I tried:

    Always
    > Spread value 1 in ID for Enemy
    > Spread value 1 in ID for Enemysprite

    ID of "Enemy" = ID of "Enemysprite"
    > *Do animation stuff*

    This usually works briefly when an enemy is first spawned, but eventually the sprites stop following along with the enemy and the hit box goes rogue from the sprite. I end up with a bunch of spawned enemies moving independently of their sprites which should be following them. I am unsure if this is because I am constantly spreading values, but it seems to me like it starts out working and then for some reason fusion forgets that particular sprites and hit boxes are supposed to be paired together.

    I have also tried spreading values when the object and sprite are first randomly spawned. That didn't work either. I have tried ForEach as well, but that seems to only work on single objects unless I am missing something.

    The extra factor of making my sprites separate from the actual enemy hit box seems to be complicating things for me. Is there an efficient way I can handle multiple instances of the same randomly spawning enemy while maintaining sprites separate from their intended hit box?

    I appreciate any help that can be offered!

  2. #2
    Clicker Fusion 2.5 DeveloperiOS Export ModuleInstall Creator Pro
    Julian82's Avatar
    Join Date
    May 2012
    Location
    outbuddies.com
    Posts
    711
    Mentioned
    33 Post(s)
    Tagged
    0 Thread(s)
    I recommend leaving object pairings behind and using the embedded detector method instead. Saves a lot of headaches and is, in my experience, also better when it comes to performance. http://www.diybandits.com.au/MMF/tut...embedded1.html

    I also posted some more information about this method here, which may help next to the tutorial. https://community.clickteam.com/threads/102646-Can-not-make-quot-headshot-quot-function

  3. #3
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    zip2kx's Avatar
    Join Date
    Jun 2015
    Posts
    670
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Julian82 View Post
    I recommend leaving object pairings behind and using the embedded detector method instead. Saves a lot of headaches and is, in my experience, also better when it comes to performance. http://www.diybandits.com.au/MMF/tut...embedded1.html

    I also posted some more information about this method here, which may help next to the tutorial. https://community.clickteam.com/threads/102646-Can-not-make-quot-headshot-quot-function
    This is a good method, i just want to highlight that with the latest Fusion you have to click a setting in properties that makes fusion not reset the animation, "don't reset frame duration" is the name i think.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,150
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    Foreachs aren't necessarily bad performing,
    for 20 enemies it should hold with no problem even on mobile runtime

    i.e.

    (a foreach on all enemies at start of frame,
    and/or right on enemy creation if they are spawned)

    >>> create enemy (hitbox)
    >>> create sprite
    >>> set my_enemy("sprite") to Fixed("enemy")

    then, whenever you need to pair:

    (say, "always")
    >>> start loop foreach enemy

    on each enemy
    +my_enemy("sprite") = Fixed("enemy")
    >>> set position at 0,0 from enemy
    >>> set animation to animation("enemy")
    etc. etc.

    add every hitbox-to-sprite "sync" action here,
    so the sprite would "display" what the enemy hitbox does,
    and you shouldn't have any other hassle and just deal with the hitbox


    If object count really becomes a problem,
    consider you could invert the problem (move the sprite, use the hitbox only for collision detection)
    and thus use only 1 hitbox you would cycle through all enemies each frame
    (eventually changing its animation/scale depending on which enemy it refers to)

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module
    Megabeard's Avatar
    Join Date
    Sep 2015
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the responses guys! I am willing to try a new method, but first want to see if ForEach will work.

    @schrodinger I can almost get ForEach to work, but something is not quite synching up. In your example, am I creating ForEach instances in two separate names? Or is it all the same ForEach on the enemy object?

    I didn't mention this earlier, but enemies in this case would be spawning in different areas at random. So essentially what I do is set a random range for a value (1-4) and depending on what value comes out, the enemy would spawn at a certain "Waypoint" of sorts. This also happens once every second. I believe this is what is causing things to not synch up correctly. That, or I misunderstood your example.

    I am getting enemies to spawn and mostly stay where they're supposed to, but sometimes the enemy itself goes rogue and abandons the sprite for some reason. Animations also seem to not be matching up properly.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,150
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    made a very quick example:

    foreach_sync.mfa

    if you still have issues you can perhaps try to prepare a little .mfa we can check?

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module
    Megabeard's Avatar
    Join Date
    Sep 2015
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by schrodinger View Post
    made a very quick example:

    foreach_sync.mfa

    if you still have issues you can perhaps try to prepare a little .mfa we can check?
    This worked perfectly! Thank you!

    Turns out I was misunderstanding you. I thought you were referring to the ForEach object, but your method ended up working once I saw the example. Thanks again!

  8. #8
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    1,745
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Julian82 View Post
    I recommend leaving object pairings behind and using the embedded detector method instead. Saves a lot of headaches and is, in my experience, also better when it comes to performance. http://www.diybandits.com.au/MMF/tut...embedded1.html

    I also posted some more information about this method here, which may help next to the tutorial. https://community.clickteam.com/threads/102646-Can-not-make-quot-headshot-quot-function
    That diybandits example is great. For a little extra bit of performance, you could probably add an extra collision detector 'animation' that encompasses both wall detectors, but not the ground detector. Then you first test to see if this "allWalls" detector overlaps anything - if not, then you don't bother testing the left and right detectors. So, whereas the diybandit method tests 3 overlaps each frame (left, right, ground), this method would test 4 overlaps during a wall collision (allWalls, left, right, ground) but only 2 overlaps at all other times (allWalls, ground). For a flying enemy (or most enemies in a bird's-eye-view game) you could also incorporate the ground detector into the "allWalls" detector, which would result in only 1 overlap check on most frames (allWalls).

    I know you've already found your preferred solution, Megabeard - just thought I'd mention this anyway in case anyone's interested.

Similar Threads

  1. Using the Platform Movement Object for multiple instances of one enemy, help!
    By edman3d in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 29th August 2017, 12:46 PM
  2. Handling Multiple Channel Connections
    By netninja in forum Lacewing
    Replies: 2
    Last Post: 17th February 2010, 08:47 PM
  3. Handling the Hp of multiple opponents
    By Yima in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 9th November 2009, 08:36 PM
  4. multiple instances spawning at multiple places
    By CPW in forum Multimedia Fusion 2 - Technical Support
    Replies: 17
    Last Post: 22nd February 2009, 12:38 AM
  5. Handling Enemy Movements
    By Zenoff64 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 22nd August 2007, 01:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •