Jump to content

Question about stage


YuShaN
 Share

Recommended Posts

Hi everyone. I making a game with many stage. I make 5 character can chose before start game. So I write 5 stage game for 5 player. But if I do like it I will have 5 big file game(only diffrent player). So I can write 5 small file for 5 character and 1 big file for gameplay(enemy, boss, gameplay....) ? I need any way make my code simpler. Thank you

Link to comment
Share on other sites

Hi YuShaN,

 

It is hard for me to understand what you mean, but I want to try. Please let me know if I do not understand.

 

If you want to have different "screens" you can use Phaser.StateManager. Is found in game.state.

 

Phaser.State.init() can have parameters passed in. You can pass the character name into init() with Phaser.StateManager.start().

 

This way, you can have different players show up in the same stage.

 

Is that what you mean? I have put code below to show what I mean.

var game = new Phaser.Game(width, height, Phaser.AUTO, 'game-window-element', null);var characterSelect = function(game) {};characterSelect.prototype = {    preload: function() {},        update: function() {        var characterName = 'Character A';        this.game.state.start('Gameplay', true, false, characterName);    }};var gameplay = function(game) {};gameplay.prototype = {    init: function(characterName) {         console.log('character is ' + characterName);    },    create: function() {},    update: function() {}};game.state.add('Character Select', characterSelect, false);game.state.add('Gameplay', gameplay, false);game.state.start('Character Select');
Link to comment
Share on other sites

 

Hi YuShaN,

 

It is hard for me to understand what you mean, but I want to try. Please let me know if I do not understand.

 

If you want to have different "screens" you can use Phaser.StateManager. Is found in game.state.

 

Phaser.State.init() can have parameters passed in. You can pass the character name into init() with Phaser.StateManager.start().

 

This way, you can have different players show up in the same stage.

 

Is that what you mean? I have put code below to show what I mean.

var game = new Phaser.Game(width, height, Phaser.AUTO, 'game-window-element', null);var characterSelect = function(game) {};characterSelect.prototype = {    preload: function() {},        update: function() {        var characterName = 'Character A';        this.game.state.start('Gameplay', true, false, characterName);    }};var gameplay = function(game) {};gameplay.prototype = {    init: function(characterName) {         console.log('character is ' + characterName);    },    create: function() {},    update: function() {}};game.state.add('Character Select', characterSelect, false);game.state.add('Gameplay', gameplay, false);game.state.start('Character Select');

Thank you. But I mean is I had completed a game with a character in a file game.js. Now I want have 5 characters. I rewrite 5 file game.js with 5 characters. But I will have 5 big file game.js. Have any ways I just need write a file game.js and 5 file characters I can change when game start?

Link to comment
Share on other sites

Do you mean, you want to make characters to own files? In that case you need to make own class for every character and then just call when needed in game.js

 

http://examples.phaser.io/_site/view_full.html?d=sprites&f=extending+sprite+demo+1.js&t=extending%20sprite%20demo%201

 

http://www.html5gamedevs.com/topic/6896-general-functionality-and-inheritance/

Link to comment
Share on other sites

Do you mean, you want to make characters to own files? In that case you need to make own class for every character and then just call when needed in game.js

 

http://examples.phaser.io/_site/view_full.html?d=sprites&f=extending+sprite+demo+1.js&t=extending%20sprite%20demo%201

 

http://www.html5gamedevs.com/topic/6896-general-functionality-and-inheritance/

Yeah! but how about if I make 5 diffrent style move and attack for each character?

Link to comment
Share on other sites

I would make them as own functions in player class file.

 

Like this:

create: function() {// stuff here...},update: function(){...and stuff here...},attack1: function (){// define thigs for this attack here},attack2: function (){// define thigs here}

And then just call again when needed.

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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