PDA

View Full Version : shooting, enterframe and duplicate movieclip


Littlemad
10-27-2005, 05:59 PM
I have some problems trying to make shot my ship
I can duplicate the shots, but I have problems to make them move...
I think that every single shot need an enterframe to permit them to move, but I trying and I cannot have a better result than this...

This is the link where you can see the swf:
http://www.keybrain.it/temp/test3.html

Click "space" to shot

The code interested:


ObjShot = _root.attachMovie("shot", "shots", 0);
if(sparo == 1){
shotCount++
ObjShot.duplicateMovieClip("ObjShot"+shotCount, shotCount);
_root["ObjShot"+shotCount]._x = this._x;
_root["ObjShot"+shotCount]._y = this._y;
_root["ObjShot"+shotCount]._rotation = this._rotation;
}

xThrustShot = Obj.acel*Math.sin(dirAngolo2);
yThrustShot = Obj.acel*Math.cos(dirAngolo2);

_root["ObjShot"+shotCount]._x += xThrustShot*10;
_root["ObjShot"+shotCount]._y -= yThrustShot*10;



This is the whole code:
http://www.keybrain.it/temp/test3.as

Dylan Marvin
10-28-2005, 04:37 AM
Have you tried putting the shot movement code in the "ObjShot" movie clip itself? Nothing wrong at all with enterframe for this sort of thing.

Littlemad
10-28-2005, 12:30 PM
I tryed so many things that I don't remember
But yesterday night really late I find a solution (but I don't know if suck to much CPU energy...) I putted a while.


//movimento dello sparo
ObjShot = _root.attachMovie("shot", "shots", 0); // attacco lo sparo alla root
ObjShot._visible = false; // non lo rendo visibile (altrimenti sarebbe posizionato nell'origine in alto a sinistra)
if(sparo == 1){ //se sto sparando
shotCount++
if(shotCount>50000){ //se gli spari sono troppi
shotCount--; //ferma gli spari
}else{
//se non sono troppi gli spari, duplicali e dagli le coordinate e la rotazione corrispettiva della astronave
ObjShot.duplicateMovieClip("ObjShot"+shotCount, shotCount);
_root["ObjShot"+shotCount]._x = this._x;
_root["ObjShot"+shotCount]._y = this._y;
_root["ObjShot"+shotCount]._rotation = this._rotation;
}
}

// questo While mi serve per far calcolare l'enterFrame ad ogni singolo sparo per far muoverli tutti
k=0;
while(k<=shotCount){
dirAngolo2 = _root["ObjShot"+k]._rotation*Math.PI/180;
xThrustShot = this.shotSpeed*Math.sin(dirAngolo2);
yThrustShot = this.shotSpeed*Math.cos(dirAngolo2);
_root["ObjShot"+k]._x += xThrustShot;
_root["ObjShot"+k]._y -= yThrustShot;
checkNave(_root["ObjShot"+k], _root["ObjShot"+k]._x, _root["ObjShot"+k]._y, 100);
k++
}

Littlemad
10-28-2005, 01:23 PM
now i got another problem when i shoot and shot is moved from down to up and viceversa, the allign of the shooting is not perfect

http://www.keybrain.it/temp/test.gif

the code is here:
http://www.keybrain.it/temp/test4.as

I don't understand why... sometimes work good and sometimes work bad the transposition from a side to another...
any suggest?

*update*

I find that the problem is connected to the movement of the ship, if the ship is stopped (it can only rotate) the problem of duplicate the shoot there isn't.

but I still don't understand why doesn't like the movement....

Dylan Marvin
10-28-2005, 03:01 PM
Would you mind posting your .fla?

Littlemad
10-28-2005, 03:56 PM
no problem!
http://www.keybrain.it/temp/test4.fla
and remember to put in the same folder at same path of the fla this file
http://www.keybrain.it/temp/test4.as

I think that the problem born when the values of xThrust and yThrust are different from 0 (that mean the ship is stop)
when the value became big, more imperfections come out.

Dylan Marvin
10-28-2005, 07:59 PM
Firstly, your source is MX 2004, not MX. So you might have better luck next time posting it in the MX 2004 forum. I'm using a friend's computer who had MX 2004 so it's okay for me at the moment.

I don't see much for problems. But if your concern is what you called the transposition from one side to another, it appears your problem is that the shots (and ship) transpose to their correct locations from one side of the STAGE to another, and not the visible gaming area. So what your seeing is the shots displaced a bit (and delayed in time) by the time you see them reappear. (I wouldn't ask you to translate your code hints and such) but whatever parameters you are using to determine when to "loop" the shots and ship to the opposite side just need to be changed from the stage area's dimensions to the size of the gameplay area's dimensions. Maybe I'm mistaken but the angles themselves look okay to me.

Littlemad
10-28-2005, 09:13 PM
I never thinked that exist a difference from MX2004 and MX (I don't think to use AS2...), sorry for posting in wrong place.

at the end, I decided to ignore that problem (it is verified everytime the rotation of my ship is stop but my ship is still in movement).
Because at the end I will shot 1 or 2 or 3 shot at max, I'm sure that the error with a lot of difficult will come out (it's only that I hate don't resolve the bugs...)

I don't think that is the transposition the core of the problem, I think that in some way the position of my ship in movement that generate the shots in fast sequency give some wrong value when the shots will be transported from a side to another.

Thx for look at code, can you tell me the difference between flash mx 2004 and flashmx?

Dylan Marvin
10-28-2005, 10:02 PM
You can't open an MX 2004 fla in MX without "saving as" an MX fla. I didn't look for this in your code specifically, but there could be AS2 involved. I wasn't inroduced to .as files until MX 2004, but I not sure that they're supported in MX. Lots of little differences from there, of course. I look at MX 2004 as MX v2. I'll have to check out Flash 8 to see how much is really upgraded. I'm not sure about the latest Flash and Flash Player, but at the initiation of MX 2004, ActionScript 2.0 actually gets turned into AS 1 code within the swf (macromedia said they put it in the new format to get people coding "correctly" for future updates. I'm curious if they've done that yet... I'm a couple years behind now with this stuff, waiting to get Flash 8 to upgrade my code chops.)

Littlemad
10-29-2005, 10:35 AM
I'm behind too, the last time that I programmed seriousy was on Flash 5...

You can understand my shock when I see now that exist things like "components", "class", "prototype", "as2" and a future "as3"

I seen your stuff, pretty good! big compliments!

Dylan Marvin
10-29-2005, 03:37 PM
Thanks.
I miss those Flash 5 days a bit (from a gaming perspective) when Flash was about as smart as an Atari 2600:)! You know, spending time trying to make the most out of a little instead of hunting around a million options...

Littlemad
10-31-2005, 12:31 PM
The big problem is that I'm seeking for a Job in UK (I'm italian) and some people ask me if I know AS2, instead to judge my works, or ask if I know flash game making experience, when no one in my career ask me to do that.
Now I'm dooing by myself only to show my quality, but It's a real hard and long work based on a lot of details!

Dylan Marvin
10-31-2005, 03:54 PM
I know, I know. They say knowing JavaScript is a benefit because of the similarities, but I'm trying to learn AS2 and JavaScript at the same time and it really messes up my brain!
How much AS2 do they really want you to know? Is it for a dev team?