View Full Version : need bubbles be fart by crab
OrcusDei
December 30th, 2007, 06:42 AM
Hello, here is my question, i have bubbles coming out when spacebar is pressed and crab instructed to follow my mouse. I want these bubbles be "farted" by crab, so to be connected to his position.
i tried this:
_root["bubbleTOP1" + i]._x = _root.KANITOP._x;
_root["bubbleTOP1" + i]._y = _root.KANITOP._y;but it only connects bubbles at the begining.
Please help me to solve this, im very beginner with AC and im confused:asian:
EDIT01: ehm, and i forgot, KANITOP is instance name of crab and bubbleTOP1 is identifier of bubble because i attaching it from library
OrcusDei
January 1st, 2008, 03:16 PM
anyone? nobody knows the right answer for this riddle?
ok, here is some AS2
on first frame of the main timeline:
var i = 0;
this.onEnterFrame = function()
{
if (Key.isDown(Key.SPACE))
{
i++;
_root.attachMovie("bubbleTOP1", "bubbleTOP1" + i, _root.getNextHighestDepth());
_root["bubbleTOP1" + i]._x = KANITOP._x + 3;
_root["bubbleTOP1" + i]._y = KANITOP._y;
}
}
within the crab MC
onClipEvent (load) {
speed = 5
}
onClipEvent (enterFrame) {
// the difference of the current position with the mouse
dx = _parent._xmouse-_x;
dy = _parent._ymouse-_y;
// angle with respect to mouse (radians)
angle = Math.atan2(dy, dx);
// distance from mouse
distance = Math.sqrt(dx*dx+dy*dy);
// set rotation to angle converted to degrees
_rotation = angle*180/Math.PI;
// move if the distance is more than speed
if (speed<distance) {
// cos and sin used to move based on angle and speed
_x += Math.cos(angle)*speed;
_y += Math.sin(angle)*speed;
}
//ifiky
if (speed<distance+1) {
_x += Math.cos(angle)*speed+3;
_y += Math.sin(angle)*speed+3;
}
if (speed<distance-1) {
_x -= Math.cos(angle)*speed+3;
_y -= Math.sin(angle)*speed+3;
}
if (speed+1<distance) {
_x += Math.cos(angle)*speed+1;
_y += Math.sin(angle)*speed+5;
}
} within the bubble MC
onClipEvent (load) {
this._xscale = this._yscale = Math.random() * 200 + 10
xSpeed = Math.random() * 6 - 3
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = -1 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
if (this._y < 0) { this.removeMovieClip(); }
// We calculate the increase of speed
// speedx doesn't change
speedy = speedy + gravity ;
this._x += xSpeed
// We move the ball.
// speed/5 just makes the motion slower
this._x += speedx/10 ;
this._y += speedy/10 ;
}
please help me anyone:hurt:
OrcusDei
January 1st, 2008, 04:44 PM
and im sorry, here is Flash 8 version of the .fla
PRESS SPACE FOR BUBBLES
parkerdc
January 18th, 2008, 02:00 PM
Hey Now!
Just took a look at your code and found 2 problems:
1) You have to adjust the start of the bubble as the x and y are on the top left of the image. (Offset so it will start at the head of the crab.)
Note: check out this post on position. You will still need to offset... http://www.kirupa.com/forum/showthread.php?t=284906
2) KANITOP is an instance of a movie. Inside KANITOP is the actual instance (kani01) of the crab movie. kani01 movie is being moved by the mouse. To code the movie, use KANITOP.kani01.
_root["bubbleTOP1" + i]._x = KANITOP.kani01._x;
_root["bubbleTOP1" + i]._y = KANITOP.kani01._y;
NOTE: You sould tweak your bubble code so the bubbles look real. I have attached an image of a game I wrote in Flash 9. The bubbles fade as they move further away from the diver, random sizes and random movement speed.
One trick is to add gravity BUT use a neg so it rises. ex: -.05
http://www.zuluhotel.com/bubbles1.jpg
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.