Use percent in ImageSprite


#1

Hello,

First apologize for my English, I’m using the google translator.

I wanted to ask you about how to put the width and height of ImageSprite in percent.
I’m doing a piano and I’ve done it with canvas, but ImageSprite does not give me the option to use percent, just pixels.

Could it be done with percent?

Greetings.


#2

Well, the percent blocks are just a shortcut, It can totally be done by doing math.
Just multiply the canvas.width or height times the percent number you want divided by 100.

Example: If you want a sprite to use 30% of the canvas width, set the sprite width to (canvas.width * (30 /100) - or .3 whatever it’s easier for you to understand.


#3

Hello,
I have been trying as you said, although I have not understood it very well and I can not do it.

I have a Canvas and inside an ImageSprite, could you give me an example of the block to place that image on 30% of the canvas?

I’m very bad with this, I’m learning now.

Greetings.


#4

It’s just 3 blocks, literally:

Set ImageSprite.Width to Canvas.Width x 0.3

Replace 0.3 with whatever percentage you want there, like 45 % will be 0.45