random size, keep proportions

For questions about using Classic.

Post » Fri Jun 08, 2012 12:58 pm

hi guys!

i have a feeling this is a complete noob question, but i really didnt find anything about it:

i want to create object randomly on a layer, this works fine enough, no problems.
but i also want to randomly set the size of the object while keeping its proportions. now, i cant find a simple set size action anywhere, i can only find set width and set height, but if i try to randomly set those upon creation, it doesnt keep the sprites proportions, instead, it can make for example width 50pixels, height 90pixels. and id want to keep them both the same amount. is there any simple enough solution i just cant figure out, being noob and all?

also, to make things more interesting, how can i make a random value between two values?
for example if i want to give a sprite a random size between the sizes 50pixels and 90pixels?

small bonus question:

ive been tinkering around with physics hinges, and already made some pretty neat stuff with it, but i still cant figure the basic logic behind hinges.
for example, if i create hinge from sprite a to sprite b, how can i make it so that the sprite b is also stiff? meanin that it would keep the angle relative to what it is upon creating hinge?
do i have to make hinges for both, sprite a and b?
thats all right, but it could get rather tedious when doing alot of hinges together.

little example:

if you make a car, 3 parts:
one body, two wheels. you have to make hinges FROM the body to the wheels, and that kind of confuses me. somehow i think it would be the complete opposite.

the mass is also something that puzzles me. if i made a say, simple ragdoll, with torso having the biggest mass, so i could apply force to hands, without it affecting the movement of the torso too much, what happens is that when moving the torso, the limbs that have smaller mass start to sort of act erratic, the hinges wont keep their position locked and they act "rubbery" even though having 100 stiffness.

anyone care to educate me?
Posts: 12
Reputation: 399

Post » Fri Jun 08, 2012 3:08 pm

A simple solution for your proportion problem would be to only make either the width or the height random and not both. For example, if the original sprite is 50px wide and 30px high you can make the width random and then make the height equal to Sprite.Width*0.6 This will keep it proportional.Gelidaer2012-06-08 15:20:13
Posts: 63
Reputation: 1,170

Post » Sat Jun 09, 2012 1:41 am

[QUOTE=frogbull]also, to make things more interesting, how can i make a random value between two values?
for example if i want to give a sprite a random size between the sizes 50pixels and 90pixels?[/QUOTE] Just add the offset to random() and use the range+1 in random. For example:
50 + random(41) => creates a random number in range [50, 90]
23 + random(101) => creates a random number in range [23, 123]
Posts: 1,822
Reputation: 8,291

Post » Sat Jun 09, 2012 9:17 pm

set Var = Sprite.X / Sprite.Y (so you have proportions now)
Sprite.X = Random(whatyouprefer) + minimumwidth
Sprite.Width / Var
This will keep it proportional.

Can be a bit wrong (but i dont think so), anyway you've got the ideaNugMan2012-06-09 21:19:13
Posts: 171
Reputation: 2,512

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests