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?
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.
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.
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 Any suggestions?
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.):
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.
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]