This is my first android game, I appreciate all the help. I want to define 4 spawning zones starting from out of the screen (left, right, up and down). Enemies coming from this areas have a fixed trajectory to the center, when this enemies come into the screen the player can move them to a specific corner, but if it lets go of it a new trajectory has to be calculated so it keeps moving to the center.

I am having trouble thinking on how to define this 4 areas, there is also 4 types enemies (they are the same, but they have a different color), should I place this 4 enemies on an arrayList ?. If I know how to define this 4 spawning areas which randomly decides where to spawn I then don't exactly know how to define the fixed trajectory to the center. Also, need to lower the speed to a more adecuate one. (Sorry if this seems like a lot am asking)

Current code looks like this (I am using AndEngine library):

public class gameEscene extends baseScene {

    // Regions for images
    private ITextureRegion BackgroundRegion;
    private ITextureRegion Corner;
    private ITextureRegion Center;
    private ITextureRegion Marco;
    // Sprites
    private Sprite spriteBackground;
    private Sprite spriteCorner;
    private Sprite spriteCenter;
    private Sprite spriteMarco;

    //  Enemies
    private ArrayList<Enemies> listEnemies;
    private ITextureRegion regionEnemy;
    //  Time to generate enemies
    private float timeEnemies = 0;              //  Counter
    private float   TIME_LIMIT  =   2.5f;       //  Every 2.5s it creates

    public void loadResources() {
        BackgroundRegion = loadImage("black.jpg");
       Corner = loadImage("Corner_T.png");
        Center = loadImage("Center.png");
        Marco = loadImage("m.png");
        regionEnemy = loadimage("ship.png");

    private void createEnemies() {
        for (int x = 700; x <= 1200; x += 100) {
            for (int y = 100; y <= 700; y += 100) {
                Sprite ship = loadSprite(x, y, regionEnemy);
                Enemies enemy = new Enemies(ship);


    public void createScene() {
        listEnemies = new ArrayList<>();
        spriteBackground = loadSprite(GameControl.CAMARA_WIDTH/2, GameControl.CAMARA_HEIGHT/2, BackgroundRegion);
        spriteCorner = loadSprite(GameControl.CAMARA_WIDTH/2, GameControl.CAMARA_HEIGHT/2, Corner);
        spriteCenter = loadSprite(GameControl.CAMARA_WIDTH/2, GameControl.CAMARA_HEIGHT/2, Center);
        spriteMarco = loadSprite(GameControl.CAMARA_WIDTH/2, GameControl.CAMARA_HEIGHT/2, Marco);

    public void onBackKeyPressed() {
        // Regresar al menú principal

    public sceneType getSceneType() {
        return sceneType.GAME_SCENE;

    public void liberateScene() {

    public void liberateResources() {
        BackgroundRegion = null;
        Corner = null;
        Center = null;
        Marco = null;
        regionEnemy = null;

    protected void onManagedUpdate(float pSecondsElapsed)   {

        timeEnemies +=  pSecondsElapsed;        //  Acumulates time
        if  (timeEnemies>TIME_LIMIT)    {   //  Time has completed
            tiemeEnemies    =   0;
            Sprite spriteEnemy  =   loadSprite(GameControl.CAMARA_WIDTH+regionEnemy.getWidth(),
                    (float)(Math.random()*GameControl.CAMARA_HEIGHT-regionEnemy.getHeight())    +

            Enemies newEnemy = new Enemies(spriteEnemies);
            listEnemies.add(newEnemy);  //  Adds it to the scene
            attachChild(newEnemy.getSpriteEnemy()); //  Adds it to the list

        //  Updates every enemy and sees if any has gotten out of the screen
        for (int    i=listEnemies.size()-1; i>=0;   i--)    {
            Enemies enemy   =   listEnemies.get(i);
            enemy.mover(-10, 0);
            if  (enemy.getSpriteEnemy().getX()<-enemy.getSpriteEnemy().getWidth())  {
                detachChild(enemy.getSpriteEnemy());        //  Deletes it from the scene
                listEnemies.remove(enemy);                                                                  //  eliminates it from the list
            //  Checks the collision of enemy with another sprite

            if  (spriteCenter.collidesWith(enemy.getSpriteEnemy())) {



Enemies class looks like this:

public class Enemies {

    private Sprite sprite;

    public Enemies(Sprite sprite) {
        this.sprite = sprite;

    public Sprite getSpriteEnemy() {
        return sprite;

    public void setSprite(Sprite sprite) {
        this.sprite = sprite;

    public void mover(int dx, int dy) {
        sprite.setPosition( sprite.getX()+dx, sprite.getY()+dy );


Thanks in advance for the help.

Edit: Screenshot of idea

Game concept

  • \$\begingroup\$ I'm finding it hard to visualise your problem. Could you perhaps draw it, or post an annotated screenshot? \$\endgroup\$
    – Anko
    Oct 24, 2015 at 0:00
  • \$\begingroup\$ Sure, I put an image of the idea above. So, enemies will be coming from this 4 areas (coming from outside the screen), with a fixed trajectory to the center image/sprite, the user has to move them to their corresponding color, if the player doesn't place if in the corresponding color and drops it on a blank space, it still has to recalculate trajectory to the center. Sorry If my idea didn't come thru, and thanks in advance. \$\endgroup\$
    – OrangeHat
    Oct 24, 2015 at 0:58

1 Answer 1


It looks to me like you are not saving the enemies locations in their class, try using a random to generate Their location (from presets ranges) and then using ArrayLists and Itteraters together to spawn and ammend their positions?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .