PDA

View Full Version : Advanced ActionScript: Moving


cereal_killa
06-11-2005, 09:35 AM
I am trying to use this code to make my sprite move, but I doesn't work.
onClipEvent(enterFrame){
if(key.isPress(39)){
setProperty (character, _x, _x+5)
}
}
and it won't work. What does someone else suggest?
and would you suggestion be the same premace as a jump script?

VooDoo
06-11-2005, 12:14 PM
I've got a test you can try out, make a platform like a line turn that into a movie clip and call it platform_mc and an instance name called plat5 and make a new layer and put a Mc your wanting to move and put this code on it.

onClipEvent (load) {
drop = 0;
direction = "right";
this._parent.you_did_it._visible = false;
this._parent.get_plane._visible = false;
this._parent.game_over._visible = false;
jump = false;
this.stop();
}
// just put a marker here
onClipEvent (enterFrame) {
if (_root.end == false) {
if (Key.isDown(90)) {
if (direction == "right") {
this._xscale = -this._xscale;
direction = "left";
}
// where it says this._x -= 3; thats how fast to the left
this.play();
if (this._x<10) {
this._x == 10;
} else {
this._x -= 3;
}
}
}
if (_root.end == false) {
if (Key.isDown(88)) {
if (direction == "left") {
this._xscale = -this._xscale;
direction = "right";
}
// i think this part is the boundary inspector where it says 500 + 500 thats the bondary walls
// where it says this._x += 3; That means the speed of the movie clip going right
this.play();
if (this._x>500) {
this._x == 500;
} else {
this._x += 3;
}
}
}
//where it says Key.isDown (Key.space) && 1jump) thats the jump key
if (_root.end == false) {
if (Key.isDown(Key.space) && !jump) {
drop = 20;
jump = true;
}
}
if (jump == true) {
drop -= 1;
if (drop<=-500) {
drop = -500;
}
this._y -= drop;
}
for (i=1; i<10; i++) {
if (_root["plat"+i].hitTest(this._x, this._y, true)) {
drop = 0;
jump = false;
plat_num = i;
this._y = _root["plat"+i]._y-5;
}
}
if ((_root["plat"+plat_num]._x-this._x)<-(_root["plat"+plat_num]._width/2) && !jump || (_root["plat"+plat_num]._x-this._x)>(_root["plat"+plat_num]._width/2) && !jump) {
drop -= 1;
if (drop<=-10) {
drop = -10;
}
this._y -= drop;
}
}


That should make some **** move for ya :smokeing1 .

Ilikepandas
06-11-2005, 10:50 PM
Heres some simple crap. Get a symbol (Movie clip). On the first frame of the movie clip go to the actions and go stop() then on the other frames make a jumping animation. on the first frame again make the character drawing another movie clip inside the first movie clip. call it "walk". on this movie clip "walk" also add stop() on the first frame. then on the other frames get him/her walking. THEN... go back to the main movie and add this code to the main symbol thing:

onClipEvent (load) {
movespeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this.walk.play ();
this._xscale = 100
_x += movespeed;
}
if (Key.isDown(Key.LEFT)) {
this.walk.play ();
this._xscale = -100
_x -= movespeed;
}
if (Key.isDown(Key.SPACE)) {
play()
}
}

for this to work properly make sure the character isn't resized differently than it is from the library and also make sure he/she is facing right.

understand? no? then go to flashkit.com or somethink

cereal_killa
06-12-2005, 11:52 AM
THANK YOU PANDA!
do you want to work on a side scroller together?
I got some ideas, and I'm using your code!
I tried this, but its kinda slow and without
options for expansion.

onClipEvent (load) {
walkSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(key.RIGHT)) {
_x += walkSpeed;
}
if (Key.isDown(key.LEFT)) {
_x -= walkSpeed;
}
}

thanks!

edit: this is the sample game, it sucks as of right now, and I don't really think there is much chance of it getting better unless i learn more code.

VooDoo
06-12-2005, 02:49 PM
Your better off using my script theres more controls for the character.

cereal_killa
06-13-2005, 12:40 PM
Um, VooDoo, I don't see any code. ilikepandas, thanks again.I gotta put that thing to the side right now, I'm re-making my schools website, laugh at it (http://cortlandschools.org).