Jump to content

couple of questions


coelacanth
 Share

Recommended Posts

var game = new Phaser.Game(1024,768,Phaser.AUTO, 'space game', {preload: preload, create: create, update: update});

var ships;
var ship;

function preload(){
            game.load.image('spaceship', 'assets/spaceship_sprite.png');
            game.load.image('menu', 'assets/menu.png');

        }

function create(){
            
            ship = game.add.sprite(500,680, 'spaceship');
            game.physics.arcade.enable(ship);
            ship.scale.setTo(0.5,0.5);
           
            //ship2 = myship(game, 'spaceship', 600, 200);
                 
            ships = game.add.group();
            for (var i = 0; i < 0; i++){
                //var sx = 100;
                ships.create(600, 200, 'spaceship');
                //myship(game, 'spaceship', 500+sx, 200);
                //sx += 100;

                //game.add.sprite(500, 200, 'spaceship');
            }
            
            cursors = game.input.keyboard.createCursorKeys();
            
            pauseKey = game.input.keyboard.addKey(Phaser.Keyboard.ONE);
            pauseKey.onDown.add(addMenu, this);
            game.input.keyboard.removeKeyCapture(Phaser.Keyboard.ONE);
           
        }

function update(){
            if(cursors.left.isDown){
                ship.body.x += -7;
                
            }

            if(cursors.right.isDown){
                ship.body.x += 7; 
                
            }
         
        }

function addMenu(){
    game.add.sprite(100,100,'menu');
}

1. I want to add a few sprites of a ship into the 'ships' group. But for loop doesn't work. I'm folowing this example: https://phaser.io/examples/v2/groups/add-a-sprite-to-group#gv

even If I try to add object from external script. I've tried to create a few ships of 'myship' without the 'for loop' and it works fine.

2. If I uncomment this line: //ship2 = myship(game, 'spaceship', 600, 200), my 'ship' doesn't move (key input doesn't work).

What am I doing wrong? Sorry for my poor english.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...