Spawning actors with different attributes

dasincdasinc Member Posts: 5
edited January 2018 in Working with GS (PC)

G'day people, I have had a search but can't find the answer to this problem. I have an actor(ball) that when touched I want it to spawn other actors(balls) but smaller. I'd rather not have to have multiple different size balls and that seems a bit silly.

Is it possible to spawn the same actor type with different attributes?

Thanks in advance.

Comments

  • dasincdasinc Member Posts: 5

    I think I'll just have to make 3 different sized balls. Or I could just spawn them and change the size immediately, but I think you'd notice that.

  • IceboxIcebox Member Posts: 1,485

    When you spawn an actor , it gives you the option to control the Direction /rotation of the actor.

    You can spawn your actor and set the direction of the spawned actor to be random(1,3)

    if self.rotation = 1
    change color to blue
    change the rotation back to 0 ( this will change quick and you will not notice that the actor was rotated the second it was spawned)

    if self.rotation = 2
    change color to yellow
    change the rotation back to 0

    if self.rotation = 3
    change color to pink
    change the rotation back to 0

    You can extend this , so for example

    if self.rotation = 1
    change self.redball to true
    change image to red ball image
    change self.rotation to 0

    if self.redball is true
    { do whatever you want }

    Do the same for the other ball

    if self.rotation = 2
    change self.Greenball to true
    change image to green ball image
    change self.rotation to 0

    if self.Greenball is true
    { do whatever you want }

    I think adding seperate actors would be better , it will reduce complications in the long run.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You can also "pass" attribute values to spawned actors through the use of game attributes. These rules will spawn three balls of different sizes...

    In the spawner actor:

    Change attribute game.newSize to 80
    Spawn actor [ball]

    Change attribute game.newSize to 60
    Spawn actor [ball]

    Change attribute game.newSize to 40
    Spawn actor [ball]

    In the spawned [ball] actor:

    Change attribute self.size.Height to game.newSize
    Change attribute self.size.Width to game.newSize

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • IceboxIcebox Member Posts: 1,485
    edited January 2018

    If you want to spawn smaller sized balls you can also do this

    create a boolean self attribute name it parent set it to false

    if self.parent = false
    change self.size.width to random number
    change self.size.height to random number ( or width to maintain the same size )

    if touch is pressed spawn actor

    now place your actor on the scene , double click the actor in the scene , set its self.parent to true manually by ticking the boolean , so now its the parent and it wont be affected by the rule ( to change the size) , while the others will have self.parent set to false by default so they would change size randomly.

  • dasincdasinc Member Posts: 5

    Hey guys, sorry I never thanked you for your suggestions. I did have a play with what you said, and it works (as you knew it would:) but I had already set it up with the different sized balls. Decided since I will be using them elsewhere, it is just easier I think.
    Thanks again though, taught me to be a bit creative in my thinking.

Sign In or Register to comment.