Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsHow to set random x or y position in as2?
for example from 200 to 250?
this._x = Math.random() * 610;
^ thats from zero... but i need from 600 to 610...
At 11/30/12 04:24 AM, TheSexualHero wrote: How to set random x or y position in as2?
for example from 200 to 250?
this._x = Math.random() * 610;
^ thats from zero... but i need from 600 to 610...
Isn't it kinda obvious? You need a random number between 0 and 10. But you want that to start from 600, what do you do?
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
Isn't it kinda obvious? You need a random number between 0 and 10. But you want that to start from 600, what do you do?
i need to write like this?
this._x = Math.random(600) * 610;
actually i need for my x coordinates to be from 600 to 610...
var rx:uint = 600 + Math.random() * 10;
Anybody with a brain can figure this out...
.
You can use the following algorithm to get numbers in a specific range:
function getRandomNum(min:Number, max:Number):Number
{
return Math.floor(Math.random() * (1 + (max - min))) + min;
}
So for example, you want a movie clip to spawn in x,y only in the visible screen with a stage size of 640 x 400 px:
var spawnx:int = getRandomNum(0, 640);
var spawny:int = getRandomNum(0, 400);
Hope it helps.
At 11/30/12 05:25 AM, 64base wrote: var rx:uint = 600 + Math.random() * 10;
AS2, not AS3.
_x = Math.random() * 10 + 600; Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
Free Web Traffic http://www.te4everyone.com/index.php?ref=50
At 11/30/12 10:41 AM, tonicipriani wrote: this._x = 600+(Math.random() * 10);
nuuu, don't use "this." - just "_x"
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P