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.

Multiple pictures

Code:
    for i in 0..9
      @sprite_block[i] = Sprite.new
      @sprite_block[i].bitmap = RPG::Cache.picture("block.png")
      @sprite_block[i].x = i * 64
      @sprite_block[i].y = 0
    end

I want to make copies of the same picture (32x64 pixels) then put them in diffrent positions. How would i go about doing that instead of creating a new block of code for each picture? The crappy code above should give you an idea of want i want to do if you dont know what i mean. Obviously it doesn't work.

Thanks in advance.:thumb:
 

khmp

Sponsor

As a forewarning, make sure that you dispose of those elements after you're done with them. To help generate random positions utilize the rand method built in to ruby. Not sure if that's all you wanted. Another warning though with the code below overlap may occur.

Code:
for i in 0..9
  @sp_block[i] = Sprite.new
  @sp_block[i].bitmap = RPG::Cache.picture("block.png")
  @sp_block[i].x = rand(640 -  @sp_block[i].bitmap.width)
  @sp_block[i].y = rand(480 -  @sp_block[i].bitmap.height)
end

Good luck with it Opt7ons! :thumb:
 

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