Random width/height and proportions...

For questions about using Classic.

Post » Sat May 02, 2009 4:30 pm

I want to create copies of the same object with random sizes, but I don't want their proportions to be distorted.

I tried;


*set height*
35 + (random 20)

*set width*
40 + (random 20)


35 and 40 are the original dimensions. The problem is that unless both random numbers are the same the image either looks squished or stretched.

Is there a way to generate a random number and then add/subtract that number to another value?

(could it be done with global or private variables? that's the only way I imagine it would work but I'm not entirely sure how to do it in this case...)

-thanks!
B
4
S
2
G
4
Posts: 401
Reputation: 2,302

Post » Sat May 02, 2009 4:46 pm

You probably should use some basic math for this.

35/40 is 0.875... your ratio basically.

Then set sprite.width to 40 + random(X)
and in the following action you set sprite.height to sprite.width*0.875.

That should work. Remember you will not really get random sizes this way since you're only adding a random number to the size. You should use + random(X) - random(X) or something. Unless you want only bigger versions of course.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Sat May 02, 2009 4:48 pm

Thank you Pixel, I'll give that a try. 8)
B
4
S
2
G
4
Posts: 401
Reputation: 2,302

Post » Sat May 02, 2009 5:19 pm

(never mind... my project .cap is working perfectly now! :D )
B
4
S
2
G
4
Posts: 401
Reputation: 2,302


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests