Help please - display objects

How can Hey I get my items to display? In my class, I have a function that creates objects and they fall at random in the rows, but showing only 1. And I used trace(); to test how onstage and he says 4 but only 1 starting to fall.

I think that there is something wrong with the method I use to create the objects in lines.

Here is the code:

package

{

import flash.display.MovieClip;

import flash.events.Event;

import flash.events.MouseEvent;

import flash.events.TimerEvent;

import flash.utils.Timer;

SerializableAttribute public class Main extends MovieClip

{

public var enemyA:Array = [];

public var birdA:Array = [];

public var rowNum:int = 1;

private var gap: int = 100;

private var obj_no = 2;

public var timer: int = 0;

public var time_limit = 10;

public var TimerSpeed:uint = 1000;

public var MyTimer:Timer = new Timer (TimerSpeed);

public var enemy1:mychar = new mychar();

public var TheBird:BirdChar = new BirdChar();

public void Main()

{

The constructor code

}

public void activateGameControls()

{

createEnemyF();

createBirdF();

this.addEventListener (Event.ENTER_FRAME, loopF);

MyTimer.addEventListener (TimerEvent.TIMER, TimerHandler);

MyTimer.start ();

}

public void deactivateGameControls()

{

addChild (TheBird);

addChild (enemy1);

removeChild (TheBird);

removeChild (enemy1);

}

public void createEnemyF()

{

for (var i: int = 0; i < rowNum; i ++)

{

for (var j: int = 0; j < obj_no; j ++)

{

enemy1.x = Math.Random () * stage.stageWidth - enemy1.width;

enemy1.y = - I * (gap + enemy1.height) - 30.65;

enemyA.push (enemy1);

addChild (enemy1);

trace (enemy1.x, enemy1.y);

}

}

}

public void createBirdF()

{

TheBird.x = 270,95;

TheBird.y = 350.95;

birdA.push (TheBird);

addChild (TheBird);

}

public void loopF(event:Event)

{

updateEnemyPositionsF();

updateBirdPositionsF();

hitTestF();

}

public void updateEnemyPositionsF()

{

enemy1.y += 2;

}

public void updateBirdPositionsF()

{

TheBird.x = mouseX;

}

public void hitTestF()

{

If (TheBird.hitTestObject (enemy1))

{

gotoAndPlay (5);

deactivateGameControls();

trace ("The Bird Hit Enemy 1'");

}

}

function TimerHandler(event:TimerEvent)

{

timer += 1;

If (timer is 50)

{

MyTimer.removeEventListener (TimerEvent.TIMER, TimerHandler);

MyEventArgs;

gotoAndPlay (4);

}

ElseIf (timer == time_limit)

{

gotoAndPlay (5);

deactivateGameControls();

}

}

}

}

(1) what is mychar? Given the way you use it, it takes asigned class to a MovieClip symbol in your library

-the name suggests a kind of text, which is not appropriate

-the class names should begin with capital letter

-I would like the enemy name

(2) I noticed that you create only one instance of your enemy (new mychar())

-If you want multiple enemies to fall from the sky, you must create multiple enemies (in loop...)

(3) If you want to move each enemy, you need to store in the table. You can do this when they are created (in the loop for)

(4) you move your enemies by getting then one by one on the table and by incrementing the value 'y '.

(5) would definitely get rid of the variable "enemy1" - it's useless. Use enemyA instead - it can contain all your enemies

Explanation of my code:

// an array in which you will store references to your enemies
var enemyA:Array = [];

// constant defining how many enemies you want there to be
const MAX_ENEMIES:int = 10;

// loop for creation on your enemies
for(var i:int = 0; i < MAX_ENEMIES; i++) {

     // local variable to temporarily store current enemy we're adding
     var enemy:DisplayObject = new Enemy();

     // set enemy's x position, random from left edge to the right edge of the screen
     enemy.x = Math.random() * stage.stageWidth - enemy.width;

     // set enemy's y position, in his own row. each enemy is a row higher than the previous one
     enemy.y = - i * (gap + enemy.height) - 30.65;

     // add the enemy to the display list so he is visible on the stage
     addChild(enemy);

     // trace his position
     trace(enemy.x, enemy.y);

     // store the enemy in the array so we can address him later
     enemyA.push(enemy);
}

//then onEnterFrame or timer call updateEnemyPositions

function updateEnemyPositions():void {
     // loop for enemy movement - falling off the sky
     for(var i:int = 0; i < enemyA.length; i++) {

          // get a reference of i-th enemy in the array
          var enemy:DisplayObject = enemyA[i] as DisplayObject;

          // move enemy a bit more downwards
          enemy.y += 2;
     }
}

I really can't put it more simply, there cannot be any simpler. -Read 5 times and then try it.

I do not have the game for you, you must understand what I say and apply it to yourself, to your game. Otherwise you'll never be able to do it yourself, sorry.

Tags: Adobe Animate

Similar Questions

Maybe you are looking for