LogoLogo
  • Home
  • Projects
  • About
  • Contact

Playing With a Couple Game Ideas

Devon O. · September 16, 2012 · Actionscript, Flash, Games · 10 comments
12

Just a couple game fragments, really – prototypes, if you will; but some fun nonetheless, and it’s always good to tinker with new ideas…

After working on some various filters for Starling (cf. the last two posts here), I was itching to make something that actually used one. So, that in mind, here’s a little top-down-shoot-a zombie-with-a-flame-thrower game that makes use of the SpotlightFilter from when last I wrote: Zombie Roast.

Also, since Away3D 4 made its official debut and added the ability to combine itself with Starling, I’ve been wanting to do something with that awesome combination. And that led to this little Tron like Light Cycle game idea (the scrolling background is Starling, while the bikes, of course are in Away3D).

Anyway, that’s what I’ve been up to whilst waiting for the axe to fall…

Bonus:

Here’s one more Starling Framework filter for y’all: MotionBlur. You can see an example in action here. There’s actually two drawbacks to this filter: it will only work in the ‘Baseline’ profile (not ‘BaselineConstrained’); and, to avoid image clipping, it requires a lot of empty space around what you want to blur (e.g. in the example, the image is a 300×300 png with a 150×150 image centered in the transparency). Those issues aside, though, it’s a nice effect and you’re free to use it if you’d like…

UPDATE:

Following the advice in the comments from PrimaryFeather, I have made use of the marginX and marginY properties so that it is no longer necessary to surround your objects-to-be-blurred with copious amounts of transparent space. It’s a bit hacky, but from testing, it seems to work fine. If you run across problems though, post ’em and I’ll see what I can do. I also, put up a new example compiled with the new class file. You can use the sliders to adjust the amount and angle properties and get a good look on what exactly’s going on..

C#
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
*    Copyright (c) 2012 Devon O. Wolfgang
*
*    Permission is hereby granted, free of charge, to any person obtaining a copy
*    of this software and associated documentation files (the "Software"), to deal
*    in the Software without restriction, including without limitation the rights
*    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*    copies of the Software, and to permit persons to whom the Software is
*    furnished to do so, subject to the following conditions:
*
*    The above copyright notice and this permission notice shall be included in
*    all copies or substantial portions of the Software.
*
*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*    THE SOFTWARE.
*/
package starling.filters
{
    import flash.display3D.Context3D;
    import flash.display3D.Context3DProgramType;
    import flash.display3D.Program3D;
    import starling.textures.Texture;
    /**
     * Motion Blur filter for Starling Framework.
     * NOTE: This filter is only supported in 'baseline' profiles - NOT 'baselineConstrained'
     * @author Devon O.
     */
    public class MotionBlurFilter extends FragmentFilter
    {
        private var mQuantifiers:Vector.<Number> = new <Number>[1, 1, 1, 1];
        private var mShaderProgram:Program3D;
        private var mSteps:int;
        private var mAmount:Number;
        private var mAngle:Number;
        /**
         *
         * @param    angle    angle of blur in radians
         * @param    amount    the amount of blur
         * @param    steps    the level of the blur. A higher number produces a better result, but with worse performance. Can only be set once.
         */
        public function MotionBlurFilter(angle:Number = 0.0, amount:Number = 0.0, steps:int = 5)
        {
            mAngle    = angle;
            mAmount    = clamp(amount, 0.0, 20.0);
            mSteps    = int(clamp(steps, 2.0, 30.0));
            marginX = marginY = mAmount * mSteps * 1.50;
        }
        public override function dispose():void
        {
            if (mShaderProgram) mShaderProgram.dispose();
            super.dispose();
        }
        protected override function createPrograms():void
        {
            var step:String =
                "add ft1.x, ft1.x, fc0.w \n" +
                "mul ft2.xy, ft0.xy, ft1.x \n" +
                "add ft3.xy, v0.xy, ft2.xy \n" +
                "tex ft5, ft3.xy, fs0<2d, clamp, linear, nomip> \n" +
                "add ft4, ft4, ft5 \n";
            var fragmentProgramCode:String =
                "mov ft0.y, fc0.x \n" +
                "sin ft0.y, ft0.y \n" +
                "mov ft0.x, fc0.x \n" +
                "cos ft0.x, ft0.x \n" +
                "mul ft0.xy, ft0.xy, fc0.y \n" +
                "mov ft1.x, fc0.w \n" +
                "sub ft1.x, ft1.x, ft1.x \n" +
                "mul ft2.xy, ft0.xy, ft1.x \n" +
                "add ft3.xy, v0.xy, ft2.xy \n" +
                "tex ft4, ft3.xy, fs0<2d, clamp, linear, nomip> \n";
            var numSteps:int = mSteps - 1;
            for (var i:int = 0; i < numSteps; i++)
            {
                fragmentProgramCode += step;
            }
            fragmentProgramCode +=
                "div ft4, ft4, fc0.z \n" +
                "mov oc, ft4";
            mShaderProgram = assembleAgal(fragmentProgramCode);
        }
        protected override function activate(pass:int, context:Context3D, texture:Texture):void
        {
            // already set by super class:
            //
            // vertex constants 0-3: mvpMatrix (3D)
            // vertex attribute 0:   vertex position (FLOAT_2)
            // vertex attribute 1:   texture coordinates (FLOAT_2)
            // texture 0:            input texture
            var tSize:Number = (texture.width + texture.height) * .50;
            mQuantifiers[0] = mAngle;
            mQuantifiers[1] = mAmount;
            mQuantifiers[2] = mSteps;
            mQuantifiers[3] = 1 / tSize;
            context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, mQuantifiers, 1);
            context.setProgram(mShaderProgram);
        }
        private function clamp(target:Number, min:Number, max:Number):Number {
            if (target < min) target = min;
            if (target > max) target = max;
            return target;
        }
        public function get angle():Number { return mAngle; }
        public function set angle(value:Number):void { mAngle = value; }
        public function get amount():Number { return mAmount; }
        public function set amount(value:Number):void {
            mAmount = clamp(value, 0, 20);
            marginX = marginY = mAmount * mSteps * 1.50;
        }
    }
}

 

  Facebook   Pinterest   Twitter   Google+
away3dstarling
  • Quick Sound Effects Generator
    May 12, 2010 · 5 comments
    2216
    5
    Read more
  • Kinect Application Running in Dublin
    March 06, 2011 · 0 comments
    1737
    8
    Read more
  • Adding Flash/Actionscript Content to a Flex Project
    March 29, 2008 · 0 comments
    1836
    1
    Read more
10 Comments:
  1. Wow, awesome! Great to see those filters used in actual game! =)

    As for the motion blur: Starling filters contain the properties “marginX” and “marginY”. They extend the filter quad in x and y direction. Perhaps you can make use of those!

    PrimaryFeather · September 16, 2012
  2. Thank you for the kind words.

    And thank you for the marginX / marginY tip. I’m going to play around with that shortly and see if it solves the clipping problem.

    Devon O. · September 17, 2012
  3. I can’t get this filter to work.

    I took a liberty to decompile the example just to check what I’m doing wrong and I found out that it has built with a simpler version of the class.

    Have you verified that this code on the page is working as it should? I only see the alpha value change as I tweak the properties but no blur effect.

    Your other filters are working fine! Great job!

    TeroA · September 18, 2012
  4. Hey TeroA,

    It seems to work all right for me. I’m wondering – did you set the levels to 1? In essence, what the filter does is duplicate the image the number of times specified by the levels argument, then spread those images at the angle set.

    In any case, I just posted an update with a link to new example which makes use of the code posted. See if that works for you.

    And thank you for the feedback!

    Devon O. · September 19, 2012
  5. Thanks a lot Devon O, this motion blur filter is great (as so much other code in this blog) but I’ve got exactely the same problem than TeroA. The filter only changes the alpha of the sprite (that becomes almost transparent), but there is no blur.

    Here is the code I use: mysprite.filter = new MotionBlurFilter(0,1);

    I use the last version of Starling (included in Citrus Engine package), Flash Player 11.3, Flex 4.6.0 and Air 3.3.

    Dr Schizo · March 17, 2013
  6. Hey Dr S.

    The problem may be that you’re using this in “baseline_constrained” mode. In baseline_constrained, the highest number of steps (3rd argument of the constructor) supported is 2; which, to be honest, is such a subtle effect, it’s really not worth using.

    d.

    Devon O. · March 17, 2013
  7. Unfortunately, I don’t:
    mystarling = new Starling(Game, stage, null, null, “auto”, “baseline”);
    …
    mysprite.filter = new MotionBlurFilter(0,5);

    =(

    Dr Schizo · March 18, 2013
  8. Hey Devon, apologies on bringing up an old thread. I was having the same issues as Tero and Dr. S with regards to the MotionBlurFilter. I was loading up my assets through the Starling AssetManager class and getting no love. Then I tried embedding the assets and everything worked!

    So I thought it must be an issue with the AssetManager. I then stripped out the AssetManager from my code and tried a new test. I embedded 2 identical assets and added them right after each other. With the first, I added the MotionBlurFilter as the image was added to stage. This worked fine. With the second image, I waited 1 second after the item was added to stage and then added the filter. It didn’t work?

    Any ideas?

    btw, the new version with the marginX and marginY changes, isn’t in your github repo…

    munkychunks · September 12, 2013
  9. Hey munkychunks (awesome handle!),

    Off the top of my head, I have no idea what may be causing that problem. Thank you though for letting me know the one in github is out of date, though. I think this weekend, I’m going to rewrite this shader from scratch then try to figure out where all the problems may be coming from.

    -d.

    Devon O. · September 12, 2013
  10. Ha, thanks Devon!

    I’ve just noticed it happening with the GodRaysFilter as well and this is also a Context3DProfile.BASELINE filter? May be a clue?

    If I figure anything out, I’ll let you know.

    As others have commented, great filters! I reckon for every kudos you get, there are a thousand devs out there who are super stoked you wrote these! Many thanks!

    munkychunks · September 12, 2013

Leave a Comment! Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • MainDepth on Unity Ripple or Shock Wave Effect
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2021 Devon O. Wolfgang