Jump to content

separate file in phaser and states ? just one line in main.js


espace
 Share

Recommended Posts

hi,

my desire is this :

  • have one file main.js
  • and have other files like background.js
  • call a variable like background in my main.js just in one line ...without be preocupated with preload, create, update and render

i want in fact, if i have modification on one var like background just edited one file and not do the modification at 3 times in my main.js (preload, create,render) is it possible ?

i have google a lot of this and i have found many solution but could you please give me a concrete example with this file ... thanks in advance

 

//main.js
var game = new Phaser.Game(w, h, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {
	game.load.image('rect','rect.png');
}

var background =[];


function create() {

	background.opponent=game.add.sprite(0,0,'rect');
	background.player=game.add.sprite(w2,0,'rect');

}

function update() {
	        background.opponent.tint=0xff4f4f
		background.opponent.width=w2
		background.opponent.height=h

		background.player.tint=0x25a7ba
		background.player.width=w2
		background.player.height=h

}

function render() {

}

 

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