Ninjadoodle Posted September 2, 2014 Share Posted September 2, 2014 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! Quote Link to comment Share on other sites More sharing options...
enpu Posted September 2, 2014 Share Posted September 2, 2014 I would do it like this:this.ball = new game.Sprite('ball.png'); Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted September 2, 2014 Author Share Posted September 2, 2014 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.