flashgameblog.at

Currently the posts are filtered by: misc.
Reset this filter to see all posts.

02.03.2010
16:12

exporting image sequences

If there is no reason to keep vector graphics in the swf, I normally replace them with Pngs. The flash player is faster in copying pixels than in drawing curves and lines. So, this brings mostly a better performance. But there are two drawbacks in the flash IDE.

- The export function just animates the main time line. All embedded MCs are standing on their first frame. This results in the fact that you can't export nested animations.

- If parts of the animation are controlled by Actionscript, this parts wont be exported at all.

That was exactly my problem today. And fortunately last week end I started to work with AIR. And in Air2beta you even have the possibility to exit the application after all your work is done. So the logical consequence was to write a pseudo command line tool that creates a proper image sequence of PNGs.(That's why I love to be a programmer, you simply make your solutions.) I call it a pseudo command line tool because you call it from the command line, but air apps are GUI apps, even if you don't need it like in this case.

It's really simple to use: You give it a swf file, an output folder, the size of the images and if you want a name prefix.

This is how a call looks like:

swf2imgseq.exe -if c:\temp\test.swf -of c:\temp\ -width 640 -height 480 -prefix img

I needed that tool quickly to continue with my work, so I didn't take time to implement error checkings.

That means you have:
- to give a proper file path
- the out folder has to end with an slash
- width and height has to be int values
- prefix gets a part of the file name, so your OS gives you some rules about it.

I don't know how the program behaves in case of wrong parameters.
You don't get any warranties and you use it on your own risk.

By the way: I have seen this last week end and I didn't know that. If you install an air app, it will be converted to an .exe file automatically.

 

download: swf2imgseq.zip

28.11.2009
00:56

PixelBender for game developers

 

This week I found the time to take a look at PixelBender. And  of course my first thought was, how to use it in my next game.

In praxis PixelBender is used for two thing. On one hand it's used for what it's supposed to - visual effects. On the other hand it's used for calculation. In this post I am talking just about visual effects.

For my games in the past I used movieclip animations for visual effects. With visual effects I mean brain death effects. That means the effect is played and doesn't have any back coupling to the logic or the game environment. That's nice to use, because you trigger the effect and don't have to care about the rest. The movieclip removes itself from the stage with a short script in the last frame.

This mechanism had got the following characteristics:

- Effect has to be easy to start.
- The effect should be animated automatically.
- When the effect is finished everything should be cleaned up  automatically.

For PixelBender effects I wanted a mechanism doing exactly the same, but things are a bit more complicated.

- For flash games all recourses should be compiled into one swf. There are some issues to get the PixelBenders effect into the swf file.
- PixelBender effects are not designed to be animated.
- The filters array of the Displayobject object is not able to be manipulated.

Getting PixelBender effects into the swf file


Exporting the PixelBender kernel in the PixelBender toolkit created a .pbj file. This file is used by the flash player at runtime. There are three methods get the .pbj file into the swf file.

1. loading at runtime

I will not discuss this solution here, because it isn't practical for flash games. Flash games are mostly spread over a lot a sites and servers. You would need your own server to store all your effects, what would cause a lot of traffic and work to maintain.

2. [embed]

The embed tag allows you to embed the .pbj file into your swf file. There is just one drawback about it. The embed tag in not part of the AS3 specifications, it's part of the flex framework. So, if you use this tag the flex framework is involved.

3. PixelBender to Actionscript converter

I have found this tool, that converts your .pbj file into an actionscript class containing the .pbj file as a byte array. With this method the .pbj file is embedded into the swf file without involving the flex framework. But there is a drawback too. This method makes it necessary to convert the .pbj file newly every time you change it.

http://blog.brun.pl/2008/05/pixel-bender-pbj-file-to-actionscript-class-converter/


I decided to use the embed tag in my class, because from my point of view it's the best solution.

I won't explain the source of the classes here. They should be easily understood and where it's needed the source is documented.

The main class is the effectManager. You have to call it's main function in your main game loop. You may now ask why I didn't use timer objects for the animations. The solution is simple: I design all my programs to be driven by one force based on the ENTER_FRAME event. It's simply easier to handle.

In the download file you will find the logic for the effect management, an example PixelBender project and an example how it's used in the swf file.

 

download: pixelbender1.zip

 

  1. package {
  2.  
  3.   import classes.at.lueftenegger.effects.EffectsManager;
  4.   import classes.at.lueftenegger.effects.fx.ShockWave;
  5.   import flash.display.Sprite;
  6.   import flash.events.Event;
  7.   import flash.events.MouseEvent;
  8.  
  9.  
  10.   public class Main extends Sprite{
  11.    
  12.     // Embed is not part of the AS3 specification.
  13.     // It's part of the Flex framework.
  14.     // So this framework is involved here,
  15.     // but there is no other solution.
  16.     [Embed("./assets/shockwave.pbj", mimeType = "application/octet-stream")]
  17.     public static var fxShockWave:Class;
  18.    
  19.     private var _fm:EffectsManager;
  20.    
  21.     public function Main(){
  22.       _fm = new EffectsManager();
  23.      
  24.       addEventListener(MouseEvent.CLICK, doShockwave);
  25.       addEventListener(Event.ENTER_FRAME, main);
  26.      
  27.       // you have to write a Class implementing IEffect for every single effect
  28.       // you create in your game.
  29.       // This line gives the effect class a reference
  30.       // to the embeded pbj file
  31.       ShockWave.effect = fxShockWave;
  32.      
  33.     }
  34.    
  35.     private function doShockwave(e:MouseEvent):void {
  36.      
  37.       // this line of code triggers the effect. That's all you have to do.
  38.       _fm.AddEffect(new ShockWave(stage.mouseX, stage.mouseY), image);
  39.      
  40.     }
  41.    
  42.     private function main(e:Event):void {
  43.       // game main loop
  44.      
  45.       // ... your game runs here     
  46.      
  47.       // in your game main loop call the effect manager's
  48.       // main function to run the effects.
  49.       _fm.main();
  50.     }
  51.    
  52.   }
  53.  
  54. }
14.11.2009
13:48

flashgameblog.at in english

Last night I had an interesting chat with some developers. We talked about blogging and I came to the conclusion to continue this blog in english. The german posts will stay as they are.

 

Letzte Nacht hatte ich eine interessante Unterhaltung mit einigen Flashspieleentwicklern. Diese Unterhaltung führte mich zu der Entscheidung, diesen Blog in englisch weiterzuführen. Die vorhandenen deutschen Einträge bleiben ungeändert vorhanden.

< < September 2010 > >
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

Blog rolls

Latest Comments

ISO Blender Camera Setup
24.04.2010 06:58
update
21.03.2010 01:15
if-Statement
16.11.2009 08:34
hmm...
16.11.2009 08:00

Archive

  • [-]2010(8)
    • [-]August(1)
    • [-]July(1)
    • [-]June(2)
    • [-]April(1)
    • [-]March(2)
    • [-]February(1)
  • [-]2009(13)
    • [-]December(4)
    • [-]November(8)
    • [-]October(1)

Copy and paste this link into your RSS news reader

RSS 0.91Posts
RSS 2.0Posts

Social Bookmarking

Bookmark bei: Mr. Wong Bookmark bei: Webnews Bookmark bei: Icio Bookmark bei: Oneview Bookmark bei: Linkarena Bookmark bei: Favoriten Bookmark bei: Seekxl Bookmark bei: Favit Bookmark bei: Social Bookmarking Tool Bookmark bei: Power Oldie Bookmark bei: Bookmarks.cc Bookmark bei: Newskick Bookmark bei: Newsider Bookmark bei: Linksilo Bookmark bei: Readster Bookmark bei: Folkd Bookmark bei: Yigg Bookmark bei: Digg Bookmark bei: Del.icio.us Bookmark bei: Reddit Bookmark bei: Simpy Bookmark bei: StumbleUpon Bookmark bei: Slashdot Bookmark bei: Netscape Bookmark bei: Furl Bookmark bei: Yahoo Bookmark bei: Spurl Bookmark bei: Google Bookmark bei: Blinklist Bookmark bei: Blogmarks Bookmark bei: Diigo Bookmark bei: Technorati Bookmark bei: Newsvine Bookmark bei: Blinkbits Bookmark bei: Ma.Gnolia Bookmark bei: Smarking Bookmark bei: Netvouz Information