Bullet problem.

17 posts

Flag Post

So, when i was making my previous ‘project’ (hehe it was too noobish to call an actual project) I always jut created a new movie clip and copied the whole code when i wanted 2 enemies appear at once.

But this time i want to work with bullets, and copying like 20 bullets is, as i believe, going to make the game lag a lot.

So is there a way to create ‘copies’ of bullets with simple scripting?

Huh, i hope someone actually understands this. ^^
Thanks,
Balidani

 
Flag Post

draw one bullet. Right click on it in your library and click linkage. Click export for AS and identify it as “bullet”.

Now you can create movies of them maybe in an array? I don’t know what you want to do.

var bullets:Array = new Array (MovieClip);

and a for loop or something setting each bullet with

bullets[i].attachMovie (“bullet”…..);

Does that do what you want? You might also want to look at the function “duplicateMovieClip”. Maybe using that is better? I haven’t tried to make a game like you’re making. I just thought I’d give you something to get you started.

 
Flag Post

wtf??

None of that code is even correct… I know you mean well, but maybe it’s best to practice your own coding skills before confusing people with bad code.

var bullets:Array = new Array();

You don’t need to include a MovieClip instance as a parameter to the Array constructor. You could initialize it that way, but it’s probably best to add bullets into the array as follows:

bullets.push(attachMovie("bullet","bullet" + i,i));

The code you posted:
bq. bullets[i].attachMovie (“bullet”…..);

…doesn’t make any sense :S

 
Flag Post

Wow. First of all, either contribute something to this guy’s question or stop spamming his thread. Did you just come here to insult me? I’m sorry, but I’d rather not take advice from someone who uses the term “programming skills”. I will keep my comments about POD to myself.

The (“bullet”…..) part was “fill in the rest of the function yourself”. Could you not figure that out? Everyone doesn’t need every single things spoon fed to them.

Kongregate needs an ignore user button.

 
Flag Post

And a question for someone else since I’m not sure Indie knows what he’s talking about:

Is there anything wrong with the var bullets:Array = new Array (MovieClip); line? I always pass a data type to the Array constructor and assumed that was the proper thing to do if I knew what data type my array was going to store. Should I stop doing this?

 
Flag Post

First of all, either contribute something to this guy’s question or stop spamming his thread.

I’m not spamming. Quite to the contrary, I’m giving him advice he can actually use… not incorrect code snippets which will likely just cause confusion.

The (“bullet”…..) part was “fill in the rest of the function yourself”. Could you not figure that out?

No, but apparently you’re not smart enough to know why that code is completely bogus. Do you even know that attachMovie is a method of the MovieClip class? Do you even know what a method is? Can you tell me what the attachMovie method returns? Do you realize that saying

 bullets[i].attachMovie

is assuming the array is already populated with MovieClips? Why do you want to double the amount of clips on the stage? Gimme a freakin’ break. You’re not even writing sensible code.

I’m not sure Indie knows what he’s talking about

I don’t get paid $50 an hour as a professional Flash programmer for nothing, so just chew on that, bub. Regardless of what you think about POD, it’s a LOT better than anything that you’ve done in Flash (wait… have you done anything in Flash??) My guess is that you couldn’t code yourself out of a wet paper bag, but hey, prove me wrong.

 
Flag Post

Ugh, you are some kind of loser internet creep – I can tell already. Ok, I don’t think you’ve helped anyone here. You’re just trying to promote your “mad programming skills” and the fact that you get “$50 an hour”. Seriously man, I don’t think anyone is impressed. I just kind of pity you myself.

I almost lost my head and got into some kind of pissing match with you but then came to my senses. Good luck with life dude. I hope I never have to talk to you again.

 
Flag Post

Wow, you certainly did resort to petty insults, though. I likewise hope that you never speak to me again, but FYI I’m a part of this community, and have been for a lot longer than you. I’m not trying to prove anything here, except proper technique.

You don’t have to be impressed with my skills or my wage, I do just fine without anyone’s approval. I only mentioned what I do for a living so you’d know I’m not full of crap. Not sure you’re worth reasoning with, though…

 
Flag Post

Holy crap guys, stop arguing. One guy asked a question and all he wanted was an answer, not an argument.
http://www.myflashresource.com/flash-tutorials/the-tank-part-2-rotating-and-shooting-the-cannon theres a good tutorial for how to shoot bullets, so it will show you how do duplicate bullets. That one is an ok tutorial. There is a better one i like but i can’t find now. If i find it ill post link for you.

 
Flag Post

Woah, chill guys!

@sage880: Your code was sketchy and Indie was pointing that out as he should. I’m not saying I endorse his comments or how he’s handling this, but if you post sketchy code in a programming forum, be prepared to be corrected. If you cant accept being told your code is odd, you may want to avoid posting until you can handle that. Indies response to your initial post included a more standard example of how to do what is being asked.


bq. And a question for someone else since I’m not sure Indie knows what he’s talking about: Is there anything wrong with the var bullets:Array = new Array (MovieClip);


Passing parameters into the Array constructor will populate the array with those values, unless you use an integer which will specify the initial length of the array. Passing in the MovieClip data type as you showed will push an initial value into the array, in that case a function pointing to the MovieClip class. This is nearly useless except in stange cases (of which I cant even think of any), and its not something you want to recommend in general. It will possibly confuse a lot of users to have an unexpected type function in their newly created array (which they likely wont expect, especially if they push other data types later).

So yeah, he is correct – its not really a good idea. MovieClip is a TopLevel class (and is an abstract so you wont use new MovieClip() in AS2), so a pointer to it will not likely ever need to be stored.

@Indie: His code may be weird, but he was trying to help. He should get some credit for that, since he didnt have to post. Lets not try to scare off everyone that wants to help (right or wrong) :)

 
Flag Post

Okay, okay.

Point well taken, Coder. I am merely pointing out obvious flaws in the advice being given. I mean no personal offense.

I apologize to Sage and I hope that he will continue to contribute to our little programming forum here :)

 
Flag Post

Thanks for the apology. I was never annoyed with your correction – I just didn’t think the “wtf?? go practice your coding skills” was constructive. Hey, as long as people are polite I’d love to see why my code is wrong. I have no problem what-so-ever with people teaching me things. I know I’m rusty as hell – I written one line of code in at least 7 years and laid my eyes on Flash CS3 for the first time this September.

I just came across this guy’s unanswered post which was 4 hours old. I know how frustrating it is when you’re looking and waiting for an answer so I figured I’d try and point this guy in the right direction. If someone had came along and wrote “Actually, this is the best way to do this…” I wouldn’t have batted an eye. In fact, I probably would have taken notes and maybe even thanked the person.

 
Flag Post

Awesome. I’m just going to stop posting for awhile…

 
Flag Post

Thanks, for the answers guys! Today i might be able to start working on this bullet thing.
But I still wonder, does duplicate movie clip doesnt copy the actionscript attached to the movieClip?

 
Flag Post

I just figured it out myself :P
it took a few mins but figuring things out yourself is cool ^^

 
Flag Post

Glad to see it resolved. Thanks both of you for trying to help.

 
Flag Post

I just figured it out myself :P it took a few mins but figuring things out yourself is cool ^^

Definitely. I learned a lot more than coding from this thread…