├── .gitignore ├── .travis.yml ├── Classes ├── UIImage+Sprite.h └── UIImage+Sprite.m ├── LICENSE ├── README.mdown ├── SpriteAnimationDemo ├── SpriteAnimationDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── SpriteAnimationDemo.xccheckout │ │ └── xcuserdata │ │ │ ├── r3n.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── WorkspaceSettings.xcsettings │ │ │ └── rafalsroka.xcuserdatad │ │ │ └── WorkspaceSettings.xcsettings │ └── xcuserdata │ │ ├── r3n.xcuserdatad │ │ └── xcschemes │ │ │ ├── SpriteAnimationDemo.xcscheme │ │ │ └── xcschememanagement.plist │ │ └── rafalsroka.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints.xcbkptlist │ │ └── xcschemes │ │ ├── SpriteAnimationDemo.xcscheme │ │ └── xcschememanagement.plist └── SpriteAnimationDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── LaunchImage.launchimage │ │ └── Contents.json │ ├── explosions.imageset │ │ ├── Contents.json │ │ └── explosions.png │ └── explosions_debug.imageset │ │ ├── Contents.json │ │ └── explosions_debug.png │ ├── MasterViewController.h │ ├── MasterViewController.m │ ├── SpriteAnimationDemo-Info.plist │ ├── SpriteAnimationDemo-Prefix.pch │ ├── UIImage+Sprite.h │ ├── UIImage+Sprite.m │ ├── en.lproj │ ├── InfoPlist.strings │ └── MasterViewController.xib │ ├── explosions.png │ ├── explosions_debug.png │ └── main.m └── UIImage+SpriteAdditions.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | # Pods - for those of you who use CocoaPods 20 | Pods -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode9 3 | script: 4 | - xcodebuild clean build -sdk iphonesimulator -project ./SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj -scheme SpriteAnimationDemo CODE_SIGNING_REQUIRED=NO -------------------------------------------------------------------------------- /Classes/UIImage+Sprite.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Sprite.h 3 | // 4 | // Created by Rafal Sroka on 11-11-17. 5 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 6 | // 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | #import 29 | #import 30 | 31 | /** 32 | Useful UIImage category for handling sprite sheets. This add-on smoothes the way of extracting images from a sprite sheet (texture atlas). 33 | Note that for performance reasons you should not fire these methods every time you want to get the array of animation frames. 34 | You should rather fire it once and store the output array somewhere. This is because the Core Graphics image manipulation operations (especially on large images) are not so fast and your application may slow down. 35 | */ 36 | @interface UIImage (Sprite) 37 | 38 | /** 39 | The method returns an array with UIImages. Original sprite sheet is sliced into smaller chunks, each of the specified size. 40 | @param image the image with sprite sheet (texture atlas) 41 | @param size the size of the single chunk 42 | @returns the array of UIImages, each representing a single animation frame 43 | */ 44 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size; 45 | 46 | 47 | /** 48 | The method returns an array with UIImages. Original sprite sheet is sliced into smaller chunks, each of the specified size. 49 | @param image the image with sprite sheet (texture atlas) 50 | @param range the range of the chunks 51 | @param size the size of the single chunk 52 | @returns the array of UIImages, each representing a single animation frame 53 | */ 54 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size; 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Classes/UIImage+Sprite.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Sprite.m 3 | // 4 | // Created by Rafal Sroka on 11-11-17. 5 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 6 | // 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | #import "UIImage+Sprite.h" 29 | 30 | 31 | @implementation UIImage (Sprite) 32 | 33 | 34 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 35 | spriteSize:(CGSize)size 36 | { 37 | 38 | return [self spritesWithSpriteSheetImage:self 39 | inRange:NSMakeRange(0, lroundf(MAXFLOAT)) 40 | spriteSize:size]; 41 | } 42 | 43 | 44 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 45 | inRange:(NSRange)range 46 | spriteSize:(CGSize)size 47 | { 48 | if (!image || CGSizeEqualToSize(size, CGSizeZero) || range.length == 0) 49 | return nil; 50 | 51 | CGImageRef spriteSheet = [image CGImage]; 52 | NSMutableArray *tempArray = [[NSMutableArray alloc] init]; 53 | 54 | int width = CGImageGetWidth(spriteSheet); 55 | int height = CGImageGetHeight(spriteSheet); 56 | 57 | int maxI = width / size.width; 58 | 59 | int startI = 0; 60 | int startJ = 0; 61 | int length = 0; 62 | 63 | int startPosition = range.location; 64 | 65 | // Extracting initial I & J values from range info 66 | if (startPosition != 0) 67 | { 68 | for (int k=1; k<=maxI; k++) 69 | { 70 | int d = k * maxI; 71 | 72 | if (d/startPosition == 1) 73 | { 74 | startI = maxI - (d % startPosition); 75 | break; 76 | } 77 | else if (d/startPosition > 1) 78 | { 79 | startI = startPosition; 80 | break; 81 | } 82 | 83 | startJ++; 84 | } 85 | } 86 | 87 | int positionX = startI * size.width; 88 | int positionY = startJ * size.height; 89 | BOOL isReady = NO; 90 | 91 | while (positionY < height) 92 | { 93 | while (positionX < width) 94 | { 95 | CGImageRef sprite = CGImageCreateWithImageInRect(spriteSheet, 96 | CGRectMake(positionX, 97 | positionY, 98 | size.width, 99 | size.height)); 100 | [tempArray addObject:[UIImage imageWithCGImage:sprite]]; 101 | 102 | CGImageRelease(sprite); 103 | 104 | length++; 105 | 106 | if (length == range.length) 107 | { 108 | isReady = YES; 109 | break; 110 | } 111 | 112 | positionX += size.width; 113 | } 114 | 115 | if (isReady) break; 116 | 117 | positionX = 0; 118 | positionY += size.height; 119 | } 120 | 121 | return [NSArray arrayWithArray:tempArray]; 122 | } 123 | 124 | 125 | @end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | 4 | This code is distributed under the terms and conditions of the MIT license. 5 | 6 | Copyright (c) 2011 Rafal Sroka 7 | 8 | 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: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | 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. -------------------------------------------------------------------------------- /README.mdown: -------------------------------------------------------------------------------- 1 | 2 | [![Build Status](https://travis-ci.org/r3econ/UIImage-Sprite-Additions.svg?branch=master)](https://travis-ci.org/r3econ/UIImage-Sprite-Additions) 3 | [![CodeFactor](https://www.codefactor.io/repository/github/r3econ/sprite-additions/badge)](https://www.codefactor.io/repository/github/r3econ/sprite-additions) 4 | [![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://img.shields.io/badge/License-MIT-brightgreen.svg) 5 | ![Platform](https://img.shields.io/badge/platform-ios%20%7C%20tvos-lightgrey.svg) 6 | 7 | UIImage Sprite Additions 8 | ============= 9 | 10 | Useful `UIImage` category for handling sprite sheets. This add-on smoothes the way of extracting images from a sprite sheet (texture atlas). 11 | 12 | This can be useful in `UIImageView` animations where animationImages array has to be filled with a set of images representing frames. `UIImage-Sprite` category makes this process trivial by introducing two methods: 13 | ```objective-c 14 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size; 15 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size; 16 | ``` 17 | Quick start 18 | ======= 19 | 20 | Just copy `UIImage+Sprite.h` and `UIImage+Sprite.m` to your project or use CocoaPods to install the pod. 21 | 22 | Instructions for CocoaPods users: 23 | 24 | 1. Install [CocoaPods](http://cocoapods.org/) with `gem install cocoapods`. 25 | 2. Create a file in your XCode project called `Podfile` and add the following line: 26 | 27 | pod 'UIImage+SpriteAdditions' 28 | 29 | 3. Run `pod install` in your xcode project directory. CocoaPods should download and 30 | install the `UIImage+SpriteAdditions` category, and create a new Xcode workspace. Open up this workspace in Xcode. 31 | 32 | How to 33 | ======= 34 | 35 | There are two methods in `UIImage+SpriteAdditions` category. First one: 36 | ```objective-c 37 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size; 38 | ``` 39 | The method returns an array with `UIImage` objects. Original sprite sheet (image) is sliced into smaller chunks, each of the specified size. 40 | 41 | Second method is very similar: 42 | ```objective-c 43 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size; 44 | ``` 45 | This method does exactly the same thing as the latter. However, this time we can specify the range of the chunks we want to get. 46 | 47 | Note that for performance reasons you should not fire these methods every time you want to get the array of animation frames. You should rather fire it once and store the output array somewhere. This is because the `CoreGraphics` image manipulation operations (especially on large images) are not so fast and your application may slow down. 48 | 49 | I wrote this add-on to facilitate the setup of short animations using `UIImageView`. For more complex animations I recommend using `OpenGLES`. 50 | 51 | Demo 52 | ======= 53 | 54 | `SpriteAnimationDemo` project presents the usage of the `UIImage+Sprite` methods. The example shows how to create an animated `UIImageView`. This cool explosion sprite sheet which I included in the demo can be found [here](http://gushh.net/blog/free-game-sprites-explosion-3/). I added some numbers to this image to make testing and debugging easier. 55 | 56 | ![Imgur](https://i.imgur.com/lPNJnso.gif) 57 | 58 | License 59 | ======= 60 | 61 | This code is distributed under the terms and conditions of the MIT license. 62 | 63 | Copyright (c) 2011 Rafal Sroka -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 86FE6C9A18AFDC8A0084C082 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86FE6C9918AFDC8A0084C082 /* Images.xcassets */; }; 11 | AF044E2414758C5000B2C688 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF044E2314758C5000B2C688 /* UIKit.framework */; }; 12 | AF044E2614758C5000B2C688 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF044E2514758C5000B2C688 /* Foundation.framework */; }; 13 | AF044E2814758C5000B2C688 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF044E2714758C5000B2C688 /* CoreGraphics.framework */; }; 14 | AF044E2E14758C5000B2C688 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF044E2C14758C5000B2C688 /* InfoPlist.strings */; }; 15 | AF044E3014758C5000B2C688 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AF044E2F14758C5000B2C688 /* main.m */; }; 16 | AF044E3414758C5000B2C688 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = AF044E3314758C5000B2C688 /* AppDelegate.m */; }; 17 | AF044E3714758C5000B2C688 /* MasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AF044E3614758C5000B2C688 /* MasterViewController.m */; }; 18 | AF044E3D14758C5000B2C688 /* MasterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AF044E3B14758C5000B2C688 /* MasterViewController.xib */; }; 19 | B53AF6F3190EFCCB00C29B17 /* UIImage+Sprite.m in Sources */ = {isa = PBXBuildFile; fileRef = B53AF6F2190EFCCB00C29B17 /* UIImage+Sprite.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 86FE6C9918AFDC8A0084C082 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 24 | AF044E1F14758C5000B2C688 /* SpriteAnimationDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SpriteAnimationDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | AF044E2314758C5000B2C688 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 26 | AF044E2514758C5000B2C688 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 27 | AF044E2714758C5000B2C688 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 28 | AF044E2B14758C5000B2C688 /* SpriteAnimationDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SpriteAnimationDemo-Info.plist"; sourceTree = ""; }; 29 | AF044E2D14758C5000B2C688 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 30 | AF044E2F14758C5000B2C688 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | AF044E3114758C5000B2C688 /* SpriteAnimationDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SpriteAnimationDemo-Prefix.pch"; sourceTree = ""; }; 32 | AF044E3214758C5000B2C688 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 33 | AF044E3314758C5000B2C688 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 34 | AF044E3514758C5000B2C688 /* MasterViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MasterViewController.h; sourceTree = ""; }; 35 | AF044E3614758C5000B2C688 /* MasterViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MasterViewController.m; sourceTree = ""; }; 36 | AF044E3C14758C5000B2C688 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MasterViewController.xib; sourceTree = ""; }; 37 | B53AF6F1190EFCCB00C29B17 /* UIImage+Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+Sprite.h"; path = "SpriteAnimationDemo/UIImage+Sprite.h"; sourceTree = SOURCE_ROOT; }; 38 | B53AF6F2190EFCCB00C29B17 /* UIImage+Sprite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImage+Sprite.m"; path = "SpriteAnimationDemo/UIImage+Sprite.m"; sourceTree = SOURCE_ROOT; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | AF044E1C14758C5000B2C688 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | AF044E2414758C5000B2C688 /* UIKit.framework in Frameworks */, 47 | AF044E2614758C5000B2C688 /* Foundation.framework in Frameworks */, 48 | AF044E2814758C5000B2C688 /* CoreGraphics.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 8636FACE1FC7809500271A1B /* UIImage+SpriteAdditions */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | B53AF6F1190EFCCB00C29B17 /* UIImage+Sprite.h */, 59 | B53AF6F2190EFCCB00C29B17 /* UIImage+Sprite.m */, 60 | ); 61 | name = "UIImage+SpriteAdditions"; 62 | sourceTree = ""; 63 | }; 64 | AF044E1414758C5000B2C688 = { 65 | isa = PBXGroup; 66 | children = ( 67 | AF044E2914758C5000B2C688 /* SpriteAnimationDemo */, 68 | AF044E2214758C5000B2C688 /* Frameworks */, 69 | AF044E2014758C5000B2C688 /* Products */, 70 | ); 71 | sourceTree = ""; 72 | }; 73 | AF044E2014758C5000B2C688 /* Products */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | AF044E1F14758C5000B2C688 /* SpriteAnimationDemo.app */, 77 | ); 78 | name = Products; 79 | sourceTree = ""; 80 | }; 81 | AF044E2214758C5000B2C688 /* Frameworks */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | AF044E2314758C5000B2C688 /* UIKit.framework */, 85 | AF044E2514758C5000B2C688 /* Foundation.framework */, 86 | AF044E2714758C5000B2C688 /* CoreGraphics.framework */, 87 | ); 88 | name = Frameworks; 89 | sourceTree = ""; 90 | }; 91 | AF044E2914758C5000B2C688 /* SpriteAnimationDemo */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 8636FACE1FC7809500271A1B /* UIImage+SpriteAdditions */, 95 | AF9201081BB59D4B00B12591 /* App Delegate */, 96 | AF9201071BB59D3900B12591 /* View Controllers */, 97 | 86FE6C9918AFDC8A0084C082 /* Images.xcassets */, 98 | AF044E2A14758C5000B2C688 /* Supporting Files */, 99 | ); 100 | path = SpriteAnimationDemo; 101 | sourceTree = ""; 102 | }; 103 | AF044E2A14758C5000B2C688 /* Supporting Files */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | AF044E2B14758C5000B2C688 /* SpriteAnimationDemo-Info.plist */, 107 | AF044E2C14758C5000B2C688 /* InfoPlist.strings */, 108 | AF044E2F14758C5000B2C688 /* main.m */, 109 | AF044E3114758C5000B2C688 /* SpriteAnimationDemo-Prefix.pch */, 110 | ); 111 | name = "Supporting Files"; 112 | sourceTree = ""; 113 | }; 114 | AF9201071BB59D3900B12591 /* View Controllers */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | AF044E3514758C5000B2C688 /* MasterViewController.h */, 118 | AF044E3614758C5000B2C688 /* MasterViewController.m */, 119 | AF044E3B14758C5000B2C688 /* MasterViewController.xib */, 120 | ); 121 | name = "View Controllers"; 122 | sourceTree = ""; 123 | }; 124 | AF9201081BB59D4B00B12591 /* App Delegate */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | AF044E3214758C5000B2C688 /* AppDelegate.h */, 128 | AF044E3314758C5000B2C688 /* AppDelegate.m */, 129 | ); 130 | name = "App Delegate"; 131 | sourceTree = ""; 132 | }; 133 | /* End PBXGroup section */ 134 | 135 | /* Begin PBXNativeTarget section */ 136 | AF044E1E14758C5000B2C688 /* SpriteAnimationDemo */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = AF044E4314758C5000B2C688 /* Build configuration list for PBXNativeTarget "SpriteAnimationDemo" */; 139 | buildPhases = ( 140 | AF044E1B14758C5000B2C688 /* Sources */, 141 | AF044E1C14758C5000B2C688 /* Frameworks */, 142 | AF044E1D14758C5000B2C688 /* Resources */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | ); 148 | name = SpriteAnimationDemo; 149 | productName = SpriteAnimationDemo; 150 | productReference = AF044E1F14758C5000B2C688 /* SpriteAnimationDemo.app */; 151 | productType = "com.apple.product-type.application"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | AF044E1614758C5000B2C688 /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastUpgradeCheck = 0900; 160 | }; 161 | buildConfigurationList = AF044E1914758C5000B2C688 /* Build configuration list for PBXProject "SpriteAnimationDemo" */; 162 | compatibilityVersion = "Xcode 3.2"; 163 | developmentRegion = English; 164 | hasScannedForEncodings = 0; 165 | knownRegions = ( 166 | en, 167 | ); 168 | mainGroup = AF044E1414758C5000B2C688; 169 | productRefGroup = AF044E2014758C5000B2C688 /* Products */; 170 | projectDirPath = ""; 171 | projectRoot = ""; 172 | targets = ( 173 | AF044E1E14758C5000B2C688 /* SpriteAnimationDemo */, 174 | ); 175 | }; 176 | /* End PBXProject section */ 177 | 178 | /* Begin PBXResourcesBuildPhase section */ 179 | AF044E1D14758C5000B2C688 /* Resources */ = { 180 | isa = PBXResourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | AF044E2E14758C5000B2C688 /* InfoPlist.strings in Resources */, 184 | 86FE6C9A18AFDC8A0084C082 /* Images.xcassets in Resources */, 185 | AF044E3D14758C5000B2C688 /* MasterViewController.xib in Resources */, 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | /* End PBXResourcesBuildPhase section */ 190 | 191 | /* Begin PBXSourcesBuildPhase section */ 192 | AF044E1B14758C5000B2C688 /* Sources */ = { 193 | isa = PBXSourcesBuildPhase; 194 | buildActionMask = 2147483647; 195 | files = ( 196 | AF044E3014758C5000B2C688 /* main.m in Sources */, 197 | AF044E3414758C5000B2C688 /* AppDelegate.m in Sources */, 198 | B53AF6F3190EFCCB00C29B17 /* UIImage+Sprite.m in Sources */, 199 | AF044E3714758C5000B2C688 /* MasterViewController.m in Sources */, 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | }; 203 | /* End PBXSourcesBuildPhase section */ 204 | 205 | /* Begin PBXVariantGroup section */ 206 | AF044E2C14758C5000B2C688 /* InfoPlist.strings */ = { 207 | isa = PBXVariantGroup; 208 | children = ( 209 | AF044E2D14758C5000B2C688 /* en */, 210 | ); 211 | name = InfoPlist.strings; 212 | sourceTree = ""; 213 | }; 214 | AF044E3B14758C5000B2C688 /* MasterViewController.xib */ = { 215 | isa = PBXVariantGroup; 216 | children = ( 217 | AF044E3C14758C5000B2C688 /* en */, 218 | ); 219 | name = MasterViewController.xib; 220 | sourceTree = ""; 221 | }; 222 | /* End PBXVariantGroup section */ 223 | 224 | /* Begin XCBuildConfiguration section */ 225 | AF044E4114758C5000B2C688 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_COMMA = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 245 | COPY_PHASE_STRIP = NO; 246 | ENABLE_STRICT_OBJC_MSGSEND = YES; 247 | ENABLE_TESTABILITY = YES; 248 | GCC_C_LANGUAGE_STANDARD = gnu99; 249 | GCC_DYNAMIC_NO_PIC = NO; 250 | GCC_NO_COMMON_BLOCKS = YES; 251 | GCC_OPTIMIZATION_LEVEL = 0; 252 | GCC_PREPROCESSOR_DEFINITIONS = ( 253 | "DEBUG=1", 254 | "$(inherited)", 255 | ); 256 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 257 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 266 | ONLY_ACTIVE_ARCH = YES; 267 | SDKROOT = iphoneos; 268 | }; 269 | name = Debug; 270 | }; 271 | AF044E4214758C5000B2C688 /* Release */ = { 272 | isa = XCBuildConfiguration; 273 | buildSettings = { 274 | ALWAYS_SEARCH_USER_PATHS = NO; 275 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_COMMA = YES; 278 | CLANG_WARN_CONSTANT_CONVERSION = YES; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INFINITE_RECURSION = YES; 282 | CLANG_WARN_INT_CONVERSION = YES; 283 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 284 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 285 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 286 | CLANG_WARN_STRICT_PROTOTYPES = YES; 287 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 288 | CLANG_WARN_UNREACHABLE_CODE = YES; 289 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 290 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 291 | COPY_PHASE_STRIP = YES; 292 | ENABLE_STRICT_OBJC_MSGSEND = YES; 293 | GCC_C_LANGUAGE_STANDARD = gnu99; 294 | GCC_NO_COMMON_BLOCKS = YES; 295 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 298 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 299 | GCC_WARN_UNDECLARED_SELECTOR = YES; 300 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 301 | GCC_WARN_UNUSED_FUNCTION = YES; 302 | GCC_WARN_UNUSED_VARIABLE = YES; 303 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 304 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 305 | SDKROOT = iphoneos; 306 | VALIDATE_PRODUCT = YES; 307 | }; 308 | name = Release; 309 | }; 310 | AF044E4414758C5000B2C688 /* Debug */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 314 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 315 | CLANG_ENABLE_OBJC_ARC = YES; 316 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 317 | GCC_PREFIX_HEADER = "SpriteAnimationDemo/SpriteAnimationDemo-Prefix.pch"; 318 | GCC_VERSION = ""; 319 | INFOPLIST_FILE = "SpriteAnimationDemo/SpriteAnimationDemo-Info.plist"; 320 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 321 | PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:rfc1034identifier}"; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | WRAPPER_EXTENSION = app; 324 | }; 325 | name = Debug; 326 | }; 327 | AF044E4514758C5000B2C688 /* Release */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 334 | GCC_PREFIX_HEADER = "SpriteAnimationDemo/SpriteAnimationDemo-Prefix.pch"; 335 | GCC_VERSION = ""; 336 | INFOPLIST_FILE = "SpriteAnimationDemo/SpriteAnimationDemo-Info.plist"; 337 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 338 | PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:rfc1034identifier}"; 339 | PRODUCT_NAME = "$(TARGET_NAME)"; 340 | WRAPPER_EXTENSION = app; 341 | }; 342 | name = Release; 343 | }; 344 | /* End XCBuildConfiguration section */ 345 | 346 | /* Begin XCConfigurationList section */ 347 | AF044E1914758C5000B2C688 /* Build configuration list for PBXProject "SpriteAnimationDemo" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | AF044E4114758C5000B2C688 /* Debug */, 351 | AF044E4214758C5000B2C688 /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | AF044E4314758C5000B2C688 /* Build configuration list for PBXNativeTarget "SpriteAnimationDemo" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | AF044E4414758C5000B2C688 /* Debug */, 360 | AF044E4514758C5000B2C688 /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | /* End XCConfigurationList section */ 366 | }; 367 | rootObject = AF044E1614758C5000B2C688 /* Project object */; 368 | } 369 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/xcshareddata/SpriteAnimationDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | AF0BB5F6-1090-4313-AEEB-3FAA57757D6F 9 | IDESourceControlProjectName 10 | SpriteAnimationDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 44686E89-64F2-4371-811A-221B73225D67 14 | https://github.com/r3econ/UIImage-Sprite-Additions.git 15 | 16 | IDESourceControlProjectPath 17 | SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 44686E89-64F2-4371-811A-221B73225D67 21 | ../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/r3econ/UIImage-Sprite-Additions.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 44686E89-64F2-4371-811A-221B73225D67 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 44686E89-64F2-4371-811A-221B73225D67 36 | IDESourceControlWCCName 37 | SpriteAdditions 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/xcuserdata/r3n.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r3econ/sprite-additions/ced40347f33963522a6956e0f7b2321f340c060f/SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/xcuserdata/r3n.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/xcuserdata/r3n.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | IssueFilterStyle 12 | ShowActiveSchemeOnly 13 | LiveSourceIssuesEnabled 14 | 15 | SnapshotAutomaticallyBeforeSignificantChanges 16 | 17 | SnapshotLocationStyle 18 | Default 19 | 20 | 21 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/project.xcworkspace/xcuserdata/rafalsroka.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/xcuserdata/r3n.xcuserdatad/xcschemes/SpriteAnimationDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 56 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/xcuserdata/r3n.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SpriteAnimationDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AF044E1E14758C5000B2C688 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/xcuserdata/rafalsroka.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/xcuserdata/rafalsroka.xcuserdatad/xcschemes/SpriteAnimationDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo.xcodeproj/xcuserdata/rafalsroka.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SpriteAnimationDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AF044E1E14758C5000B2C688 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SpriteAnimationDemo 4 | // 5 | // Created by Rafal Sroka on 11-11-17. 6 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 7 | // 8 | // 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining 12 | // a copy of this software and associated documentation files (the 13 | // "Software"), to deal in the Software without restriction, including 14 | // without limitation the rights to use, copy, modify, merge, publish, 15 | // distribute, sublicense, and/or sell copies of the Software, and to 16 | // permit persons to whom the Software is furnished to do so, subject to 17 | // the following conditions: 18 | // 19 | // The above copyright notice and this permission notice shall be 20 | // included in all copies or substantial portions of the Software. 21 | // 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | #import 32 | 33 | @interface AppDelegate : UIResponder 34 | 35 | @property (strong, nonatomic) UIWindow *window; 36 | @property (strong, nonatomic) UINavigationController *navigationController; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SpriteAnimationDemo 4 | // 5 | // Created by Rafal Sroka on 11-11-17. 6 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 7 | // 8 | // 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining 12 | // a copy of this software and associated documentation files (the 13 | // "Software"), to deal in the Software without restriction, including 14 | // without limitation the rights to use, copy, modify, merge, publish, 15 | // distribute, sublicense, and/or sell copies of the Software, and to 16 | // permit persons to whom the Software is furnished to do so, subject to 17 | // the following conditions: 18 | // 19 | // The above copyright notice and this permission notice shall be 20 | // included in all copies or substantial portions of the Software. 21 | // 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | #import "AppDelegate.h" 32 | #import "MasterViewController.h" 33 | 34 | @implementation AppDelegate 35 | 36 | 37 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 38 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 39 | 40 | MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil]; 41 | self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; 42 | 43 | self.window.rootViewController = self.navigationController; 44 | [self.window makeKeyAndVisible]; 45 | 46 | return YES; 47 | } 48 | 49 | - (void)applicationWillResignActive:(UIApplication *)application { 50 | /* 51 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 52 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 53 | */ 54 | } 55 | 56 | - (void)applicationDidEnterBackground:(UIApplication *)application { 57 | /* 58 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 59 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 60 | */ 61 | } 62 | 63 | - (void)applicationWillEnterForeground:(UIApplication *)application { 64 | /* 65 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 66 | */ 67 | } 68 | 69 | - (void)applicationDidBecomeActive:(UIApplication *)application { 70 | /* 71 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 72 | */ 73 | } 74 | 75 | - (void)applicationWillTerminate:(UIApplication *)application { 76 | /* 77 | Called when the application is about to terminate. 78 | Save data if appropriate. 79 | See also applicationDidEnterBackground:. 80 | */ 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "29x29", 26 | "scale" : "3x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "40x40", 36 | "scale" : "3x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "57x57", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "iphone", 45 | "size" : "57x57", 46 | "scale" : "2x" 47 | }, 48 | { 49 | "idiom" : "iphone", 50 | "size" : "60x60", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "iphone", 55 | "size" : "60x60", 56 | "scale" : "3x" 57 | }, 58 | { 59 | "idiom" : "ios-marketing", 60 | "size" : "1024x1024", 61 | "scale" : "1x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "minimum-system-version" : "7.0", 7 | "subtype" : "retina4", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "idiom" : "iphone", 12 | "scale" : "1x", 13 | "orientation" : "portrait" 14 | }, 15 | { 16 | "idiom" : "iphone", 17 | "scale" : "2x", 18 | "orientation" : "portrait" 19 | }, 20 | { 21 | "orientation" : "portrait", 22 | "idiom" : "iphone", 23 | "subtype" : "retina4", 24 | "scale" : "2x" 25 | }, 26 | { 27 | "orientation" : "portrait", 28 | "idiom" : "iphone", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "2x" 31 | } 32 | ], 33 | "info" : { 34 | "version" : 1, 35 | "author" : "xcode" 36 | } 37 | } -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "explosions.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions.imageset/explosions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r3econ/sprite-additions/ced40347f33963522a6956e0f7b2321f340c060f/SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions.imageset/explosions.png -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions_debug.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "explosions_debug.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions_debug.imageset/explosions_debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r3econ/sprite-additions/ced40347f33963522a6956e0f7b2321f340c060f/SpriteAnimationDemo/SpriteAnimationDemo/Images.xcassets/explosions_debug.imageset/explosions_debug.png -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/MasterViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.h 3 | // SpriteAnimationDemo 4 | // 5 | // Created by Rafal Sroka on 11-11-17. 6 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 7 | // 8 | // 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining 12 | // a copy of this software and associated documentation files (the 13 | // "Software"), to deal in the Software without restriction, including 14 | // without limitation the rights to use, copy, modify, merge, publish, 15 | // distribute, sublicense, and/or sell copies of the Software, and to 16 | // permit persons to whom the Software is furnished to do so, subject to 17 | // the following conditions: 18 | // 19 | // The above copyright notice and this permission notice shall be 20 | // included in all copies or substantial portions of the Software. 21 | // 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | #import 32 | 33 | @interface MasterViewController : UIViewController 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/MasterViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.m 3 | // SpriteAnimationDemo 4 | // 5 | // Created by Rafal Sroka on 11-11-17. 6 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 7 | // 8 | // 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining 12 | // a copy of this software and associated documentation files (the 13 | // "Software"), to deal in the Software without restriction, including 14 | // without limitation the rights to use, copy, modify, merge, publish, 15 | // distribute, sublicense, and/or sell copies of the Software, and to 16 | // permit persons to whom the Software is furnished to do so, subject to 17 | // the following conditions: 18 | // 19 | // The above copyright notice and this permission notice shall be 20 | // included in all copies or substantial portions of the Software. 21 | // 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | #import "MasterViewController.h" 31 | #import "UIImage+Sprite.h" 32 | 33 | @interface MasterViewController() 34 | 35 | @property(nonatomic, weak) IBOutlet UIImageView *imageView; 36 | @property(nonatomic, weak) IBOutlet UILabel *lengthLabel; 37 | @property(nonatomic, weak) IBOutlet UILabel *locationLabel; 38 | @property(nonatomic, weak) IBOutlet UIView *settingsView; 39 | @property(nonatomic, weak) IBOutlet UISwitch *customRangeSwitch; 40 | 41 | @end 42 | 43 | @implementation MasterViewController 44 | 45 | #pragma mark - View lifecycle 46 | 47 | - (void)viewDidLoad { 48 | [super viewDidLoad]; 49 | 50 | [self setTitle:NSLocalizedString(@"Sprite Animation", @"")]; 51 | [self switchValueChanged:_customRangeSwitch]; 52 | } 53 | 54 | #pragma mark - Actions 55 | 56 | - (IBAction)buttonAction:(id)sender { 57 | if ([_imageView isAnimating]) { 58 | [_imageView stopAnimating]; 59 | 60 | [((UIButton *)sender) setTitle:NSLocalizedString(@"Start animation!", @"") 61 | forState:UIControlStateNormal]; 62 | return; 63 | } 64 | 65 | // This cool sprite sheet can be found at http://gushh.net/blog/free-game-sprites-explosion-3/ 66 | // I added numbers to this image to make testing and debuging easier. 67 | // 68 | UIImage *spriteSheet = [UIImage imageNamed:@"explosions_debug"]; 69 | 70 | if ([_customRangeSwitch isOn]) { 71 | NSRange range = NSMakeRange([_locationLabel.text intValue], 72 | [_lengthLabel.text intValue]); 73 | 74 | NSArray *arrayWithSprites = [spriteSheet spritesWithSpriteSheetImage:spriteSheet 75 | inRange:range 76 | spriteSize:CGSizeMake(128, 128)]; 77 | [_imageView setAnimationImages:arrayWithSprites]; 78 | } 79 | else { 80 | NSArray *arrayWithSprites = [spriteSheet spritesWithSpriteSheetImage:spriteSheet 81 | spriteSize:CGSizeMake(128, 128)]; 82 | [_imageView setAnimationImages:arrayWithSprites]; 83 | } 84 | 85 | NSLog(@"Sprite images: %lu", (unsigned long)[_imageView.animationImages count]); 86 | 87 | float animationDuration = [_imageView.animationImages count] * 0.100f; // 100ms per frame 88 | 89 | [_imageView setAnimationRepeatCount:0]; 90 | [_imageView setAnimationDuration:animationDuration]; 91 | [_imageView startAnimating]; 92 | 93 | [((UIButton *)sender) setTitle:NSLocalizedString(@"Stop animation!", @"") 94 | forState:UIControlStateNormal]; 95 | } 96 | 97 | - (IBAction)locationValueChanged:(id)sender { 98 | _locationLabel.text = [NSString stringWithFormat:@"%.0f", ((UIStepper *)sender).value]; 99 | } 100 | 101 | - (IBAction)lengthValueChanged:(id)sender { 102 | _lengthLabel.text = [NSString stringWithFormat:@"%.0f", ((UIStepper *)sender).value]; 103 | } 104 | 105 | - (IBAction)switchValueChanged:(id)sender { 106 | UISwitch *sw = (UISwitch *)sender; 107 | [_settingsView setUserInteractionEnabled:[sw isOn]]; 108 | 109 | [UIView animateWithDuration:1.0f animations:^{ 110 | if ([sw isOn]) { 111 | [_settingsView setAlpha:1.0]; 112 | } 113 | else { 114 | [_settingsView setAlpha:0.2]; 115 | } 116 | }]; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/SpriteAnimationDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/SpriteAnimationDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SpriteAnimationDemo' target in the 'SpriteAnimationDemo' project 3 | // 4 | // 5 | // This code is distributed under the terms and conditions of the MIT license. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining 8 | // a copy of this software and associated documentation files (the 9 | // "Software"), to deal in the Software without restriction, including 10 | // without limitation the rights to use, copy, modify, merge, publish, 11 | // distribute, sublicense, and/or sell copies of the Software, and to 12 | // permit persons to whom the Software is furnished to do so, subject to 13 | // the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | 27 | #import 28 | 29 | #ifndef __IPHONE_4_0 30 | #warning "This project uses features only available in iOS SDK 4.0 and later." 31 | #endif 32 | 33 | #ifdef __OBJC__ 34 | #import 35 | #import 36 | #endif 37 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/UIImage+Sprite.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Sprite.h 3 | // 4 | // Created by Rafal Sroka on 11-11-17. 5 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 6 | // 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | #import 29 | 30 | /** 31 | Useful UIImage category for handling sprite sheets. This add-on smoothes the way of extracting images from a sprite sheet (texture atlas). 32 | Note that for performance reasons you should not fire these methods every time you want to get the array of animation frames. 33 | You should rather fire it once and store the output array somewhere. This is because the Core Graphics image manipulation operations (especially on large images) are not so fast and your application may slow down. 34 | */ 35 | @interface UIImage (Sprite) 36 | 37 | /** 38 | The method returns an array with UIImages. Original sprite sheet is sliced into smaller chunks, each of the specified size. 39 | @param image the image with sprite sheet (texture atlas) 40 | @param size the size of the single chunk 41 | @returns the array of UIImages, each representing a single animation frame 42 | */ 43 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 44 | spriteSize:(CGSize)size; 45 | 46 | 47 | /** 48 | The method returns an array with UIImages. Original sprite sheet is sliced into smaller chunks, each of the specified size. 49 | @param image the image with sprite sheet (texture atlas) 50 | @param range the range of the chunks 51 | @param size the size of the single chunk 52 | @returns the array of UIImages, each representing a single animation frame 53 | */ 54 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 55 | inRange:(NSRange)range 56 | spriteSize:(CGSize)size; 57 | 58 | 59 | @end -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/UIImage+Sprite.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Sprite.m 3 | // 4 | // Created by Rafal Sroka on 11-11-17. 5 | // Copyright (c) 2011 Rafal Sroka. All rights reserved. 6 | // 7 | // This code is distributed under the terms and conditions of the MIT license. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining 10 | // a copy of this software and associated documentation files (the 11 | // "Software"), to deal in the Software without restriction, including 12 | // without limitation the rights to use, copy, modify, merge, publish, 13 | // distribute, sublicense, and/or sell copies of the Software, and to 14 | // permit persons to whom the Software is furnished to do so, subject to 15 | // the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | #import "UIImage+Sprite.h" 29 | 30 | 31 | @implementation UIImage (Sprite) 32 | 33 | 34 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 35 | spriteSize:(CGSize)size { 36 | return [self spritesWithSpriteSheetImage:self 37 | inRange:NSMakeRange(0, lroundf(MAXFLOAT)) 38 | spriteSize:size]; 39 | } 40 | 41 | 42 | - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 43 | inRange:(NSRange)range 44 | spriteSize:(CGSize)size { 45 | if (!image || CGSizeEqualToSize(size, CGSizeZero) || range.length == 0) { 46 | return nil; 47 | } 48 | 49 | CGImageRef spriteSheet = [image CGImage]; 50 | NSMutableArray *tempArray = [[NSMutableArray alloc] init]; 51 | 52 | CGFloat width = CGImageGetWidth(spriteSheet); 53 | CGFloat height = CGImageGetHeight(spriteSheet); 54 | 55 | NSUInteger maxI = (NSUInteger)(width / size.width); 56 | 57 | NSUInteger startI = 0; 58 | NSUInteger startJ = 0; 59 | NSUInteger length = 0; 60 | 61 | NSUInteger startPosition = range.location; 62 | 63 | // Extracting initial I & J values from range info 64 | if (startPosition != 0) { 65 | for (int k=1; k<=maxI; k++) 66 | { 67 | NSUInteger d = k * maxI; 68 | 69 | if (d/startPosition == 1) 70 | { 71 | startI = maxI - (d % startPosition); 72 | break; 73 | } 74 | else if (d/startPosition > 1) 75 | { 76 | startI = startPosition; 77 | break; 78 | } 79 | 80 | startJ++; 81 | } 82 | } 83 | 84 | CGFloat positionX = startI * size.width; 85 | CGFloat positionY = startJ * size.height; 86 | BOOL isReady = NO; 87 | 88 | while (positionY < height) { 89 | while (positionX < width) { 90 | CGImageRef sprite = CGImageCreateWithImageInRect(spriteSheet, 91 | CGRectMake(positionX, 92 | positionY, 93 | size.width, 94 | size.height)); 95 | [tempArray addObject:[UIImage imageWithCGImage:sprite]]; 96 | 97 | CGImageRelease(sprite); 98 | 99 | length++; 100 | 101 | if (length == range.length) { 102 | isReady = YES; 103 | break; 104 | } 105 | 106 | positionX += size.width; 107 | } 108 | 109 | if (isReady) break; 110 | 111 | positionX = 0; 112 | positionY += size.height; 113 | } 114 | 115 | return [NSArray arrayWithArray:tempArray]; 116 | } 117 | 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/en.lproj/MasterViewController.xib: -------------------------------------------------------------------------------- 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 | 52 | 65 | 66 | 67 | 68 | 77 | 83 | 92 | 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 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/explosions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r3econ/sprite-additions/ced40347f33963522a6956e0f7b2321f340c060f/SpriteAnimationDemo/SpriteAnimationDemo/explosions.png -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/explosions_debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r3econ/sprite-additions/ced40347f33963522a6956e0f7b2321f340c060f/SpriteAnimationDemo/SpriteAnimationDemo/explosions_debug.png -------------------------------------------------------------------------------- /SpriteAnimationDemo/SpriteAnimationDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SpriteAnimationDemo 4 | // 5 | // Created by Rafal Sroka on 11-11-17. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | // 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | // 11 | // Permission is hereby granted, free of charge, to any person obtaining 12 | // a copy of this software and associated documentation files (the 13 | // "Software"), to deal in the Software without restriction, including 14 | // without limitation the rights to use, copy, modify, merge, publish, 15 | // distribute, sublicense, and/or sell copies of the Software, and to 16 | // permit persons to whom the Software is furnished to do so, subject to 17 | // the following conditions: 18 | // 19 | // The above copyright notice and this permission notice shall be 20 | // included in all copies or substantial portions of the Software. 21 | // 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | #import 32 | 33 | #import "AppDelegate.h" 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | @autoreleasepool { 38 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /UIImage+SpriteAdditions.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "UIImage+SpriteAdditions" 4 | s.version = "1.0.1" 5 | s.summary = "Useful UIImage category for handling sprite sheets." 6 | 7 | s.description = <<-DESC 8 | UIImage Sprite Additions 9 | ============= 10 | 11 | Useful UIImage category for handling sprite sheets. This add-on smoothes the way of extracting images from a sprite sheet (texture atlas). 12 | 13 | This can be useful in UIImageView animations where animationImages array has to be filled with a set of images representing frames. UIImage-Sprite category makes this process trivial by introducing two methods: 14 | 15 | -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size; 16 | -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size; 17 | 18 | How to 19 | ======= 20 | 21 | There are two methods in UIImage+Sprite category. First one: 22 | 23 | -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size; 24 | 25 | The method returns an array with UIImages. Original sprite sheet (image) is sliced into smaller chunks, each of the specified size. 26 | 27 | Second method is very similar: 28 | 29 | -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size; 30 | 31 | This method does exactly the same thing as the latter. However, this time we can specify the range of the chunks we want to get. 32 | 33 | Note that for performance reasons you should not fire these methods every time you want to get the array of animation frames. You should rather fire it once and store the output array somewhere. This is because the Core Graphics image manipulation operations (especially on large images) are not so fast and your application may slow down. 34 | 35 | I wrote this add-on to facilitate the setup of short animations using UIImageView. For more complex animations I recommend using OpenGLES or SpriteKit. 36 | 37 | Demo 38 | ======= 39 | 40 | SpriteAnimationDemo project presents the usage of the UIImage+Sprite methods. The example shows how to create an animated UIImageView. This cool explosion sprite sheet which I included in the demo can be found at http://gushh.net/blog/free-game-sprites-explosion-3/. I added some numbers to this image to make testing and debugging easier. 41 | DESC 42 | 43 | s.homepage = "http://github.com/r3econ/UIImage-Sprite-Additions" 44 | s.screenshots = "http://dl.dropbox.com/u/7121070/github/UIImage-Sprite-Additions/1.png" 45 | 46 | s.license = { :type => 'MIT', :file => 'LICENSE' } 47 | s.author = { "Rafał Sroka" => "rafal.sroka.it@gmail.com" } 48 | 49 | s.social_media_url = "http://twitter.com/srokaraf" 50 | s.platform = :ios, '7.0' 51 | 52 | s.source = { :git => "https://github.com/r3econ/UIImage-Sprite-Additions.git", :tag => "1.0.1" } 53 | 54 | s.source_files = 'Classes/*.{h,m}', 'SpriteAnimationDemo/**/*.{h,m}' 55 | s.framework = 'CoreGraphics' 56 | s.requires_arc = true 57 | 58 | end 59 | --------------------------------------------------------------------------------