|
metadata
OK, so I did the whole tutorial. The enemy ship comes, I can shoot it, the missile dissapears when it hits the enemy but the ENEMY SHIP WON’T EXPLODE! The enemy ships will explode if the hero ship touches them but not if the missile touches them. (I went further and the enemy ship also shoots and the missile dissapears – no problems there)
Here’s the Missile code:
`
class Missile extends MovieClip
{
var speed;
function onLoad()
{
speed = 20;
}
function onEnterFrame()
{
_x += speed;
for(var i in _root.ship.enemies)
{
if(this.hitTest( _root.ship.enemies[i] ) )
{
this.removeMovieClip();
_root.ship.ememies[i].explode();
}
}
if(_x > 600)
{
this.removeMovieClip();
}
}
}
`
and here’s the EnemyShip code:
`
class EnemyShip extends MovieClip
{
var speed;
var shootTimer;
function onLoad()
{
_x = 700;
_y = Math.random()*200 + 50;
speed = Math.random()*4 + 5;
shootTimer = 0;
}
function onEnterFrame()
{
_x -= speed;
if(_x < -100)
{
this.removeMovieClip();
}
if(this.hitTest(_root.ship))
{
explode();
}
shootTimer += 1;
if(shootTimer > 30)
{
shootTimer = 0;
var missile = _root.attachMovie("EnemyMissile","EnemyMissile" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
missile._x = _x - 50;
missile._y = _y + 2;
}
}
function explode()
{
var explosion = _root.attachMovie( "Explosion" , "Explosion" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );
explosion._x = _x;
explosion._y = _y;
this.removeMovieClip();
}
}
`
THANKS!!! Dibbo.
|
|
|
metadata
You can post your code on Kongregate by using the tags \< pre\> to open and \< /pre\> to close. Make sure to remove the spaces in both tags.
So
Blank Line
pre tag open
code
code
code
pre tag close
rest of paragraph
|
|
|
metadata
hum try to put this entire onEnterFrame()
`
function onEnterFrame()
{
_x -= speed;
if(_x < -100)
{
this.removeMovieClip();
}
if(this.hitTest(_root.ship))
{
explode();
}
if(this.hitTest(_root.missile))
{
explode();
}
shootTimer += 1;
if(shootTimer > 30)
{
shootTimer = 0;
var missile = _root.attachMovie("EnemyMissile","EnemyMissile" + _root.getNextHighestDepth(),_root.getNextHighestDepth());
missile._x = _x - 50;
missile._y = _y + 2;
}
}
function explode()
{
var explosion = _root.attachMovie( "Explosion" , "Explosion" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );
explosion._x = _x;
explosion._y = _y;
this.removeMovieClip();
}
`
I guess that will work. Another thing: try to UNDERSTAND the codes so you can run more complex ones. any questions i’m here
|
|
|
metadata
nah that didnt work – i tried it, it didnt fix the problem i had above and for some reason when i hit the enemy ships they wud dissapear and the explosion wud happen in the top left corner of the stage.
i think im gonna get a book on flash soon so i think that’ll help me get started – but im still looking for an answer to my prob! thanks for ur reply though!
|
|
|
metadata
hmm, looks fine
Try swapping the removeMovieClip() and .explode() lines in the Missile class.
|
|
|
metadata
I’m no expert and still in the process of learing actionscripts.
try what explodingferret has said
i’m not sure but i think removeMovieClip is a destructor for the class. which means \_root.ship.enemies[i] no longer exists so there is no explode function for that instance any more.
I’ll try to lay it out a bit better.
imagine you have 3 enemies
\_root.ship.enemies3 , \_root.ship.enemies12 , \_root.ship.enemies16
now we remove one
\_root.ship.enemies12.removeMovieClip();
now we only have 2 enemies
\_root.ship.enemies3 , \_root.ship.enemies16
So if we try to do
\_root.ship.enemies12.explode():
we can’t as there is no \_root.ship.enemies12 anymore
|
|
|
metadata
hmm damn i thought that wud work – it didnt work and had no effect on the game. thanks for trying anyway!
|
|
|
metadata
your going to kick your self if this is right SPELLING MISTAKE
\_root.ship.eMemies[i].explode
M should be n.
And ignore my previous post it’s complete nonsense the this.removeMovieClip Destroys the class it’s in which is the missle class in this case.
|
|
|
metadata
OMG YOU’RE RIGHT!!! hahahahahhahaha i even checked the whole thing for spelling mistakes :|
lol thanks so much i wudnt of seen that! and it all works fine now :D
|
|
|
metadata
my missiles wont make the enemies explode, nor the missile will disappear…
help please
`
class missile extends MovieClip
{
var speed;
function onLoad()
{
speed = 20
}
function onEnterFrame()
{
_x += speed;
for(var i in _root.ship.enemies)
{
if(this.hitTest( _root.ship.enemies[i] ) )
{
this.removeMovieClip();
_root.ship.enemies[i].explode();
}
}
if(_x > 600)
{
this.removeMovieClip();
}
}
}
``
class ship extends MovieClip
{
var velocity;
var shootLimiter;
var enemyTimer;
var enemies;
function onLoad()
{
velocity = 10;
shootLimiter = 0;
enemyTimer = 0;
enemies = [];
}
etc etc etc
{
enemyTimer = 0
var enemy = _root.attachMovie("EnemyShip", "EnemyShip" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
enemies.push(enemy);
}
`
|
|
|
metadata
I just need to find where the explosion images are. It’s not in the source\_files I downloaded.
|
|
|
metadata
I have a similar problem. The ship and missile objects (both player and Enemy) wont interact with each other. I’ve gone through all the code several times and there are no errors, but the Enemyship will not explode nor will the missiles disappear! I think it has some thing to do with the hitTests I used, but I’m not sure.
|