PDA

View Full Version : Basic automatic up and down movement


colorfusion
03-05-2011, 05:17 PM
Basically I have just started learning actionscript and I have been experimenting with making scripts and things, I have a game with a character and a cloud.
I have got it so the player can stand on the cloud, but I would like the cloud to move up then down constantly, I do not care too much about if its smooth but if it is then thats a bonus.

Here is the script I put in so far which I thought would work:


onClipEvent (enterFrame) {
for (i=1;i<500;i++){
_y = _y + 0.5
}
for (i=1;i<500;i++){
_y = _y - 0.5
}
}

It gives me no errors when running it but just doesnt do anything, the cloud stays completely static.
Could anyone please help me with this? Probably something easy but I have been searching for a while and can't find an answer.

JF91
03-05-2011, 07:20 PM
Make the cloud a movie clip, and give it an instance name.

The use something like:

cloud.addEventListener(Event.ENTER_FRAME, moveCloud);

function moveCloud(evt:Event){
for(i:uint=0;i<20;i++){
cloud.y++;
}
for(i:uint=0;i<20;i++){
cloud.y--;
}
}

colorfusion
03-06-2011, 07:57 AM
Thanks but the cloud still just stays still and the output gives:


**Error** Scene=Scene 1, layer=Stuff, frame=1:Line 4: The class or interface 'Event' could not be loaded.
function moveCloud(evt:Event){

**Error** Scene=Scene 1, layer=Stuff, frame=1:Line 5: The class or interface 'uint' could not be loaded.
for(i:uint=0;i<20;i++){

**Error** Scene=Scene 1, layer=Stuff, frame=1:Line 8: The class or interface 'uint' could not be loaded.
for(i:uint=0;i<20;i++){

marlopax
03-06-2011, 09:49 AM
If this make sense to you


var boolX:Boolean = false;
var boolY:Boolean = false;

cloud.onEnterFrame = function() {
if (cloud._x<0-250) {
boolX = true;
} else if (cloud._x>0+500) {
boolX = false;
}
if (cloud._y<15) {
boolY = true;
} else if (cloud._y>20) {
boolY = false;
}
if (boolY == true) {
cloud._y++;
cloud._alpha += 10;
} else {
cloud._y--;
cloud._alpha -= 10;
}
if (boolX == true) {
cloud._x = 580;
} else {
cloud._x -= 5;
}
};


This code will go in TimeLine.



marlopax

colorfusion
03-06-2011, 11:23 AM
If this make sense to you


var boolX:Boolean = false;
var boolY:Boolean = false;

cloud.onEnterFrame = function() {
if (cloud._x<0-250) {
boolX = true;
} else if (cloud._x>0+500) {
boolX = false;
}
if (cloud._y<15) {
boolY = true;
} else if (cloud._y>20) {
boolY = false;
}
if (boolY == true) {
cloud._y++;
cloud._alpha += 10;
} else {
cloud._y--;
cloud._alpha -= 10;
}
if (boolX == true) {
cloud._x = 580;
} else {
cloud._x -= 5;
}
};


This code will go in TimeLine.



marlopax

Thanks! With a little editing this works exactly how I want it!
Here is the working script I have got in the Timeline:

var boolX:Boolean = false;
var boolY:Boolean = false;

cloud.onEnterFrame = function() {
if (cloud._y<300) {
boolY = true;
} else if (cloud._y>450) {
boolY = false;
}
if (boolY == true) {
cloud._y++;
} else {
cloud._y--;
}
};

marlopax
03-06-2011, 06:19 PM
You are Welcome

I 'd shown you both way movement, whichever fits your need....



marlopax