Jump to content

Communicating between init and update?


Ninjadoodle
 Share

Recommended Posts

Hi Guys

 

Here is a quick question.

 

Normally when setting up  sprite inside a scene's init function I would go ...

 

var ball = new game.Sprite('ball.png');

 

But, what if I want it to communicate with the update function?

 

since "var ball" makes it local to the init function, is there any harm, in not putting var i front of it and making it global?

 

Is this the correct way to do things in panda?

 

Thank you in advance!

Link to comment
Share on other sites

Hi @enpu

 

Thank you for the reply! Do I still need to do this if I made an object?

 

Ball = game.Class.extend({
init: function() {
this.sprite = new game.Sprite('ball.png');
this.sprite.position.x = 240*r;
this.sprite.position.y = 160*r;
 
layerFg.addChild(this.sprite);
},
});

 

Then inside the scenes init function ...

 

this.ball = new Ball();

 

What exactly does putting 'this.ball' as opposed to just putting ball?

 

Thank you again in advance!

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