PDA

View Full Version : Grassy Field Scroll Question



tripwire
December 1st, 2002, 03:55 PM
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

alethos
December 2nd, 2002, 01:58 PM
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

tripwire
December 3rd, 2002, 06:47 AM
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 Any suggestions?

alethos
December 3rd, 2002, 08:51 AM
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.

-Al

EDIT
Fixed speeling eerors. :)

fez
December 3rd, 2002, 03:35 PM
COUGH...lostinbeta...COUGH

alethos
December 3rd, 2002, 03:46 PM
You should really take something for that cough, Fez. It could lead to more serious health problems...

-Al

fez
December 3rd, 2002, 03:58 PM
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

lostinbeta
December 4th, 2002, 01:09 AM
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 :(

get it?... remedy... doctor lostinbeta...LOL... ah nevermind

Echo4Bravo
January 15th, 2004, 11:02 PM
OK I am really new to this but is there a way to make the base of the blades of grass fixed?
I have come to find that flash is not just the pretty pictures anymore..... LOL
Thanks in advance
E4B

GreenLantern
January 15th, 2004, 11:41 PM
in that "moving grass blade simulation" thing. If you will notice the single blade of grass that is actually being manipulated is drawn so that is slightly arced to the right like so "/" if you want the grass to move to the left you are going to have to arc it left "\" If you can see where i'm going with this, it could get really really complex. I would definitly like to see it, if you can make it happen. Good luck.