Jump to content

A few more questions about Phaser


toto88x
 Share

Recommended Posts

Hello,

 

I almost finished my first Phaser game!  Below are my questions.

 

1) How can I change the volume of one sound in my game? And what about all sounds? Something like

- var hit = game.add.audio('hit');

- hit.volume = 0.5;

 

2) How can I change the font size of a text? Because changing fontSize: '32px' doesn't seems to work.

- game.add.text(w/2, h-35, 'this is a test', { fontSize: '18px', fill: '#fff', align: 'center' });

 

3) When I do a game.state.start('GameOver'), should I clean all my variables to free memory? If so, is there a function automatically called before switching states?

 

4) I know about tween().to(), but isn't there something like tween().by()? This would be super handy to move a character by 100px, instead of moving him to character.x + 100px.

 

Thanks! :-)

Link to comment
Share on other sites

1) I haven't messed with volume on sounds yet, but both the Phaser.Sound and Phaser.SoundManager classes have a volume property.

 

2) See here for the available font properties:

http://www.goodboydigital.com/pixijs/docs/classes/Text.html

There is no fontSize property, you include that in the font property. eg: 18px Arial

 

3) Probably a good idea. A state object has it's create function called when switching to it, and if an existing state was there, the existing state has its shutdown function called.

 

4) Nope.

Link to comment
Share on other sites

Thanks a lot! A few comments:

 

1) Yes I've seen that, but I don't know how to make it work :-/

 

2) Perfect, it works! But it seems the fonts are somewhat blurry. Is this normal? What I'm doing: game.add.text(w/2, h/2, 'blurry text', { font: "18px Arial", fill: '#fff' });

 
3) shutdown works perfectly!
 
4) Ok, maybe in v1.2 then ^^
Link to comment
Share on other sites

4) I know about tween().to(), but isn't there something like tween().by()? This would be super handy to move a character by 100px, instead of moving him to character.x + 100px.

 

You can do this:

tween(sprite).to( { x: '+100' });

It will recognise +100 is a string and add 100px to the sprites current x position when the tween starts. Minus values work the same too.

Link to comment
Share on other sites

You can do this:

tween(sprite).to( { x: '+100' });

It will recognise +100 is a string and add 100px to the sprites current x position when the tween starts. Minus values work the same too.

 

Super nice, thanks!

 

 

I still don't know how to change the volume of sounds in the game (either a specific sound, or for all of them). Can anyone help me on this?

Link to comment
Share on other sites

  • 2 weeks later...
Hi all, I have also some questions about Phaser, dunno need to create a new topic for that or no, but will ask here:
 
1) first two parameters don't work in tilemapLayer function
x - X position of the new tilemapLayer.
y - Y position of the new tilemapLayer.
layer = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0);
 
I use that example:
 
write:
layer = game.add.tilemapLayer(50, 50, 800, 600, tileset, map, 0);
 
and I don't see any changes. I just want to move the tilemapLayer to x = 50; y = 50.
 

also

layer.x = 50;layer.y = 50;
don't work for me :) let me know please what need to do.
 
2) Rich said, "In 1.1.4 I've added the ability to render multiple layers to a single canvas, but that won't be ready until end of this month."
does anyone know is this available or not now? I mean of course dev-branch version of Phaser.
 
Link to comment
Share on other sites

about the 1st of my item - I found a temporary solution via group.

 

if you want to move your tilemapLayer - you can just place him into the group and move it.

var screen = game.add.group();layer = screen.add(game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0));screen.x = 50;screen.y = 50;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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