Be a Supporter!

Help please!

  • 229 Views
  • 8 Replies
New Topic Respond to this Topic
TheSexualHero
TheSexualHero
  • Member since: Oct. 18, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Help please! 2012-11-30 04:24:58 Reply

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...

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Help please! 2012-11-30 04:47:04 Reply

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.

TheSexualHero
TheSexualHero
  • Member since: Oct. 18, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Help please! 2012-11-30 05:06:52 Reply


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;

TheSexualHero
TheSexualHero
  • Member since: Oct. 18, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Help please! 2012-11-30 05:10:37 Reply

actually i need for my x coordinates to be from 600 to 610...

64base
64base
  • Member since: Apr. 18, 2012
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to Help please! 2012-11-30 05:25:59 Reply

var rx:uint = 600 + Math.random() * 10;

Anybody with a brain can figure this out...


.

Spysociety
Spysociety
  • Member since: Dec. 30, 2009
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to Help please! 2012-11-30 06:59:26 Reply

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.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Help please! 2012-11-30 10:11:48 Reply

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

BBS Signature
tonicipriani
tonicipriani
  • Member since: Feb. 18, 2011
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Help please! 2012-11-30 10:41:08 Reply

this._x = 600+(Math.random() * 10);

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Help please! 2012-11-30 10:46:20 Reply

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

BBS Signature