How to Creating multiple energy bar for the same actor that was spawn multiple times

bomaguiarbomaguiar Member Posts: 6
edited January 2012 in Working with GS (Mac)
Can you help me to find a way to display multiple energy bars on top of multiple moving actors.

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    did you open the Keyboard Entry Demo from GS … third Row in New ???

    3rd scene shows how to have a lifeBar above the actor …
    think making multipleInstances of that lifeBar … each constrained to an actor, might work for you

    @};- MH
  • bomaguiarbomaguiar Member Posts: 6
    The thing is that I'm re-spawning the same actor, like 10 times for example. So how can I tell which one is which and secondly do I need to create a constrained atribute for each of them?
  • MotherHooseMotherHoose Member Posts: 2,456
    edited January 2012
    okay see the problem … hopefully, see the solution

    on prototypeActor that you are spawning:
    add an attribute Index type … name: myLives … set to the number/amount of lives (5 ???)
    in behaviors
    Rule: when
    Event: collides
    --changeAttribute: self.myLives To: self.myLives-1

    Rule: when
    Attribute: self.myLives = 0
    --Destroy
    ====
    to tell which spawnedActor is which:
    gameAttribute Index type … spawnNumber = 0

    on Spawner:
    just before the spawn
    changeAttribute: game.spawnNumber To: game.spawnNumber+1
    then spawnBehavior

    on prototypeActor being spawned:
    another attribute Index type … my#
    behaviors: changeAttribute: self.my# To: game.spawnNumber

    @};- MH
  • bomaguiarbomaguiar Member Posts: 6
    Hi MH,

    Thank you for the help... Yes I was on the same way to figuring out which one is which, I just added an extra rule to avoid that the spawn number was set to all the actor by adding that spawn number need to be equal to zero be be change. This means that the actor spawn number will only be changed once.

    But still my problem is how to create multiple energy bar above the actor? do I need to create new constrain x and y for each of the spawn actors? I was thinking about the table to write the values there but this feature is still not available :S

    tks in advance for the help

    Pedro
  • MotherHooseMotherHoose Member Posts: 2,456
    perhaps also have a numbering system for the lifeBar? and spawning at the same time … and also changing that # in sync with the spawnNumber might help

    how many of the Actor's needing lifeBars do you intend to have on the screen at one time? 5? 10?

    please email me at gmail I will send you a demo …

    @};- MH
  • bomaguiarbomaguiar Member Posts: 6
    I just send you a private msg with my email!

    tks
  • MotherHooseMotherHoose Member Posts: 2,456
    sent!

    hope it helps

    @};- MH
  • bomaguiarbomaguiar Member Posts: 6
    Hi MH
    thank you so much for the help,
    Yesterday I found a different way to solve this problem, because may main propose was to try no to have to create 2 contrains for each new spawn actor, and have an automatic away.
    The question is and I hope you can help me is to figure out if the solution I found is the best in terms of performance?
    Just to give a bit of more information, I'm trying to do a kind of tower defense game, so I will need to have a lot of actor with energy bar in the game.

    For my solution was each time the actor was spawn we will spawn a new energy bar using the self x and y of the actor with a time rule to refresh every 0.01 sec.
    In the energy bar I just create a rule with time is it would destroy itself also every 0.01 sec.

    It works fine but if I add more then 6 actor the others actor in the game start to have a strange behavior, so the game starts to have performance issues :S

    What do you think? do you know which solution will be better?

    tks
    Pedro
  • MotherHooseMotherHoose Member Posts: 2,456
    Timers … numerous timers… really slow things down and mess-up firing calls …
    Especially Timers that are "Every:"

    So having 2 everyTimers on 6 Actors is 12/scene … set to fire a behavior every 0.01 seconds? …
    plus you have everyTimers on the spawners to re-spawn every 0.01 sec?

    think you have to reference/call your behavior actions differently …

    would like to look at your project file …

    @};- MH
  • bomaguiarbomaguiar Member Posts: 6
    Ok I will send you to your email!
Sign In or Register to comment.