Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Giving an object a random subimage?

Jason

Awesome Bro

So what I've got, is a sprite called ball with 5 subimages, and an event placed in a room.

The events sprite is set at ball, and obviously if I test play, it just sits there spasming out switching through the 5 subimages...

What I'm trying to do is make it so the event will use one of the subimages as the sprite, but I want it to select it at random, so for example, I could close and open the game a few times, and it would (Hopefully, based on chance lol...) show a different sprite subimage each time.

Does anyone have any ideas as to how I could do this? It'd be a great help and really add some variety to my levels.

Thanks, and if you need anymore info, feel free to ask.
 
What you might want to do is just have 5 different sprites. Then, when variable [blank] is equal to zero, the sprite changes into [sprite blank] and so on. The only issue is that I do not know how you would set a random variable. :c

I hope this is what you are asking, Im not entirely sure tbh.

you can also change the sub-image with that option as well, but I do not know if it would keep spazzing out or not.
 

Jason

Awesome Bro

Lol me neither, but for the time being I've got a temporary solution, although I can only use 4 sprites... I've used the Create Random action, and made 4 objects with the same parent, and different sprites.

I mean sure, it may not be convenient, but it works for now, lol...
 
You can simply do the following:

OBJECT- CREATE: Change sprite: Speed: 0 Image: random(5)

The five digit stands for your number of images in the sprite, INCLUDING the subimage 0 (zero). So you put your number of sumimages after the random text in the subimage box (loke int the exampel above!)

Another Example: I have 7 subimages and want it to randomize subimage: Change Sprite: Image: random(7).

Easy as that:)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top