PDA

View Full Version : Removing movieclips problem



jose3760
November 30th, 2006, 07:16 AM
I have my guy who shoots at blocks. I want it so that when the bullets hit the blocks, the bullet dissapears and the block dissapears. right now, im using ._alpha because i couldnt get the removemovieclip() to work.

here is my code on the block:


onClipEvent(enterFrame){
if(this.hitTest(_root.bullet)){
_root.b1._alpha = 0;
_root.score += 1;
}
}

so since im using alpha, i can keep shooting the block and get points, which is a bad thing :P

Campestre
November 30th, 2006, 07:46 AM
try using
_root.b1._visible = false;
instead of
_root.b1._alpha = 0;
I dunno if this is right,but it's a way to hide buttons..

jose3760
November 30th, 2006, 03:08 PM
yea i tried that, it dosent remove it, it just hides it

bombsledder
November 30th, 2006, 03:24 PM
_root.b1.removeMovieClip()

bombsledder
November 30th, 2006, 03:25 PM
_alpha =0 and _visible= false do the same thing in sense

Campestre
November 30th, 2006, 03:31 PM
Oh, thanks!
I understood now

jose3760
November 30th, 2006, 04:04 PM
still dosent work, now when i shoot it, it stays visible, and i still get points :P

bombsledder
November 30th, 2006, 04:17 PM
have you used _root.getNextHighestDepth() ??

jose3760
November 30th, 2006, 04:20 PM
nope, cause i have no clue how it works :P

can you tell me how it works and what it does and ill try it :D

bombsledder
November 30th, 2006, 04:26 PM
hmm can i see the code you have and is it a component?

jose3760
November 30th, 2006, 05:09 PM
this is the code i have on the block

onClipEvent (enterFrame) {
if (this.hitTest(_root.bullet)) {
_root.score += 1;
_root.b1.removeMovieClip();
}
}

bombsledder
November 30th, 2006, 05:41 PM
ok so try this



onClipEvent (enterFrame) {
if (this.hitTest(_root.bullet)) {
_root.score += 1;
trace("movie-> "+_root.b1)
trace("movie depth->"+_root.b1.getDepth())
_root.b1.removeMovieClip();
}
}


now tell me what is in the output

jose3760
November 30th, 2006, 06:12 PM
still dsnt work :S i can send you the game through email, adn you can check it out

bombsledder
November 30th, 2006, 06:43 PM
umm why don't you tell me what was traced

Darth Arias
November 30th, 2006, 08:34 PM
A not very actionscripty way to do it would be to have it gotoandPlay a frame that ends with it being deleted when it hits the bullet. It should go away. For example:

Example (http://img180.imageshack.us/my.php?image=carnage1fz2.swf)

The enemies, when shot, actually just play some frames that end with an empty frame, that it stops on. They effectively go away. Hopes this helps.

bombsledder
November 30th, 2006, 08:48 PM
he wants it gone, if he didnt want it there he would stick with _alpha or _visible

Darth Arias
November 30th, 2006, 10:46 PM
Yep. With my example, I want them gone though, so I do that. Although, you could potentially bring hem back, with a button say, that on a hit test makes the block stop back on a visible frame... But I digress...

jose3760
November 30th, 2006, 11:01 PM
yea, that works, but im trying to make my game as simple as possible, and that will lagg up my game cause i have alot of block, i think theres 50, (b1-b50)

Darth Arias
November 30th, 2006, 11:23 PM
It shouldn't lag up too much, mine starts to when around 75 guys are on stage, but are all the blocks different? Like are they all different mcs?

SacrificialLamb
November 30th, 2006, 11:56 PM
you can only use removeMovieClip(); on movie clips you have added with attachMovie (MovieClip.attachMovie method). But I think you can use unloadMovie(this);

p.s.
have you tried using runtime bitmap caching to speed up the game on things that do not animate much

habes
December 1st, 2006, 12:13 AM
have you attached the blocks using actionscript, or are they just set on the stage?
edit:
haha, just saw your post sacrafical lamb

Lou
December 1st, 2006, 04:58 AM
have you tried using runtime bitmap caching to speed up the game on things that do not animate much

Please explain this more, I am interested. (sorry to hijack thread)

SacrificialLamb
December 1st, 2006, 05:12 AM
I have not really used bitmap caching as I have only recently found out about it myself and have not looked in to how to use it (I have been found out throwing big words about).
But with a minimal search I think this might be a useful link, it’s about half way down and has both for and against info
http://www.adobe.com/devnet/flash/articles/flash8_bestpractices_11.html

Lou
December 1st, 2006, 05:52 AM
That article you linked is brimming with useful information. Thanks!

Flash Player 8 introduces bitmap caching, which helps you enhance the performance of nonchanging movie clips in your applications. When you set the MovieClip.cacheAsBitmap or Button.cacheAsBitmap property to true, Flash Player caches an internal bitmap representation of the movie clip or button instance. This can improve performance for movie clips that contain complex vector content. All of the vector data for a movie clip that has a cached bitmap is drawn to the bitmap, instead of to the main Stage.

It's ideal to use the cacheAsBitmap property with movie clips that have mostly static content and that do not scale and rotate frequently. With such movie clips, using the cacheAsBitmap property can lead to performance improvements when the movie clip is translated (when its x and y position is changed).


Looks like if you use it, viewers with older versions of Flash player could have some issues.

Thinker2501
December 1st, 2006, 02:56 PM
Here:


onClipEvent (enterFrame) {
if (this.hitTest(_root.bullet)) {
_root.score += 1;
_root.bullet.removeMovieClip();
this.removeMovieClip();
}
};

bombsledder
December 1st, 2006, 03:32 PM
I assumed that he was using the attachMovie method, because i regulary do i guess i made a mistake lol, explain how you have b1-b50 duplicateMovieClip ?

SacrificialLamb
December 1st, 2006, 05:51 PM
yes so would I but you can tell after he gives the code and that it was not working. I would expect use that way my self but when I was learning I was hesitant at using functions and making code too complex and I never used duplicateMovieClip just seems a silly way to do it after learning attachMovie.

bombsledder
December 1st, 2006, 06:07 PM
i had no clue it seemed like this wasnt his only code and i would have rather seen the .fla so i would been able to tell I dunno i don't like being confused =/

SacrificialLamb
December 1st, 2006, 06:11 PM
yes it's much simpler to help when you are given the .fla but people get all protective of there work and don’t like just anyone having it. that or they are ashamed of it :P

jose3760
December 1st, 2006, 10:15 PM
ok, holy crap, heres the game to make things simpiler

http://img243.imageshack.us/my.php?image=spaceshipgamewebam0.swf

i fixed the removing the blocks part, but as you see there are a few problems with shooting

SacrificialLamb
December 1st, 2006, 11:26 PM
are you asking for help with the shooting? if you post the .fla (with out sound) i could have a look. i think i know what it is, you have to make the x position of the ship a var in the bull befor you fire it, and do you remove the built when it is out of sight, if you do not that will slow down the game a lot

jose3760
December 2nd, 2006, 12:00 AM
id post the .fla but its too big. the thing is (this is real noobish ) that i use a tween to move the bullet across the screen -.-'

i could send you the fla?

Darth Arias
December 2nd, 2006, 03:10 AM
That is your problem. No doing that. Bad. :) Seriously, though, you never want to do that. Use a duplicateMovieClip for the bullet (which should be a movieclip) for when you press space. Then, tell the bullet to move up so many pixels every frame. Simple, and effective. Then, tell the bullet to go away once it has hit a block.

SacrificialLamb
December 2nd, 2006, 03:23 AM
go here
http://www.kirupa.com/developer/actionscript/vertical_shooter.htm
look at how it's done there most not that I would use that way but it works.

jose3760
December 2nd, 2006, 09:57 AM
yea it helps, but alot of the script is wrong

jose3760
December 2nd, 2006, 10:53 PM
ok, i have updated it alot, and changed alot of things. I have all the script (well, most of it) on one frame, and this is whats on it.:

//---- variables ----
var steps:Number = 10;
var spriteX:Number = 300;
var spriteY:Number = 500;
var speed:Number = 40;
var arrowActive:Boolean = false;
var dragons:Number = 10;
var i:Number = 0;
var score:Number = 0;
//---- properties ----
knight.swapDepths(100);
//---- functions ----

function checkKeys() {
if (Key.isDown(Key.RIGHT) && spriteX<700) {
spriteX += steps;
} else if (Key.isDown(Key.LEFT) && spriteX>0) {
spriteX -= steps;
}

if (Key.isDown(Key.UP) && arrowActive == false) {
attachMovie("arrow", "arrows", 0);
arrows._x = spriteX;
arrows._y = spriteY-20;
arrowActive = true

}
}

function updatePawel() {
knight._x = spriteX;
knight._y = spriteY;
}
function updateArrow() {
if (arrowActive == true) {
arrows._y -= speed;
}
if (arrows._y<-10) {
arrowActive = false;
removeMovieClip(arrows);
}
}

loop
function initDragons() {
for (i; i<dragons; i++) {
attachMovie("dragon", "dragon"+i, i);
dragon = _root["dragon"+i];
updateDragons(dragon);
dragon.onEnterFrame = function() {
if (this.hitTest(knight)) {
removemovieclip("knight")
updateDragons(this);
}

if (this._x>0) {
this._y += this.velo;
} else {
updateDragons(this);
}
};
}
}

initDragons();
function updateDragons(which) {
which._x = random(600)+0;
which._y = random(0)+0;
which.velo = random(7)+2;
}

this.onEnterFrame = function() {
checkKeys();
updatePawel();
updateArrow();
endloop

};


the the only problem is is that the asteroids dont respawn back up at the top when they get to the bottom. any suggestions?

nathan99
December 2nd, 2006, 11:21 PM
if(object._y>maximum_height_here){
object._y = newY;
}

jose3760
December 3rd, 2006, 09:11 AM
dosent seem to work

Darth Arias
December 3rd, 2006, 02:11 PM
Well, it would help to try to explain exactly what you want. For example, do you want your enemies to behave like those in the game centipede?

jose3760
December 3rd, 2006, 06:08 PM
ok. this is the code from a tutorial on kirupa, so i modified it a little. I have my character, (a spaceship) called knight, and i have my bullet that i shoot, called arrow, and my asteroids (called dragons). origonally the dragons went across the top of the screen, but i changed it so they went down. i want it so that when the asteroids (dragon) hit the bottom of the screen, they go back to the top.

bombsledder
December 3rd, 2006, 07:55 PM
this thread is too long for this problem just post your .fla so someone can fix it and it will all be good..

Darth Arias
December 3rd, 2006, 08:00 PM
Nah, that is easy enough to fix. Just, if you are really desperate, make a simple bar movie clip right below the bottom of the stage (in the grey area) that has a hit test:

//bar actionscript
onClipEvent(enterFrame){
if(this.hitTest(_root.dragon)){
_root.dragon._x = random(stage x size);
_root.dragon._y = 0);
}
}
//end actionscript

replace stage x size with the number equivalent to the width of the stage. Easy. No complaints.

bombsledder
December 3rd, 2006, 08:03 PM
//bar actionscript
onClipEvent(enterFrame){
if(this.hitTest(_root.dragon)){
_root.dragon._x = random(Stage.width)
_root.dragon._y = Stage.height
}
}
//end actionscript


might be a little more effective

Darth Arias
December 3rd, 2006, 11:19 PM
They are identical, though. So either way is fine.

bombsledder
December 4th, 2006, 03:30 PM
stage x size will return an error, it Stage.width will return the size of the stage

Darth Arias
December 4th, 2006, 05:59 PM
no, I meant stage x size as the width of the stage. That is what the note under the script means... it was more explaining.

bombsledder
December 4th, 2006, 06:08 PM
to someone that doesnt know actionscript putting that will really confuse them and make them ask more questions if i just give them the right code in the first place it saves them time, and builds up more confidence instead of quiting

Darth Arias
December 5th, 2006, 08:13 PM
I was trying to explain it... If you read my post, all the way until the end, you will notice that it does give directions... not that difficult, if you can't figure that out maybe flash is too complex...