Jump to content

Select different Players/plane in Flying Dog


redrory
 Share

Recommended Posts

Good day guys,

 

I'm customizing Flying Dog, I've gone throught the tutorials and documentation.

 

Still a bit unclear on how to implement something.

 

After the round ends, when I click restart. I want another plane to be used for the reminder of the game.

 

I know I have to add it to assets.js, and then objects.js under this.sprite.

 

However I'm not sure how to enable the new plane on a button action or restart.

 

On restart button click - it's loads game.system.setScene(SceneGame);

 

So I was trying to however load another scene, however I think that would be overkill, all I want is a different player/sprite for the same scene.

 

Any assistance would be much appreicated.

 

 

Cheers

Link to comment
Share on other sites

You can set global variables to scene object, like this:

game.SceneMain.player = 1;

And then use that to change your player sprite, something like this:

// Restart buttonrestartButton.click = function() {    // Switch player variable between 0 and 1    if (game.SceneMain.player === 0) game.SceneMain.player++;    else game.SceneMain.player = 0;    game.system.setScene('Main');};// Player spritethis.sprite = new game.Sprite('player' + game.SceneMain.player + '.png');

Did that make sense to you?

Link to comment
Share on other sites

Hey,

 

Thanks for your reply,

 

I have a high level understanding.

A few questons:

 

When I try to set the global variable - SceneMain or SceneGame

game.SceneMain.player = 1;

I get the following error - Cannot read property 'player' of undefined

 

Also the player sprite line - is that handled during scenes or objects?

Link to comment
Share on other sites

Hey,

 

So I fixed that undefined erorr.

 

I've added the Sprite code to objects.js, my issue is that it doesn't seems to be incrementing by the time it gets to the new or restarted scene.

 

I've added the global variable game.scene.player = 1; to my objects.js right above where I add my sprites.

 

My question is - in my restartButton, when I increments how does that ++ value reach back to my sprite to then show the new player.

 

scenes.js

this.restartButton = new game.Sprite('media/restart.png', game.system.width / 2, game.system.height / 2 + 225, {            anchor: {x:0.5, y:0.5},            scale: {x:0, y:0},            interactive: true,            mousedown: function() {                game.analytics.event('restart');                console.log('Before number ' + game.scene.player);                game.scene.player = 1;                if (game.scene.player === 0) game.scene.player++;                else game.scene.player = 0;                game.system.setScene(SceneGame);                console.log('Random number is ' + game.scene.player);            }        });

objects

   game.scene.player = 1;        this.sprite = new game.MovieClip([            game.Texture.fromImage('media/player' + game.scene.player + '.png'),            game.Texture.fromImage('media/player' + game.scene.player + '.png'),        ]);
Link to comment
Share on other sites

When I do that, I get the following :  Uncaught TypeError: Cannot read property 'player' of undefined

 

As i assume I don't have scene by that name.

 

My scene name seems to be game.scene - as I use the following to add buttons to it.

game.scene.stage.addChild(box);

I'm thinking do I have to create a SceneMain scene or can I use the one that I have below?

Link to comment
Share on other sites

Hey,

 

So I've created another scene, pretty much by copying the default scene.

 

So on my button click I'm now loading that different scene, which is half the problem however, I'm still unsure how to load a different sprite within that new scene. Mostly because objects aren't handled within the scene.js but within objects.

 

I'm not even seeing, where I'm calling my sprite from scene, for me to me able to call a different one.

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