# Grassy Field Scroll Question

**URL:** <https://forum.kirupa.com/t/grassy-field-scroll-question/8949>\
**Category:** flash\
**Created:** [December 1, 2002, 8:55pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949 "2002-12-01T20:55:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tripwire](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@tripwire](https://forum.kirupa.com/u/tripwire)\
**Post date:** [December 1, 2002, 8:55pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/1 "2002-12-01T20:55:46Z")

</div>

I was checking out Kirupa’s “grassy field concept” and have been trying to figure out how to enable the grass to move both to the left and right in response to the mouse. Currently it just scrolls to the left. Do I need to create an if statement which would tell it to scroll right or left depending on where the mouse is on the screen?

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 2, 2002, 6:58pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/2 "2002-12-02T18:58:58Z")

</div>

I haven’t seen the grassy thing you mention, but my instincts tell me that what you’ve done is put the registry point of your MC in one of the corners instead of in the center. So what’s happening is that no matter where your mouse is, its x coordinates are always positive (assuming your registry point is in top left corner) so the grass scrolls always in one direction.

That’s my guess anyway. If I come across the grass thing you’re talking about I’ll try to give you more solid help. 🙂

-Al

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 11:47am UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/3 "2002-12-03T11:47:07Z")

</div>

The idea behind the “grassy field concept” is to draw one blade of grass and then with actionscript duplicate that one blade numerous times randomly to create the illusion of a field. So we’re only really dealing with one blade of grass within a movie clip.

The problem I’m having is the moving and looping. I don’t think the position of the registry point would come into play here. The blade of grass is positioned at x: 0 anyway. Here is the code I’m using to move the grass.

onClipEvent (enterFrame) {  
x = (\_root.\_xmouse+50)/rxn;  
this.\_xscale = -x;  
this.\_x -= x/10;  
pos = this.\_x;  
if (pos\<-50) {  
this.\_x += Math.round(290+Math.random()\*100);  
}  
}

At the moment it will only scroll to the left and I need it to move both to the left and right in response to the mouse. Heres a link to the concept: [http://www.kirupa.com/developer/mx/grass.asp](http://www.kirupa.com/developer/mx/grass.asp) Any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 1:51pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/4 "2002-12-03T13:51:23Z")

</div>

Yep, it’s the registry point alright. In your code you have :

x = (\_root.\_xmouse+5/rxn;

First off, you didn’t close the parantheses. 🙂 Second, the property \_root.\_xmouse returns the x coordinate of the mouse in relation to \_root, or the stage in other words. The “registry point” of the stage (ok, I admit, the stage’s “registry point” is really just the origin) is the top left corner. This means that anything on the stage (including the mouse cursor) will have a positive x coordinate. That’s why the grass moves in only one direction. To fix this, you have several options, but this is the one I would use off the top of my head (Note: this will only work in MX.):

```auto

x = (_root._xmouse - (Stage.width/2) +5)/rxn;

```

The Stage.width part is not a variable you set, but a read-only property new to Flash MX. That means that even if you decide to change the width of the Flash movie, you won’t have to change this code.

If you have Flash 5, you could substitute a constant for Stage.width/2 (which is basically half the width of the stage).

This sorta “moves” the origin of the stage to the center, horizontally, for the purpose of tracking the mouse position for this grass thing. I put “moves” in quotations obviously because it doesn’t really move it, I hope you see.

Hope that helps! If you need any more info just ask.

-Al

**EDIT**  
Fixed speeling eerors. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 8:35pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/5 "2002-12-03T20:35:37Z")

</div>

COUGH…lostinbeta…COUGH

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 8:46pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/6 "2002-12-03T20:46:05Z")

</div>

You should really take something for that cough, Fez. It could lead to more serious health problems…

-Al

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 8:58pm UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/7 "2002-12-03T20:58:52Z")

</div>

lol… i was actually aiming for a sneezish cough but i couldnt exactly figure out what it was supposed to sound like. AHPHSH didnt look right to me

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 4, 2002, 6:09am UTC](https://forum.kirupa.com/t/grassy-field-scroll-question/8949/8 "2002-12-04T06:09:03Z")

</div>

Someone coughed for doctor lostinbeta?

Actually I have gotten this to work when I first saw it, but I don’t recommend it.

See, using his method, the motion is directed by the \_xmouse position, which is a number. Closer to the left side of the stage the number gets to be 0, so even when you get it to go the other way… it is so slow it is pointless to do that.

I couldn’t find a remedy for this BTW ☹

[SIZE=1]get it?.. remedy… doctor lostinbeta…LOL… ah nevermind[/SIZE]
