raigan
|
|
« on: September 01, 2010, 01:10:56 PM » |
|
This may be the first post in a series where I try to wrap my head around what the current best practices are for graphics in Flash. I'm about 5 years behind the times and trying to figure out how things are currently done.
Sadly this is not a bitmap based game, I need to use movieclips.
I've got a bunch of existing graphics in an old .swf, and I know how to embed them, but everything I've read suggests that all of the timeline code will be stripped.
This is a problem, because I use timeline code in two important ways: 1) particle graphics have code at the end of their animation that asks their parent to remove them; this lets me e.g attach a particle where I want it, start it playing, and leave it -- it will clean itself up when it's done.
2) entity graphics contain multiple different animations on a single timeline, with code in the last frame of each animation which controls looping (a running animation will e.g contain a gotoAndPlay() that moves the playhead back to the start of the animation; a oneshot animation will contain a gotoAndStop() that halts the playhead on the last frame). This lets client code simply do gotoAndPlay(anim_name) to start an animation and forget about it (the animation will loop or halt appropriately).
This is all very crusty and "actionscript 1"; what is the "modern" way to achieve similar functionality?
I could use addFrameScript() to inject the appropriate code back into the various frames (annoyingly tedious to code, but doable), or in the movieclip's enterFrame() I could keep checking the current frame and take appropriate action -- stopping the playhead, moving the playhead, or removing the movieclip -- which seems really stupid (i.e each frame I'll be doing if(current_frame == END_OF_RUN_ANIM){gotoAndPlay(START_OF_RUN_ANIM)}else if(current_frame == etc...)).
Anyway it seems like there are many possible solutions but they all suck; any suggestions or references are welcome!
thanks, raigan p.s - I would actually much rather find a new way to deal with the graphics, which lets me control everything. With bitmap-based games in Flash (or in an OpenGL-based game), each entity can push zero or more chunks of render-data onto a list, and then to draw the scene I iterate over the list and process each entry in the list (an entry would be e.g a chunk of data describing everything needed to draw a sprite, i.e sprite name, position, orientation, frame/animation data, etc.), which ultimately results in some pixels being copied onto the main canvas (Flash) or some vertex data pushed onto a list somewhere (OpenGL).
Sadly I can't see how to create an analogous system with .swf-based graphics -- aside from attaching movieclips each frame, then removing them all, which seems way too stupid. If anyone has any experience with this sort of thing, I'd love to hear about it.. every solution I can think of just seems so stupid and awkward.
|
|
|
Logged
|
|
|
|
nikki
|
|
« Reply #1 on: September 01, 2010, 05:00:30 PM » |
|
i think the Displaylist and the AS3 Event system woudl be a good read. someone posted better links once but i couldn't find the post.
|
|
|
Logged
|
|
|
|
lpmaurice
|
|
« Reply #2 on: September 01, 2010, 09:19:56 PM » |
|
If I understood correctly, you can do all you want just fine. Grant Skinner posted on the subject a while ago: http://www.gskinner.com/blog/archives/2007/03/using_flash_sym.htmlAs you can see, timeline code can be kept. Now, for your particle mc, you might need to create a custom class since the method you want to call is not a true MovieClip method, but it will work nonetheless. I hope this helps! Your tutorials on collision detection/reaction helped me so much back in the days, I'd be happy to give back a bit
|
|
|
Logged
|
|
|
|
lpmaurice
|
|
« Reply #3 on: September 01, 2010, 09:29:23 PM » |
|
Also: if, for example, your run animation is contained in a movieclip, you don't have to tell it to go to frame 1 once it reached the last frame. Just let it go and it will loop by itself.
|
|
|
Logged
|
|
|
|
raigan
|
|
« Reply #4 on: September 02, 2010, 05:45:38 AM » |
|
I understand how to actually display movieclips/sprites/shapes/etc. and all of that.. my problem was how to use old AS1-style .swf graphics in an AS3 project. Awesome, thanks -- that's perfect! Also: if, for example, your run animation is contained in a movieclip, you don't have to tell it to go to frame 1 once it reached the last frame. Just let it go and it will loop by itself.
Sadly there can be multiple animations on a single timeline on a single movieclip, and even if there's a single one it may need to be a "oneshot" (non-looping).
|
|
|
Logged
|
|
|
|
Johan Peitz
|
|
« Reply #5 on: September 09, 2010, 11:49:02 AM » |
|
How about wrapping each graphics swf in a custom class that handles the all the special cases? If you lose the code you probably need to rewrite it somewhere else. Unless there is a not of graphics that all behave differently it shouldn't take so long. It also sound like a good learning experience.
|
|
|
Logged
|
|
|
|
raigan
|
|
« Reply #6 on: September 09, 2010, 04:47:42 PM » |
|
Actually, we're importing everything via .swc to keep the code preserved.. it works!
|
|
|
Logged
|
|
|
|
st33d
Guest
|
|
« Reply #7 on: September 10, 2010, 12:54:04 AM » |
|
That's quite interesting. Care to elaborate?
|
|
|
Logged
|
|
|
|
raigan
|
|
« Reply #8 on: September 10, 2010, 06:19:42 AM » |
|
I found this great tutorial/sample code which show you how, it's VERY easy: http://www.flashdevelop.org/community/viewtopic.php?t=2457In Flash you just set the MovieClip to export with linkage name "myMC" extending class MovieClip, then in your AS3 code you can do: var test:MovieClip = new myMC(); No need for Embed or anything. Of course, AFAICT it requires Flash CS3/CS4 (and actually we only have CS3, and there were problems because we were compiling with the Flex4 SDK, so.. somewhat annoying!)
|
|
|
Logged
|
|
|
|
|