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.

zoom_y and zoom_y Problem

Hi @all

I´ve a little Question about Sprites, and their zooming-type.

I know, a Sprites zooms with the counts 1.2 , 0.5 , 10.4 ...ETC

Now my Problem: With Pictures, i can zoom them in percentage ( from 1% to 100% ). That´s better for bars. The Percent Code is easy: f.e.
Code:
% = actor´s hp * 100 / actor´s hp_max

Ok.. But with Sprites, there´s a problem...
if i use this:
Code:
sprite.zoom_x = actor´s hp * 100 / actor´s hp_max
The Sprite has a size from 1.0 to 100.0

If i change it to:
Code:
sprite.zoom_x = ((actor´s hp * 100) / actor´s hp_max)/100
The Sprite is shown correct. But if i decrease the hp by 1. The Sprite is completely invisible.


The Question now:
How to zoom a sprites X and Y size by percentage?
 

khmp

Sponsor

The math you have is right. I know its just psuedo code in those tags, so you might be already doing this, but when you want the answer to be in the form of a floating point number its best to convert the right hand of the operation to a float.

sprite.zoom_x = ((actor.hp * 100.0) / actor.maxhp.to_f) / 100.0

The right hand of the operation must convert the number to a float otherwise you will mix up integer division with float division. If ((actor.hp * 100.0) / actor.maxhp.to_f) came out to anything less than 100 when you go to divide with the integer form of 100 you will get zero as an answer. Which is why the sprite disappears.

A quick test for this is to put these lines right above main:
Code:
p 99/100 # 0
p 99/100.0 # 0.99

Good luck with it Sir Lord Biowulve! :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