|
Author |
Topic: floating scroller, Any suggestions? (Read 1014 times) |
|
Ibex
|
floating scroller, Any suggestions?
« on: Dec 4th, 2004, 5:28pm » |
|
Hey im trying to set up images that float left and right depending on the x, y location of the mouse. The images are seperate variables but are aligned side by side. There isn't enough room in the applet for all the images so i will add images to in the row but want to make it so that they scroll to the left if the mouse is further to the right so that the images off the screen will slide into view. Im trying to do this without a mousepressed function because i need to reserve that for something else. Im figuring the code should be written something like: if(mouseX is greater than 300){ Xposition = Xposition +1;} Or something like that. Any suggestions?
|
|
|
|
Ibex
|
Re: floating scroller, Any suggestions?
« Reply #1 on: Dec 4th, 2004, 7:45pm » |
|
nevermind the basix - i figured that much out... i programmed a basic shift of variables; xspeed, xposition, and xdirection with regards to the position of the mouse on the x axis. It shifts left to right at a static speed. Though i'd like to add an increase in speed connected to position of the mouse but nothing seems to happen when i change the speed variable. My test image only increases in speed when i change the value of the position variable(xpos). I'd like to make the rolling of the images more smooth. Any way to have the rolling of the images increase and decrease in speed with regards to mouse location? Like the further the mouse is to the right, the faster it rolls to the left and the further the mouse is to the left, the faster the images roll to the right. Im thinking its probably a simple equation that my lack of math practice wont afford me. Any refs, ideas, or prior experience? Ibex
|
|
|
|
st33d
|
Re: floating scroller, Any suggestions?
« Reply #2 on: Dec 10th, 2004, 9:42pm » |
|
http://processing.org/learning/examples/animated_sprite.html I've butchered the above code trying to explain to capeta how to lay a rotating image on a background. So here's round two of the butcher especially for you. The example above already features the accelerating drag. Using a .gif that is 20,20 pixels I've created a spinnning example for you. Code: Sprite one; float theta = 0; float drag = 30.0; float xpos; void setup(){ size(400,400); background(0,255,0); one = new Sprite("1.gif"); smooth(); framerate(24); } void loop(){ background(0,255,0); push(); float difx = mouseX - xpos; println("difx:"+difx+" xpos:"+xpos+" mouseX:"+mouseX); if(abs(difx) > 1.0) { xpos = xpos + difx/drag; xpos = constrain(xpos, 0, width-20); } translate(xpos,100); theta = (theta+0.1)%360; rotate(theta); one.display(-10,-10); pop(); } class Sprite{ BImage i; Sprite(String imageName){ loadImages(imageName); } void loadImages(String name){ i = loadImage(name); } void display(float xpos, float ypos){ image(i, xpos, ypos); } } |
| I've basically just streamlined the above code for images only. I hope it's of use.
|
I could murder a pint.
|
|
|
|