spawn vs alpha and un-spawn

chicopchicop Member Posts: 263
edited November -1 in Working with GS (Mac)
i was wondering, when you have an actor change alpha to 0 it appears its still in the scene(which makes sense), so if you know where it is you can click the actor without actually seeing it.

is spawning the only option to prevent this,say have a actor appear and disappear? and can you un-spawn an actor?

cheers!

Comments

  • 2D-Sprite-Box2D-Sprite-Box Member Posts: 72
    You can destroy the actor
  • synthesissynthesis Member Posts: 1,693
    You cannot "unspawn" and actor...but you can "destroy" it.

    However...If you want an actor to only function with alpha = 1...
    do this...

    Create an attribute (boolean) in the actor named "self.buttonActive" (or whatever)

    Then in the actor...have a rule that states:
    if self.alpha=1 >> then self.buttonActive = true
    otherwise >> self.buttonActive = false.

    Then put anything that you want to prevent operating inside a rule that states:

    Rule: when self.buttonActive = true
    ...[custom rules go here for when the actor is active]

    This is good practice for all actors that are complex. The activation attribute boolean will act similar to a light switch...so things will only happen when "the lights are on".

    Using this method will allow you to make the actor active or inactive for other reasons in addition to its alpha setting.
  • StusAppsStusApps Member, PRO Posts: 1,352
    up to you if you need it again.

    For me I would have the actors in the scene but with alpha set to 0. Make sure to have a rule that the actor can only be interacted with if alpha=1, put this in the rule for touch is pressed. Then if needed again just have the alpha go back to 0 until needed.
  • chicopchicop Member Posts: 263
    cheers guys

    i went with spawn for now.. some how i cant wrap my head around the other stuff just yet
  • synthesissynthesis Member Posts: 1,693
    @chicop
    I recommend you work to understand my methodology above. The switching principle will help you immensely in lots of other ways later in your game development process. Its not too complex once you understand it. Plus...its much more efficient on the device processing and more flexible than spawning.
  • chicopchicop Member Posts: 263
    could you give an actual step by step for this part:

    if self.alpha=1 >> then self.buttonActive = true
    otherwise >> self.buttonActive = false.

    like is it a rule within a rule or are these attribute changes?
  • synthesissynthesis Member Posts: 1,693
    What you wrote there is 1 rule behavior.

    RULE: When self.alpha = 1 (a test to see if the actor's alpha is on)
    ........ then .... change attribute self.buttonActive = true (make the button active)
    otherwise:
    ........ then .... change attribute self.buttonActive = false (make the button inactive)

    Then in a separate rule:
    RULE: When self.buttonActive = true (a test to see if the actor is active)
    ........ then .... [ do what you need to do inside this rule if the button is active ]

    That's it.

    The above 2 rules creates an activation switch. The first rule checks to see if the "lights are on" in the actor (the alpha). If they are...then the actor is "Activated".

    The second rule basically is a trigger rule that is executed when the actor is activated. Anything inside this rule will operate when the actor is activated...which according to our first rule...is when the alpha is = to 1. You can have other switches then if desired to make the actor active as well...
    example:

    RULE: When game.monkeysFly = true (a test to see if the monkeys are flying)
    ........ then .... change attribute self.buttonActive = true (make the button active)
    otherwise:
    ........ then .... change attribute self.buttonActive = false (make the button inactive)
Sign In or Register to comment.