How to have random background every game restart?

Dell7730Dell7730 Member, PRO Posts: 388

I would like to have a different static background every time we play the game, where it loads another image from a group of several images.

Best Answers

  • KevinCrossKevinCross London, UKPosts: 1,894
    edited June 2015 Accepted Answer

    Change Attribute: self.Image = "Background_"..random(1, 5)..".png"

    You'll have to forgive me as I can't remember how to write random in GameSalad as I'm at work, nowhere near GameSalad

    Make sure your images are saved with a unique number in the file name i.e:

    Background_1.png
    Background_2.png
    Background_3.png
    etc.

  • ApprowApprow Posts: 703
    Accepted Answer

    @Dell Agarpo Rename all your background imags to bg1, bg2, bg3 etc. Put a change attribute: self.Image = "bg"..random(1,3) that should do the trick:)

Answers

  • Dell7730Dell7730 Member, PRO Posts: 388

    @KevinCross said:
    Change Attribute: self.Image = "Background_"..random(1, 5)..".png"

    You'll have to forgive me as I can't remember how to write random in GameSalad as I'm at work, nowhere near GameSalad

    Make sure your images are saved with a unique number in the file name i.e:

    Background_1.png
    Background_2.png
    Background_3.png
    etc.

    Thanks, i'll give it a try and let you know

  • Dell7730Dell7730 Member, PRO Posts: 388

    @Approw said:
    @Dell Agarpo Rename all your background imags to bg1, bg2, bg3 etc. Put a change attribute: self.Image = "bg"..random(1,3) that should do the trick:)

    thanks, i'll try that also

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    @Approw said:
    @Dell Agarpo Rename all your background imags to bg1, bg2, bg3 etc. Put a change attribute: self.Image = "bg"..random(1,3) that should do the trick:)

    I think you need to put the file extension on the end.

  • ApprowApprow Member Posts: 703

    @KevinCross Nope its not necessary anymore. at least it always works for me;)

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    @Approw said:
    KevinCross Nope its not necessary anymore. at least it always works for me;)

    Ok cool :) it's been a while...

Sign In or Register to comment.