RE: [Flashcoders] OOP advice for game
-Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Cédric Néhémie Sent: Sunday, November 05, 2006 5:52 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game You may prefer a more common syntax for the singleton access method, like getInstance for example. In ActionScript (as opposed to Java), I think it's better to use a property: class Singleton { private function Singleton() { } public static function get instance():Singleton { if (_instance == undefined) { _instance = new Singleton(); } return _instance; } private static var _instance:Singleton; } // Elsewhere: Singleton.instance; // Returns the only instance of Singleton. Personally I would prefer an EventDispatcher rather than the Observer Yes. EventDispatcher is everywhere in AS3.0, so might as well start using it now. pattern, creating events like onWindChange, onRainChange, etc..., and a WeatherEvent object carrying the new weather values. Generally in the code that Macromedia/Adobe writes, event names dont have on as part of the name, but a function responding to them might, e.g.: WeatherManager.instance.addEventListener(windChange, Delegate.create(this, onWindChange)); Or, in AS3.0: WeatherManager.instance.addEventListener(windChange, onWindChange); -- Mike Keesey ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
Ah brilliant - thanks James, much appreciated!! Will have to look up what this mx.utils.Delegate malarkey means though... Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 09:22 To: Flashcoders mailing list Subject: RE: [Flashcoders] OOP advice for game actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
It's a life saver in AS 2.0 It basically solves the problem of function scope in AS 2.0 (something that AS 3.0 comes with as standard - yay) In this case, it means that the global function setInterval knows where to locate and call the function (inside the class) - and also knows where to clear it when you want to clear it. I don't actually understand *why* this implementation for setInterval works - it doesn't really make sense... but then there's soo much about AS 2.0 that doesn't make sense... AS 3.0 is a tidy bedroom compared to AS 2.0's sloppy student digs... J Paul Steven wrote: Ah brilliant - thanks James, much appreciated!! Will have to look up what this mx.utils.Delegate malarkey means though... Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 09:22 To: Flashcoders mailing list Subject: RE: [Flashcoders] OOP advice for game actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search
RE: [Flashcoders] OOP advice for game
Thanks James, sounds good enough to me and seems to work nicely. Many thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 10:44 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game It's a life saver in AS 2.0 It basically solves the problem of function scope in AS 2.0 (something that AS 3.0 comes with as standard - yay) In this case, it means that the global function setInterval knows where to locate and call the function (inside the class) - and also knows where to clear it when you want to clear it. I don't actually understand *why* this implementation for setInterval works - it doesn't really make sense... but then there's soo much about AS 2.0 that doesn't make sense... AS 3.0 is a tidy bedroom compared to AS 2.0's sloppy student digs... J Paul Steven wrote: Ah brilliant - thanks James, much appreciated!! Will have to look up what this mx.utils.Delegate malarkey means though... Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 09:22 To: Flashcoders mailing list Subject: RE: [Flashcoders] OOP advice for game actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders
Re: [Flashcoders] OOP advice for game
Hi Paul, To resolve the setInterval scope issue you could use the second setInterval syntax (undocumented in the Flash doc) : weatherTimer = setInterval(this, changeWeather, 5000); About the 80s time limit, if you target your swf to version 8, you could use the setTimeout method witch is perfect for that ;) (work the same as setInterval). Cédric Paul Steven wrote: Thanks James, sounds good enough to me and seems to work nicely. Many thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 10:44 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game It's a life saver in AS 2.0 It basically solves the problem of function scope in AS 2.0 (something that AS 3.0 comes with as standard - yay) In this case, it means that the global function setInterval knows where to locate and call the function (inside the class) - and also knows where to clear it when you want to clear it. I don't actually understand *why* this implementation for setInterval works - it doesn't really make sense... but then there's soo much about AS 2.0 that doesn't make sense... AS 3.0 is a tidy bedroom compared to AS 2.0's sloppy student digs... J Paul Steven wrote: Ah brilliant - thanks James, much appreciated!! Will have to look up what this mx.utils.Delegate malarkey means though... Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 09:22 To: Flashcoders mailing list Subject: RE: [Flashcoders] OOP advice for game actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
Thanks Cedric With regards the 80 seconds time limit, I have a timer on screen that displays the time remaining so this must update every second. I will look into this setTimeout function - perhaps that will do the job!! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cédric Néhémie Sent: 05 November 2006 11:47 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Hi Paul, To resolve the setInterval scope issue you could use the second setInterval syntax (undocumented in the Flash doc) : weatherTimer = setInterval(this, changeWeather, 5000); About the 80s time limit, if you target your swf to version 8, you could use the setTimeout method witch is perfect for that ;) (work the same as setInterval). Cédric Paul Steven wrote: Thanks James, sounds good enough to me and seems to work nicely. Many thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 10:44 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game It's a life saver in AS 2.0 It basically solves the problem of function scope in AS 2.0 (something that AS 3.0 comes with as standard - yay) In this case, it means that the global function setInterval knows where to locate and call the function (inside the class) - and also knows where to clear it when you want to clear it. I don't actually understand *why* this implementation for setInterval works - it doesn't really make sense... but then there's soo much about AS 2.0 that doesn't make sense... AS 3.0 is a tidy bedroom compared to AS 2.0's sloppy student digs... J Paul Steven wrote: Ah brilliant - thanks James, much appreciated!! Will have to look up what this mx.utils.Delegate malarkey means though... Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 09:22 To: Flashcoders mailing list Subject: RE: [Flashcoders] OOP advice for game actually the private func there might need to be changed to public. I've had headaches getting intervals to clear properly, and this way works for us :) Good luck! J I'm assuming you're using AS 2.0 - inside WeatherManager.as: class WeatherManager { // private var to hold interval private var weatherTimer; // constructor public function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } // weather change func private function changeWeather() { // change the weather } // clear interval func public function cleanUp() { clearInterval(weatherTimer); } } // hope that helps! I have done as you suggested and have created separate classes for the balloon, ball, scoreboard and clouds and this all seems to work fine. The design pattern is based on an Observer pattern where these separate objects register themselves as observers of a WeatherManager object. I have created a WeatherManager.as class that broadcasts any updates to the weather to the observers. Now I need to have the WeatherManager periodically change the weather conditions. I was thinking it should have some sort of internal timer and every say 5 seconds, it will amend the weather conditions. Not sure how best to create an internal timer - would I just use setInterval within the WeatherManager class? Or would it be better to create a timer class and have a loop to continually check this timer? I have had real problems in the past using setInterval in that they don't seem to clear. The game itself is time based and there is a time limit of 80 seconds so there will need to be a timer for this too. Not sure if best to use just one timer for dealing with both or just let the WeatherManager have its own timer and at the beginning of the game just start its timer and leave it to do its updates independently of the main game timer Any suggestions most appreciated Thanks Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: 04 November 2006 17:52 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe
RE: [Flashcoders] OOP advice for game - use of sound effects
Another aspect of the game I need to deal with is the sound effects. Previously to play sounds in my games I simply imported the sound files into the library, gave them a linkage name them put the following code on the first frame of my movie for each sound effect. cheer_Sound = new Sound(); cheer_Sound.attachSound(cheer_sfx); Play_Cheer_Sound = function() { cheer_Sound.start(); } As I am using this game as a learning exercise to write a game using OOP, I wondered if there is a better way to deal with all the sound effects. Basically there are about 12 different sound effects, and I basically just need to be able to make a call to play a particular sfx when required. The various objects need to be able to call the sfx. For example the WeatherManager class may want to play a wind sfx when the wind speed changes to a higher speed. Is this something I should write a separate class for or is the above the way to do it still? Many thanks Paul ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game - use of sound effects
Hey Paul, You're spoiling the fun for yourself by asking how to do this stuff ;) Work it out, and be proud of it..! J Paul Steven wrote: Another aspect of the game I need to deal with is the sound effects. Previously to play sounds in my games I simply imported the sound files into the library, gave them a linkage name them put the following code on the first frame of my movie for each sound effect. cheer_Sound = new Sound(); cheer_Sound.attachSound(cheer_sfx); Play_Cheer_Sound = function() { cheer_Sound.start(); } As I am using this game as a learning exercise to write a game using OOP, I wondered if there is a better way to deal with all the sound effects. Basically there are about 12 different sound effects, and I basically just need to be able to make a call to play a particular sfx when required. The various objects need to be able to call the sfx. For example the WeatherManager class may want to play a wind sfx when the wind speed changes to a higher speed. Is this something I should write a separate class for or is the above the way to do it still? Many thanks Paul ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
Undocumented? Maybe you meant documented? http://livedocs.macromedia.com/flash/8/main/1766.html quote setInterval function setInterval(functionReference:Function, interval:Number, [param1:Object, param2, ..., paramN]) : Number setInterval(objectReference:Object, methodName:String, interval:Number, [param1:Object, param2, ..., paramN]) : Number /quote And further down on that page there's a complete example. And the weatherInterval property should be private. There is no problem whatsoever with private properties and setInterval. I use them all the time. You should consider making the WeatherManager class a Singleton as well. regards, Muzak - Original Message - From: Cédric Néhémie [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Sunday, November 05, 2006 12:46 PM Subject: Re: [Flashcoders] OOP advice for game Hi Paul, To resolve the setInterval scope issue you could use the second setInterval syntax (undocumented in the Flash doc) : weatherTimer = setInterval(this, changeWeather, 5000); About the 80s time limit, if you target your swf to version 8, you could use the setTimeout method witch is perfect for that ;) (work the same as setInterval). Cdric Paul Steven wrote: Thanks James, sounds good enough to me and seems to work nicely. Many thanks Paul ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game - use of sound effects
Yeah good point James. Though I am not asking for code, just direction from those with experience. Guess trying to re-write a game in a day at the same time as trying to learn a new subject is a bit ambitious. I had pretty much finished the game but the code is just one huge class, and all the pseudo 3D movement is totally fudged as the graphics (fish eyed view) do not help with coding 3D movement. Anyway I decided to start again from scratch and try and do it in a more organised manner. Here is the version of the game that I had nearly completed. Lots of bugs but you will get the idea http://www.mediakitchen.co.uk/rugby_game15.html The 3D effect of moving down the pitch was done by just scaling the background / pitch image with values that I got by trial and error and its just not good enough to polish things off. Hence I am trying to recreate the pitch entirely with code http://www.mediakitchen.co.uk/move_pitch.html Then I will add a camera. http://www.mediakitchen.co.uk/scaling_camera.html Anyway as I said, this all has to be completed today which is why I cheekily asked for some direction. I will probably just do the sounds the way I previously done them for now and research this at a later date. Ok time to create the 3D game environment Cheers Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 12:47 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game - use of sound effects Hey Paul, You're spoiling the fun for yourself by asking how to do this stuff ;) Work it out, and be proud of it..! J Paul Steven wrote: Another aspect of the game I need to deal with is the sound effects. Previously to play sounds in my games I simply imported the sound files into the library, gave them a linkage name them put the following code on the first frame of my movie for each sound effect. cheer_Sound = new Sound(); cheer_Sound.attachSound(cheer_sfx); Play_Cheer_Sound = function() { cheer_Sound.start(); } As I am using this game as a learning exercise to write a game using OOP, I wondered if there is a better way to deal with all the sound effects. Basically there are about 12 different sound effects, and I basically just need to be able to make a call to play a particular sfx when required. The various objects need to be able to call the sfx. For example the WeatherManager class may want to play a wind sfx when the wind speed changes to a higher speed. Is this something I should write a separate class for or is the above the way to do it still? Many thanks Paul ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
Thanks Muzak I think the WeatherManager is a Singleton - well thats what it said in the book:) import Observable; import WeatherMessage; class WeatherManager extends Observable { // --- // Constructor // --- private function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } public static function getWeather():WeatherManager { if (weather == null) { weather = new WeatherManager(); } return weather; } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: 05 November 2006 13:03 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Undocumented? Maybe you meant documented? http://livedocs.macromedia.com/flash/8/main/1766.html quote setInterval function setInterval(functionReference:Function, interval:Number, [param1:Object, param2, ..., paramN]) : Number setInterval(objectReference:Object, methodName:String, interval:Number, [param1:Object, param2, ..., paramN]) : Number /quote And further down on that page there's a complete example. And the weatherInterval property should be private. There is no problem whatsoever with private properties and setInterval. I use them all the time. You should consider making the WeatherManager class a Singleton as well. regards, Muzak - Original Message - From: Cédric Néhémie [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Sunday, November 05, 2006 12:46 PM Subject: Re: [Flashcoders] OOP advice for game Hi Paul, To resolve the setInterval scope issue you could use the second setInterval syntax (undocumented in the Flash doc) : weatherTimer = setInterval(this, changeWeather, 5000); About the 80s time limit, if you target your swf to version 8, you could use the setTimeout method witch is perfect for that ;) (work the same as setInterval). Cdric Paul Steven wrote: Thanks James, sounds good enough to me and seems to work nicely. Many thanks Paul ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
Paul Steven wrote: Thanks Muzak I think the WeatherManager is a Singleton - well that’s what it said in the book:) import Observable; import WeatherMessage; class WeatherManager extends Observable { // --- // Constructor // --- private function WeatherManager() { weatherTimer = setInterval(mx.utils.Delegate.create(this, changeWeather), 5000); } public static function getWeather():WeatherManager { if (weather == null) { weather = new WeatherManager(); } return weather; } You may prefer a more common syntax for the singleton access method, like getInstance for example. Personally I would prefer an EventDispatcher rather than the Observer pattern, creating events like onWindChange, onRainChange, etc..., and a WeatherEvent object carrying the new weather values. It'll be more flexible if you want to add more weather phenomenon at a later time. My two euro cents. Undocumented? Maybe you meant documented? Thanks Muzak to rectify me, some memory holes... Cédric ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
Hey, Most of what you've written here sounds good. You definitely have the ideas right. A couple of the questions you're asking that can only really be answered in context of your game further down the line. One of the best things about OOP dev is that you can always keep tweaking the relationships your objects have with relative ease. I think you should just dive in and start making it happen, evolve it as you go. The more OOP projects you do, the better you'll get at judging the relationships before you begin. Specific answers below: Hi there I am making a rugby game in Flash 8 and am trying to get to grips with AS2 and OOP structuring of the code. For example, the balloon is animating continually so would need to know the current wind speed and direction say every 1/10 of a second. Therefore would I need to get my balloon object, query the current weather conditions every 1/10 second? Or would it be better to have the balloon object to have its own wind speed and wind direction property which is updated only when the weather manager makes a change to the wind speed and direction? This sounds better. Look into event listeners. It'd be best to have all these objects have their own wind speed properties, and to listen for updates to the weather object. This can be done with an event dispatcher and listeners. I guess it would be a similar situation for all the other weather influenced objects hence they would all have properties for wind speed and wind direction - does this sounds a good approach? If the weather manager is responsible for updating the wind speed and direction properties of all these objects, do I first need to create these objects then pass a reference to them to the weather manager when I create the weather manager? Or is there a way to broadcast a change in the weather conditions that all objects can receive? With regards the weather manager changing the weather conditions periodically, would it be better for it to have some sort of internal timer that decides when a change is made This sounds best on paper. Again, you might find you need to evolve it later. Good luck! ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
Or would it be better to have the balloon object to have its own wind speed and wind direction property which is updated only when the weather manager makes a change to the wind speed and direction? This is the way to go. The weather manager should dispatch an event each time it changes. The balloon (and other instances that need it) would listen to the events it is interested in. regards, Muzak ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] OOP advice for game
Thanks James and Muzak You have been most helpful. I have now found a nice chapter on Observer patterns in an AS2 book. Cheers Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: 04 November 2006 16:25 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game Or would it be better to have the balloon object to have its own wind speed and wind direction property which is updated only when the weather manager makes a change to the wind speed and direction? This is the way to go. The weather manager should dispatch an event each time it changes. The balloon (and other instances that need it) would listen to the events it is interested in. regards, Muzak ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] OOP advice for game
Yeah, I made a little game myself and use the classes FoodPiece, Snake, and GameWorld and SnakeGame. Meaning that SnakeGame handles all the stuff such as start/stop game, score counting. The GameWorld is responsible for all the drawing, and calling the update method of the Snake instance, which will then have dedicated code to update itself. Works nicely! Weyert ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com