Jump to content

couple of questions


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');
            //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);

function update(){
                ship.body.x += -7;

                ship.body.x += 7; 

function addMenu(){

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


  • Recently Browsing   0 members

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