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.

Troops width & height

Hello.

I really need help! :please:
I want to calculate the width and height of a troop and also, if possible, calculate the x and y of this troop. Here's an exemple of what i mean.
http://img363.imageshack.us/img363/7397/troopwhyv2.jpg[/IMG]
The enemies selected in red are making one troop. As i mentioned above, i want to calculate the x,y,width and height of this selection but i have no idea on how to make it.

Help me please! :please:

-Dargor
 

Anonymous

Guest

Where are you doing it from?

At any rate, you can find the screen x and y of a battler in Game_Enemy. You can access them from $game_troops.enemies, which is an array, and the method names are #screen_x and #screen_y.

The height and width are a little trickier. While you can get them from Sprite_Battler from the bitmap property using #height and #width, the only class with access to Sprite_Battler objects is Spriteset_Battle. You'll need add a hook from Game_Enemy to its respective sprite, or to the height and width of that sprite. I'd do this in Spriteset_Battle, when the sprites are created. For example:

Code:
@enemy_sprites = []
    for enemy in $game_troop.enemies.reverse
      @enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
    end

to:

Code:
@enemy_sprites = []
    for enemy in $game_troop.enemies.reverse
     sprite = Sprite_Battler.new(@viewport1, enemy)
      @enemy_sprites.push(sprite)
      enemy.sprite_height = sprite.bitmap.height
      enemy.sprite_width = sprite.bitmap.width
    end

Where sprite_width and sprite_height are accessible attributes you added to Game_Enemy, like so:

Code:
attr_accessor :sprite_width
attr_accessor :sprite_height

Now you should have all the data to calculate the corners of the area from the Game_Enemy objects.
 
:D Wahaha! Nice, thanks a lot! It helps!

Thank you very much!

-Dargor

Edit:
I want this to place the troop in the center of the screen. (320 - troop_width/2 maybe?)

Edit 2:
Ok, I have resolved somethine like 1/4 of the problem.
Now i have to find the smallest and the highest value in an array.
Ex: prite_x = [10,7,4,8]
The smallest value should be sprite_x[2] and the highest value should be sprite_x[0] but i think there is no methode in Array that allow this.
 

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