-
pull-string in AS3?
What I want to create is a lightbulb, with a pull-string next to it. When you pull the string, the lightbulb turns on, and when you let go, the string bounces up and swings around, causing the lightbulb to swing slightly as well.
I tried to do this with prefabbed animations, but it just doesn't look right. I know i have to code it so a movie clip of a single dot spawns several instances of itself, and I can do that... but then I get lost.
I've looked everywhere for tutorials/references/or anything, but I'm coming up empty.
Could anyone help me?
-
Senior Member
tweenlite will probably let you animate the bulb on the x and the string on the y...checkout ease:Bounce:EaseIn
-
what about the string bending and curving? :/
it seems that's more suited for static objects
-
Untitled-1.fla
You could implement a spring system to do this. A spring system is basically a simple physics model suitable for simulating ropes, chains, cloth etc. There are tons of examples online describing how they work and how to implement one.
The simplest solution is to use a physics engine, such as http://www.fisixengine.com. Here's an demo, which contains something similar to what you describe: http://www.fisixengine.com/demos/mona1.html
-
easing and springing
What you are looking for is easing and springing. It is a bit of an advanced animation concept. But once you do it , it becomes second nature.
PHP Code:
//Simple spring, long form:
var ax:Number = (targetX - sprite.x) * spring;
var ay:Number = (targetY - sprite.y) * spring;
vx += ax;
vy += ay;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;
//Simple spring, abbreviated form:
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;
//Simple spring, short form:
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
sprite.x += (vx *= friction);
sprite.y += (vy *= friction);
you would want to connect these springs together to make a 'string' as in thread. use the code to draw lines to each other.
PHP Code:
graphics.clear();
graphics.lineStyle(1);
graphics.moveTo(ball0.x, ball0.y);
graphics.lineTo(ball1.x, ball1.y);
-
Thank you! xD
This is exactly what I needed!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|