View Full Version : Help spawning balls in a game
bamman1108
06-30-2009, 12:02 AM
I'm making a game similar to Pong. After a certain amount of time, I want a second ball to appear and do the same thing as the first, by using attachMovie. The problem, which I just now realized, is that the code for the ball is on the timeline, and not on the movie clip, which would make this much easier.
My question is, do you know of a way to make one function work for more than one movie clip? I've tried giving the dynamically spawned ball a certain instance name, then tried a for loop around the functions I want to be the same, but it didn't work. I don't have time now, but if you want some of the code, I'll put it up later.
BTW, it's AS2. This post got moved, so it's not in the title.
bamman1108
06-30-2009, 02:51 AM
Here is the entire file (unfinished):
Flash file (http://www.zshare.net/download/62030174c70900c1/)
Also, is there a more efficient way to handle the effects when the ball hits a paddle? It gets really laggy for me whenever the ball makes contact.
bamman1108
07-01-2009, 03:10 AM
Didn't want to make a new topic, but I figured out my problem. Now I have another. The game seems to lag whenever it hits a paddle or the boundaries. I'm having trouble making this stop. I portion of it was that the function for the little ball's movements relied on calling in a variable several times, and I solved that by making a variable in the movie clip equal it and then use that. It definitely helped, but I think the the use of random numbers could also be slowing it down.
Anyone know how to fix the rest of the lag?
this.increment = _root.yspeedb/2;
xspeedp = Math.random()*-3;
yspeedp = Math.random()*3-1.5+(this.increment);
xspeedp1 = Math.random()*-3;
yspeedp1 = Math.random()*3-1.5+(this.increment);
xspeedp2 = Math.random()*-3;
yspeedp2 = Math.random()*3-1.5+(this.increment);
xspeedp3 = Math.random()*-3;
yspeedp3 = Math.random()*3-1.5+(this.increment);
xspeedp4 = Math.random()*-3;
yspeedp4 = Math.random()*3-1.5+(this.increment);
function onEnterFrame() {
this.h1._x += xspeedp;
this.h1._y += yspeedp;
this.h2._x += xspeedp1;
this.h2._y += yspeedp1;
this.h3._x += xspeedp2;
this.h3._y += yspeedp2;
this.h4._x += xspeedp3;
this.h4._y += yspeedp3;
this.h5._x += xspeedp4;
this.h5._y += yspeedp4;
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.