Forum Topic: Stupid actionscript problem

(269 views • 7 replies)

This topic is 1 page long.

<< < > >>
None

Psycosis91

Reply To Post Reply & Quote

Posted at: 5/3/06 02:13 PM

Psycosis91 DARK LEVEL 17

Sign-Up: 07/30/04

Posts: 237

Ok I've got an actionscript problem that I can't work out (there's probably an easy answer I'm just to stupid to figure it out :) )

Here's the script

for(i=1;i<100;i++){
if (_root["plat"+i].hitTest(this._x, this._y, true)) {
this.gotoAndStop("run");
}
}

It's simply saying that if the character is on one of the 100 platforms, it goes to the run frame to play the running animation, should be easy.

The problem is that when this happens it only plays the first frame of the animation, but when it's on the ground (same script just without the 'for' part really) it plays it perfectly.

Any ideas?


None

Cybex

Reply To Post Reply & Quote

Posted at: 5/3/06 02:21 PM

Cybex NEUTRAL LEVEL 20

Sign-Up: 03/04/05

Posts: 7,744

At 5/3/06 02:13 PM, psycosis91 wrote: Ok I've got an actionscript problem that I can't work out (there's probably an easy answer I'm just to stupid to figure it out :) )

Here's the script

for(i=1;i<100;i++){
if (_root["plat"+i].hitTest(this._x, this._y, true)) {
this.gotoAndStop("run");
}
}
It's simply saying that if the character is on one of the 100 platforms, it goes to the run frame to play the running animation, should be easy.

The problem is that when this happens it only plays the first frame of the animation, but when it's on the ground (same script just without the 'for' part really) it plays it perfectly.

Any ideas?

It might be something to do with the fact that its making 100 calculations a frame so, it might only try to play that animation for 1/100 of a frame. Try something like this:

for(i=1;i<100;i++){
if (_root["plat"+i].hitTest(this._x, this._y, true)) {
var=1;
}
}
if(var==1){
this.gotoAndStop("run");
}


None

Psycosis91

Reply To Post Reply & Quote

Posted at: 5/3/06 02:33 PM

Psycosis91 DARK LEVEL 17

Sign-Up: 07/30/04

Posts: 237

At 5/3/06 02:21 PM, Cybex wrote: code

I tried that but it still doesn't seem to work. As the [plat+i] is just so I can use numerous platforms without coding each. I used the for script in my other game too. I think it might have something to do with the script not being able to work in a 'for' script or something.

Thanks anyway for helping.


None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 5/3/06 02:47 PM

Afro-Ninja EVIL LEVEL 35

Sign-Up: 03/02/02

Posts: 13,171

eh, dunno if this will work but worth a try

onClipEvent(load)
{
this.running=false;
this.onPlatform=false;
}
OnClipEvent(enterFrame)
{
this.onPlatform=false;
for(i=1;i<100;i++){
if (_root["plat"+i].hitTest(this._x, this._y, true) &&!this.running) {
this.gotoAndStop("run");
this.running=this.onPlatform=true;
}
this.running = this.onPlatform;
}
}

BBS Signature

None

Psycosis91

Reply To Post Reply & Quote

Posted at: 5/3/06 03:00 PM

Psycosis91 DARK LEVEL 17

Sign-Up: 07/30/04

Posts: 237

At 5/3/06 02:47 PM, Afro_Ninja wrote: eh, dunno if this will work but worth a try

onClipEvent(load)
{
this.running=false;
this.onPlatform=false;
}
OnClipEvent(enterFrame)
{
this.onPlatform=false;
for(i=1;i<100;i++){
if (_root["plat"+i].hitTest(this._x, this._y, true) &&!this.running) {
this.gotoAndStop("run");
this.running=this.onPlatform=true;
}
this.running = this.onPlatform;
}
}

I tried that but instead of getting the run animation to play it sorta switches to and from the run frame and the jump frame. Thanks anyway, I'm gonna try and look into it more...


None

Psycosis91

Reply To Post Reply & Quote

Posted at: 5/3/06 05:30 PM

Psycosis91 DARK LEVEL 17

Sign-Up: 07/30/04

Posts: 237

sorry for DP but i'm completely stumped :( anyone got any ideas?


None

Vengeance

Reply To Post Reply & Quote

Posted at: 5/3/06 05:33 PM

Vengeance EVIL LEVEL 28

Sign-Up: 03/18/05

Posts: 5,049

well you could try this:
while(i<100){
i++
if(_root["play"+i].hitTest(_x,_y,true)){
gotoAndStop("run")
i+=100
}
}

or something along those lines, that way it will stop the while loop once it finds a platform it's on.

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

None

Khao

Reply To Post Reply & Quote

Posted at: 5/3/06 05:41 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

I suggest that you put all the platforms into 1 movieclip and hittest to that movieclip only... 100 hittests per frame is kinda hard on the machine cause hittests are laggy :\
then you could just do the run animation like you did for your ground that worked like you said


All times are Eastern Standard Time (GMT -5) | Current Time: 01:38 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!