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 =;
            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:

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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.