• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Completely Resetting a Flash game

Contributor ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

Hi, I've got what I'm sure is a common requirement, but I'm not sure the best way to pull it off, and I have a feeling I'm not going to like the answers. I've looked this up before but didn't find enough of an answer for my circumstances. I apologize for the length of this post.

In summary: I've programmed an entire game from scratch, without using class files, and there's no menu yet, and I'm not sure how to reset the game without using class files or resetting every single thing manually.

I'm making a Flash tower defense game with a friend; I'm doing all the code. I'd never used Flash or Actionscript before, so I started off directly programming the gameplay, to figure out if I'd be able to do it. I've done everything from scratch so I didn't know where to start or the "right way" of doing anything, so I figured out as I went along, which went much better than I expected.

So now I've got the gameplay almost completely programmed, the art assets are essentially finished and game looks great and runs (reasonably) well (and the occasional performance problems are due to graphics rather than code), etc. I didn't know how to use class files in AS3 when I started making the game, and when I read up on them and realized you can't import the class files into the project and must open and edit them separately, I was livid and decided not to use them; I was happy with how the coding was going anyway.

So now we've got a game where as soon as you run it, it goes straight to the field and the game starts; we haven't implemented a menu yet. We've reached the point of playtesting and it's becoming a huge nuisance having to quit the SWF and reopen or recompile it every time we want to restart the game, so it's time to program a "Reset" button. I thought this would be as simple as making the stage go to a different frame and back to the first frame, but that doesn't work, so now I'm utterly stuck. It looks like the easiest way to reset a game is to load the entire "game" as an object (or something to that effect, I forget exactly what I've read), then you can unload and reload the game object to reset it? It also looked like it would require class files which I'm hoping to avoid.

I don't think it's feasible to manually remove everything from the stage, reset all the variables, and delete all event listeners and references so everything is reset/garbage collected properly.

Thinking about it more, I'm also not sure how I'm going to get a menu to load before the game in its current state. Maybe I can move all of the gameplay to the second frame and make the menu on the first frame?

So, is it possible to reset the game without involving class files? Any chance you can do it by switching between frames and I just implemented that wrong?

TOPICS
ActionScript

Views

8.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

the easiest way to reset everything is to reload your main swf's embedding html:

function resetF():void{

navigateToURL(new URLRequest("whatever.html"),"_self");

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 02, 2019 Jan 02, 2019

Copy link to clipboard

Copied

What if the game will be an iOS app with no embedded HTML file? I’d like to know the best way to structure a game with multiple levels and a main menu. Should I be making separate swfs and try to compile them into a single .ipa file? Should I be using a different scene for every different menu and level? Or does everything have to be done in one frame with one big chunk of code for the entire game, and everything organized into functions?

any advice would be appreciated. I’m using the 2019 release of Adobe Animate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Hi.

If you don't want to go for a complete OOP approach, the simplest way in my opinion to structure a game or app is to use the main timeline as a state machine.

For example:

Frame 1: Splash screen

Frame 2: Company logo

Frame 3: Main Menu

Frame 4: Stage selection

Frame 5: In-game

Frame 6: Win

Frame 6: Game Over

Frame 7: Rank

And so on.

So all you have to do is to change the current frame and things will be reset.

It all depends on how smartly you sctructure your code.

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

If you use the timeline approach, which I sometimes do, you could place the significant screens further apart, say frame 10, 20, 30, etc. Also use frame labels as the way to go to a section, that way if you change the frame numbers for some reason the navigation will still work.

Any design elements that are needed in all sections can be in layers that stretch all the way across the timeline.

If you do have the sections on consecutive frames, you could scale up the timeline to make it easy to select a given scene while you're working on it:

Screen Shot 2019-01-03 at 2.23.18 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

LATEST

It worked, thanks! For once (in Actionscript 3 at least) the simplest solution was the one that worked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Ok, can't wait to try this. Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

You don't need to use class files.  If you created content dynamically, then switching frames won't kill it off.  Dynamically created content has no true home on the timeline unless you nail it to something that is secured to it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

Ned Murphy wrote:

You don't need to use class files.  If you created content dynamically, then switching frames won't kill it off.  Dynamically created content has no true home on the timeline unless you nail it to something that is secured to it.

Okay thanks, but if I don't need to use class files, what do I do? That was the impression I got with the dynamically loaded content.

the easiest way to reset everything is to reload your main swf's embedding html:

function resetF():void{

navigateToURL(new URLRequest("whatever.html"),"_self");

}


Thanks, but this won't be practical when the game is finished with a main menu, so I'd rather avoid that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

What would class files do for you that makes you think you can't do anything without them?  What you might be best off doing is rethinking this as if you were just starting and figure out the overall game scheme, menu, gameplay (basic), and restarting and all, and make a simplified version of that overall scheme that works.  Then see if there is any way of melding your existing work as a module within that framework.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

I think the examples I saw had the gameplay code in a class file, and they would create an instance of the game class. Then to reset the game they'd dump and reload the game class? Something like that, now I can't find those specific examples.

Um, if I start over, I'm still not going to know how to reset the game. Not to mention we've put hundreds of hours into it so far over the last year, there are thousands of lines of code, and I'm not about to start over 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

I'm not saying start over.. I'm saying start anew, doing it the right way.  First develop the frame work, then add in the elements.  Have a stand-in for your game that has just the basic start and end characteristics to start with and get everything else working.  Then once you have that all sewn together, if you did it right, your game should fit in place of the basic version without a problem.

If you can't do that, then you need to spend more time as a developer.  You need to learn that you don't approach a design by first creating the nail and then deciding you want to build a house around it.  In most anything you do (successfully), the preparation is always important and often involves more effort than doing the final work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

Generic words of wisdom aren't a substitute for an explanation of how to reset the game.

There's no need to be condescending. Like I said, this is the first time I've used Flash. I'm not a stupid lazy kid who doesn't know how to structure development, I'm a developer who needed to make sure he could program the game before designing it. It would have been an enormous waste of time to plan out the game and our development approach without any experience, then build the menu and the basic structure and then get to the gameplay and realize I couldn't handle it.

My friend and I had never made a game together, much less in Flash which I'd never even used before, so we didn't have the experience to know the best approach. So I figured it out as I went. Will I be able to dynamically create a grid which highlights under the mouse? Yes. Can I get it so the player can click a specific square and it will drop a tower there? Yes, maybe we'll be able to make the game. Can I dynamically load creeps onto the field, push them into an array, give them a waypoint set, and have them follow the waypoints? Yes. Will I actually be able to get a tower to index through the array of creeps, check which ones are in range and which of those has the lowest health, and launch a bullet which will follow that creep until it hits it? Apparently I can handle that.

And so on and so on, and by making sure I had the skills to program the game, I had programmed the game! Imagine that.

Don't decide to build a house, plan the house, and then realize you can't build it yourself and you don't have the money to have someone else build it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

You can call it condescending if you like.  It's called reality.  If you are a developer you should know better than anyone that you took the wrong approach.  And as a developer you should know that you don't need to know everything ahead of taking on a project...just that you have the ability to pursue solutions.

For now, you've been given advice on how to do a reset, but you have yet to succeed doing it.  No one here is going to do it for you.  So for all the effort you put into the game, it's time to put in more effort.... and so on and so on,  making sure you have the skills, which after thousands of lines of coding, you should.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

In hindsight I know I took the wrong approach, in the sense that if we'd done it the "correct" way we'd be a little better off now. "Ability to pursue solutions" doesn't mean squat if you're in far over your head and you don't have the time and resources to reach these solutions; I'm not getting paid to do this, it's a project in my free time. There's a limit to how far I would be able to pursue solutions, so again if I'd started off with a lot of planning and structuring and then realized I couldn't nearly handle the code, I would have wasted a lot of time and probably not had the time or energy to escalate my knowledge to the appropriate level.

Instead, we've been making constant progress, having fun along the way, and we've got a game that is nearly finished. This is a hangup, but I'm motivated by the incredible amount we've accomplished from scratch with no experience. And now we've got a product that I'm sure we'll finish, and I know practically everything I need to, but I'm pursuing a solution.

We could have spent more time planning, researching what order to do things in, but experience is the best tool for planning, and we had no experience. I know a lot of things about how to approach my next Flash project that I never would have guessed from "preparation".

For now, you've been given advice on how to do a reset


I've had exactly one method suggested (by kglad), and already explained why I don't like this solution. I hope you don't think you've given me any useful advice towards a solution, other than "you don't need class files".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 08, 2011 Feb 08, 2011

Copy link to clipboard

Copied

Easy as that:

Prepare a separate swf file (you will need a preloader, anyway), the size and framerate of your game

I`m assuming your game is called "ImadeThisGameFromScratchAndImProudOfIt.swf"

Put this code on the first Frame:

var gameLoader:Loader;

loadGame();

function loadGame() {
    gameLoader = new Loader();
    gameLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
    gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
    gameLoader.load(new URLRequest("ImadeThisGameFromScratchAndImProudOfIt.swf"));

}

function resetGame(){

   removeChild(gameLoader);

   loadGame();

}

function loop(e:ProgressEvent):void{

   //DoWhateverMustBeDone

}

function done(e:Event):void {
    addChild(gameLoader);
}

Publish this "start.swf" in the same directory as your "ImadeThisGameFromScratchAndImProudOfIt.swf" and start the game via this one now

// In the ""ImadeThisGameFromScratchAndImProudOfIt.fla" you may call the resetGame() function with

parent.parent.resetGame()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines