At 8/25/13 06:17 PM, Hagarth wrote:
Thanks for the answer.
Heres the code of `killing` enemies
for(var i=0; i <= j; i++) // Laço for, para verificação do Array dos inimigos, cria a variaável i começando em 0, e enquanto ela for menor que j(inimigos) ela adiciona mais um a i e verifica se colidiu com algum dos inimigos armazenados no Array, nas posições j.
if(enemies[i] != null && mapa.hero.hero.SwordArm.hitTestObject(enemies[i])) // Verifica se a posição i dos inimigos no Array j é diferente de null ( != - diferente ) e testa colisão dos inimigos com o braço da espada.
enemies[i].hp.scaleX -= 0.2; //Tira 0.2 de hp da barra de hp do inimigo
if(enemies[i].hp.scaleX <=0) // Verifica se o inimigo perdeu todo o hp pra poder remover do palco
Try to encapsulate things into the classes and use abstraction to your advantage.
If your enemies have a health variable, create a numeric variable that stores this health.
This makes it a lot easier to think about it.
It's not tied to some scale that can only take certain numbers or whatever.
This abstraction helps you to think about your problem, not the programming language.
To encapsulate this, use a setter and getter function to change the value of health.
In the setter for example, you can check if the health reaches zero, and dispatch an Event. (advanced stuff)
private var _health:int = 100;
public function set health (value:int):void
_health = value;
if(_health <= 0) trace("dead");
//do additional stuff like updating the health of the healthbar
public function get health ():int
Basically: If you want health, use health. If you want scale use scale.
You have the tools to be precise about what you want and do exactly that.
I created a var mortos to count enemies killed,
That's not necessary. You have your enemy objects in an array.
If one dies, remove it from the array.
If the array is empty, all enemies are gone.
and when it reaches the maximus spawned at lvl 1, i chance to lvl 2 thats in the frame 2 of mapa. At the moment i hit any enemy, the error starts to pop repeatidly, and sometimes it crashes the game, the main character starts to lose HP without colliding with the enemy.
Btw, don`t mind the comments on the code, it`s for my later reference x) as i`m new to AS.
By all means: English only.
Even if you're the only one reading them (you aren't) and I don't speak Portuguese.
At 8/25/13 06:42 PM, Hagarth wrote:
Btw, i still couldnt make the error go away, i rewrote the package to make those changes on the imports and the `this` but the error i still couldnt fix, where exactly i should put the removeEventListener?
The best idea: nowhere.
If you do not have an event listener in the first place, there's no need to remove it.
As said earlier, you should not add the ENTER_FRAME to every enemy anyway.
You have all the enemies in an array.
Call the method on each of those in your main game loop instead of letting them do their own thing.
how packages work
packages are folders, nothings fancy, nothing special