SHMotionBlurSprite

type:
extension
author:
Shilo White
description:
A simple sprite with a motion blur effect.
lastupdate:
2011-03-27
compatible:
v1.X
tag:
motion, blur, sprite
homepage:
https://gist.github.com/870334
download:
https://gist.github.com/gists/870334/download
sample:
http://shilo.coarsemode.com/sparrow/extensions/shmotionblursprite/QuadsWithBlurSample.zip

Description

SHMotionBlurSprite class will function just like a normal sprite, but it will give the children a motion blur effect. You can change the blur duration in seconds with “blurDuration” and change the starting blur alpha with “blurAlpha”.

Sample

Example

//initialize a motion blur sprite with the default properties
SHMotionBlurSprite *motionBlurSprite = [SHMotionBlurSprite motionBlurSprite];
 
//set the blur duration to 10 seconds
motionBlurSprite.blurDuration = 10.0f;
 
//set the starting blur opacity to 25%
motionBlurSprite.blurAlpha = 0.25;
 
//set the blur duration to a negative number to set motion blur to forever
motionBlurSprite.blurDuration = SH_MOTION_BLUR_INFINITE;
motionBlurSprite.blurDuration = -1.0f;
 
//set the blur duration to zero to turn the motion blur off
motionBlurSprite.blurDuration = SH_MOTION_BLUR_NONE;
motionBlurSprite.blurDuration = 0;

Instructions

To add into your Sparrow project

  1. Download the source files here: https://gist.github.com/gists/870334/download
  2. Open your desired Sparrow project
  3. Drag and drop the files into the “Groups & Files” pane
  4. Open “Game.h”
  5. Include the extension:
    #include "SHMotionBlurSprite.h"
  6. Save “Game.h”

To add directly into Sparrow source

  1. Download the source files here: https://gist.github.com/gists/870334/download
  2. Save the files into Sparrow's “/Classes/” directory
    • Example: “/sparrow/src/Classes/”
  3. Navigate back one directory and open “Sparrow.xcodeproj”
    • Example: “/sparrow/src/Sparrow.xcodeproj”
  4. Inside the “Groups & Files” pane, locate the “Display” group folder
    • Example: “Sparrow → Classes → Display”
  5. Right click the “Display” group folder and click “Add → Existing Files..”
  6. Navigate into the “/Classes/” directory and select “SHMotionBlurSprite.h” and “SHMotionBlurSprite.m”, then click “add”
  7. On the next window, leave all options as default and click “add”
  8. In the “Groups & Files” pane, Open “Sparrow.h”
    • Example “Sparrow → Classes → Sparrow.h”
  9. At the bottom of the file, add:
    #import "SHMotionBlurSprite.h"
  10. Save “Sparrow.h”
  11. Close “Sparrow.xcodeproj”

Source Code

Changelog

  • 2011-01-14: First version
  • 2011-01-15: Optimization and bug fixes
  • 2011-03-27: fixed small warning, added property “renderTexture” so objects can be drawn to it directly if needed

Todo

  • change default width/height to screen width/height based on rotation
  • Allow objects to render behind it
    • Change the clear alpha value to 0
    • Get the motion blur to show correctly while alpha value equals 0

Special Thanks

  • Daniel for the idea of how to implement a motion blur effect
  users/shilo/extensions/shmotionblursprite.txt · Last modified: 2013/03/05 10:19 (external edit)
 
Powered by DokuWiki