Character (sprite) animation

What is the best way to handle character animation on the iPhone.
Is using the UIImageView method the best to handle simple sprite animation using a number of PNG's.
Is there a limit to the number of PNG images you should use?
Also what is the best way to handle simple effects like zoom and pan, on a block of animation?
Can a block of animation follow a curved path. e.g. a character walk cycle moving over a hill.
I appreciate any response. I have a background in 2D animation and need some direction to how best to create animations on the iPhone and also what limitations I am up against.
Thanks, Steve

Okay, that is something different. I misunderstood what you meant by 'animation'.
Moving 2D sprites in a game is done by creating a virtual model of the game world in the code that represents game objects by their positions in 2D space and their "movement" as a numerical velocity vector that specifies the number of pixels that the object should move per unit time. Time is simulated by updating the objects' position and redrawing the screen at some fixed time interval (the frame rate) determined by a timer.
Here is a simple ball animation sample that assumes you have a 48x48 pixel image named ball.png. It creates a UIView subclass that should be loaded by the AppDelegate class.
The header:
#import <UIKit/UIKit.h>
typedef struct
CGFloat x;
CGFloat y;
} Vector2D;
typedef struct
Vector2D position;
Vector2D velocity;
} Sprite;
@interface GameWorld : UIView {
Sprite ball;
UIImageView *ballImage;
@end
and the implementation:
#import "GameWorld.h"
#define kDotRadius 24
@implementation GameWorld
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[UIApplication sharedApplication].statusBarHidden = YES;
ball.position.x = 200.0;
ball.position.y = 300.0;
ball.velocity.x = 3.0;
ball.velocity.y = -3.0;
ballImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball.png"]];
[self addSubview:ballImage];
[NSTimer scheduledTimerWithTimeInterval:(1.0 /30.0) target:self selector:@selector(update) userInfo:nil repeats:YES];
return self;
-(void)update {
if(ball.position.x - kDotRadius <= self.bounds.origin.x || ball.position.x + kDotRadius >= self.bounds.size.width)
ball.velocity.x *= -1.0; //negate to reverse direction
if(ball.position.y -kDotRadius <= self.bounds.origin.y || ball.position.y + kDotRadius >= self.bounds.size.height)
ball.velocity.y *= -1.0;
//commit to changes
ball.position.x += ball.velocity.x;
ball.position.y += ball.velocity.y;
[self setNeedsDisplay];//refresh the view
- (void)drawRect:(CGRect)rect {
ballImage.center = CGPointMake(ball.position.x, ball.position.y);
- (void)dealloc {
[super dealloc];
@end
So it is the UIImageView's center property that is used to create the movement of the image view across the screen. This could be done directly, but the use of C structs (Vector2D and Sprite) make the code easier to read. The center property is updated only at the moment when the screen redraw occurs.

Similar Messages

  • Issues when creating sprite animations. [was: Adobe CC please help!]

    I was watching a tutorial on how to create sprite animations when I ran into a little bit of a problem. I was trying to animate a koopa walking, but when I viewed the results the rest of the stuff disappeared! It was for CS6, but It wasn't to different.

    Matt421421 wrote:
    Dude, The title and the community. Open your eyes.
    You did not answer the question with a program name... this is the general Cloud forum
    Provide the name of the program you are using so a Moderator may move this message to the correct program forum
    This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

  • J2me sprite animation

    Could someone please help me? I need a simple j2me program. I needed to display on my phone a simple sprite animation.
    Thank you!!!

    No. We realise that would make it easy for you, whichis precisely why we are not going to do it.
    jugheadwhat exactly is that supposed to mean? Go on then, give him some 'sample' code, that will really help him learn. The ONLY way to learn is to teach yourself, and build associations for yourself. If you just use someone else's code (and sample code will just be used like that), then how are you going to do that?

  • Best way to handle Sprite animation

    Hi all,
    Comments on overheads (memory/performance) on the following techniques?
    These are overly simplified, but you get the idea?
    Bitmap.visible
    // Assume we have a bunch of sprites already in memory as bitmap data
    var spriteData : Vector.<BitmapData>;
    // Now we create a sprite for each 'frame' of animation
    var bitmaps : Vector.<Bitmap> = new Vector.<Bitmap>();
    var bitmap : Bitmap;
    for (var i:int=0; i<spriteData.length; i++){
         bitmap = new Bitmap( spriteData[i] );
         addChild(bitmap);
         bitmaps.push(bitmap);
         bitmap.visible = false;
    // Now when we animate we simply set bitmaps visiblity
    public function gotoAndStop( frame : int ):void{
         bitmaps[ currentFrame ].visible = false;
         currentFrame = frame;
         bitmaps[ currentFrame ].visible = true;
    BitmapData replacement
    // Assume we have a bunch of sprites already in memory as bitmap data
    var spriteData : Vector.<BitmapData>;
    // Now we create a single sprite
    var bitmap : Bitmap;
    addChild(bitmap);
    // Now when we animate we swap bitmap data
    public function gotoAndStop( frame : int ):void{
         bitmap.bitmapData = spriteData[ frame ];
    I haven't performed this test on mobile yet - just wanted to get thoughts first.  Obviously if the animation has a lot of frames then the top one has a huge overhead, but is there a performance hit to swapping the bitmapData of a bitmap?
    Cheers,
    Peter

    This page has a good review that may be helpful:
    http://blog.starnut.com/flash-to-ios-performance-tests/

  • Frame(sprite) animation delay problem

    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class ExampleTrialCanvas extends GameCanvas implements Runnable {
    private boolean isPlay; // Game Loop runs when isPlay is true
    private long delay; // To give thread consistency
    private int currentX, currentY; // To hold current position of the 'X'
    private int width; // To hold screen width
    private int height; // To hold screen height
    // Sprites to be used
    // private Sprite playerSprite;
    private Sprite backgroundSprite;
    private Sprite playerSprite;
    //private int i;
    // Layer Manager
    private LayerManager layerManager;
    // Constructor and initialization
    public ExampleTrialCanvas() throws Exception {
    super(true);
    width = getWidth();
    height = getHeight();
    currentX = 64;
    currentY = 150;
    delay = 100;
    // Load Images to Sprites
    Image playerImage = Image.createImage("/transparent.png");
    playerSprite = new Sprite (playerImage,32,32);
    Image backgroundImage = Image.createImage("/gillete.png");
    backgroundSprite = new Sprite(backgroundImage);
    layerManager = new LayerManager();
    layerManager.append(playerSprite);
    layerManager.append(backgroundSprite);
    // Automatically start thread for game loop
    long now, prev_time_moved;
    public void init(){
    now = System.currentTimeMillis();
    prev_time_moved = now;
    public void start() {
    isPlay = true;
    Thread t = new Thread(this);
    t.start();
    public void stop() { isPlay = false; }
    // Main Game Loop
    public void run() {
    Graphics g = getGraphics();
    while (isPlay == true) {
    input();
              drawScreen(g);
    try { Thread.sleep(delay); }
    catch (InterruptedException ie) {}
    // Method to Handle User Inputs
    private void input()
    int keyStates = getKeyStates();
    playerSprite.setFrame(0);
    // Up
    if ((keyStates & UP_PRESSED) != 0) {
         for(int i=0;i<5;i++)
         playerSprite.setFrame(i);
    // Method to Display Graphics
    private void drawScreen(Graphics g) {
    // updating player sprite position
    playerSprite.setPosition(currentX,currentY);
    // display all layers
    layerManager.paint(g,0,0);
    layerManager.setViewWindow(55,20,180,180);
    //layerManager.paint(g,20,20);
    flushGraphics();
    We want, on right click botton press the frame should animate.
    We have a player with 5 different poses, kicking a ball, "image width is 160, height is 32".
    the problem is that, the player does move through allthe frames. he starts from 0th p\frame and directly end at the last frame, withopur any delay between frames.
    we have used the for loop as follows.
    if ((keyStates & UP_PRESSED) != 0) {
         for(int i=0;i<5;i++)
         playerSprite.setFrame(i);
    we want a delay code between all the frames.

    Maybe this will help you!
    btnSignIn.addActionListener(new ActionListener()     
                                  public void actionPerformed(ActionEvent e)
                                      //display the glasspane first
                                      setGlassPane(new MyGlassPane(newAnimatedIcon("images/LoginWaitingIcon.png")));
                                      getupGlasPane.setVisible(true);        //expected the glassPane shows (it does), and the animation starts (it doesnt)
                                      Thread t1 = new Thread(new Runnable()    //The animation only starts when this thread finished
                                            public void run()
                                                 //DO THE REST
    t1.start();
    t1.join();
    setupGlasPane(false);   //finish, turning off
                       });

  • Sprite animation with double buffering

    Hello, I am writing a game. I am not using swing. Just awt.
    I have several books I am looking at right now. One uses the
    BufferedImage class to create a buffered sprite. The other book instead uses the Image class to impliment double buffering. So, I am really confused now. I do not know if I should use the BufferedImage class or the Image class. Note that
    Please help. Which method is the best to use?
    Val

    These links may assist you in full-screen animation with double-buffering:
    http://www.sys-con.com/java/article.cfm?id=1893
    http://www.meatfighter.com/meat.pdf
    - Mike

  • J2ME - Sprite Animation example

    Hi i am new to J2ME programming and was wondering if there is a simple animation example/tutorial showing the use of sprites or an animated images the one show here on the java site was a little bit to complex for a beginning developer. Your help would be greatly appreciated.
    Thanks
    sengaste

    e-mail me to [email protected]
    and i give you an example

  • Troulble slowing down sprite animations

    Hi guys! Well, I looked all over but couldn't find an answer. What I want to do is slow down the animation of a sprite. I have a working sprite class called AnimationSprite that loops through an array of images when it updates. The problem is that when my soon-to-be game is running at its frame rate (approx. 32) the "Animation Sprites" are looping through their animations too fast. I couldn't really think of a way to set a delay on their animations. I thought of using a Timer to run a TimerTask that increases the sprites' current frame at a sertain rate. Is this a good idea? Also, does GAGE run on Mac OS X? When I download it it just unzips an empty folder that doesn't contain any data.
    Anyways,
    Thanks for your time.

    static final ANIMATION_DELAY = 200;
    static final ANIMATION_FRAMES = 32;
    int counter = 0;
    //your animation loop
    g.drawImage(animFrame[(counter*ANIMATION_FRAMES)/ANIMATION_DELAY],x,y,null);
    if(++counter==ANIMATION_DELAY) counter=0;

  • Smooth object/sprite animation.

    Trying to make a smooth scroller in Flex and found the
    callLater method that looks good for updating position of sprites,
    my question is if anyone know how often this method is called?,
    need to refresh objects position quite frequently and is the usage
    of callLater the right way of doing this kind of sprite moving in
    flex, or is there better ways?
    Any ideas?

    > I've created some basic animations in flash at 24fps and
    published them.
    > When
    > viewing the .swf file the animation is smooth. But once
    I import them into
    > my
    > captivate project (set to 24fps) and view the published
    presentation some
    > of
    > the animations appear jery and not fluid at all.
    are you testing in Preview mode, or are you testing a
    published file? Just
    wondering ... if you are previewing you **might** get better
    performance
    once published.
    Steve
    Adobe Community Expert: eLearning, Mobile and Devices
    My blog -
    http://stevehoward.blogspot.com/

  • Best method for animated bitmap sprites with GPU?

    I've been looking at how GPU Hardware Acceleration is achieved with cacheAsBitmap and cacheAsBitmapMatrix which I understand for static bitmap sprites (+rotation/scale) but I don't quite understand how this would be used to animate a sprite that had different animation frames.. in terms of what is done by the GPU and what is done by the CPU
    eg potential scenarios:
    1) cache sprite sheets to GPU. use copyPixels to blit the various sprites to a single canvas. In this case presumably the canvas would not be GPU accelerated because it is constantly changing every frame. Is there in fact any benefit of having the sprite sheet cached here? is the GPU actually used for the blit onto the CPU-rendered canvas?
    2) cache individual sprite bitmap(data) frames on the GPU. use object pooling for game character sprites and add them to stage on startup. Change the bitmap every frame dynamically,  for animated sprites, to one of the cached bitmapdata textures. is the GPU actually being used in this case to change the bitmap of the sprite? or is it forced to CPU processing again?
    The only scenario I currently know should be GPU accelerated is if I use a cached sprite that doesn't animate (other than rotating and scaling with the bitmap matrix).
    thanks for any advice
    J

    J, I believe (2) is how it is currently done. A better method is required! - basically the same question I have that you are helping me with . That link to 'Yeah, but is it Flash' in my post shows an example of exactly that method (individual BitmapData for each frame).
    Just for completeness I will add the one from my post (though unsure if it is even possible):
    (3) Single BitmapData sprite sheet cached to GPU. Each Bitmap that uses this sprite sheet can somehow specify the x,y,width,height of the frame within this sprite sheet to use.

  • How to use Sprites in animation.

    Umm hi I would like some help on how to use sprites (8 or 16
    bit characters from games) to make an animation could any one
    provide me a link to any sprites animation or a link on how to do
    it. It will help much.
    Mr.Idiot

    if you have Flash, this is one of the main things that it
    does. open up your help file documentation, and start reading at
    the beginning, it will tell you all you need to know and introduce
    you to the basic concepts of the program.

  • Control the character animation in adobe edge

    Hello ,
    i have a character, i want to control the animation to use left arrow key and right arrow key.
    When i press left arrow key the character run animation call.
    When i press right arrow key character back run animation call.
    when user don't press any key the character stop animation call.
    Please help me, i am designer i don't know codding/
    Thanks
    Chetan Thakur

    Hi,
    Try this tutorial and see if this helps
    http://www.heathrowe.com/adobe-edge-simple-keydown-trigger-animation/
    The right arrow key is 39 and left 37
    if (e.which == 37) {     // key left
    this.play("sun");    //name of your character instead of sun
    Hope this helps

  • Animating Sprites the slow poke approach...

    Hi there, I've got a small application which features small creatures controlled by some fearsome AI dashing around a randomly generated environment trying to kill each other. (it's somewhat more complex than that, but you get the gist). Rather than do the sensible thing and look for examples of Sprite animation, I just got stuck in, thinking, what the hell, I'll give it a shot. This is what I came up with....
    AnimationCanvas class extends JComponent, this is where all the animation stuff is drawn.
    SpriteManager class, contains a vector of all the sprites and is responsible for updates
    abstract Sprite class, provides an extensible template for sprites, I've got things like TreeSprite and RockSprite. Some of the sprites are composite sprites, comprising of several images which are overlapped slightly, an example of this is my AgentSprite it requires a total of 52 images, I load these using a MediaTracker when the object is instanciated before the app is displayed. They are all small images, less than 1k. The animation is done through the use of a Swing Timer which repaints the scene after a delay of 1000/24 ms, which I assume gives me 24fps ( is there a way of checking the fps? ) the AI portion of the app. updates the position of the sprites via the SpriteManager and also tells the Sprite what images to use. This works sweet on Win XP with my 2Ghz machine, but the target was to have it run on anything that runs Java 1.4 +. Running it under Linux on a PIII 500 for example is like watching paint dry. Great! Soooo I can only assume it is my inept implementation that is causing the problem, I have had a little look around and have seen a few people just using a single image with many sprites on it, using a PixelGrabber to get the desired bits, is this a more efficient method? Or does pre-loading the images with a MediaTracker do a better job? Or should a time my animation a different way? I would appreciate it if you could give me a tip or two.... I'm happy to post code snippets, but there's a fair ammount, specific bits might be easier... or if some of you are particularly adventurous i can put the source code up on the net for you to d/l and have a little look at :-)
    Cheers,
    Tom

    My source code, images and pre compiled classes are now available here...
    http://www.macs.hw.ac.uk/~ceetfc/ait/ait.zip

  • Looking for a more suitable animation tool

    I've been creating animations from sprites in After Effects, with mixed results.  The input is a number of pixel art sprites (exported from elsewhere), and the output is a video, characters running around and interacting.  I have AFX doing quite a lot, but it's very awkward and I'm pretty sure it's the wrong tool for the job.  Can anyone either suggest better approaches, or more suitable software?  I'll describe what I'm doing now:
    - Many sprites are bodies or heads to combine, eg. a smiling or angry faces and walking or standing bodies.  I set the head position for each body sprite, so any head fits in the right place on any body (trivial rigging), then apply it with a script, so I can change the body and the head moves to the right place automatically.
    - Some sprites have multiple layers.  For example, while heads are normally on top of bodies, a body may have an arm raised, which needs to be above the head instead of below it.  I can create the extra layer for the body separately, and it works for any head.
    - I can set the draw order per-layer.  Usually, one character and all of its parts is drawn on top of another--body1, head1, body2, head2.  But, if two characters collide, handshake, or interact in other complex ways, I may want to draw both bodies, and then both heads, even though the heads and bodies are still anchored normally.  Some sprites may have multiple layers, eg. body, head, hands, legs.  (Z position hack...)
    - Individual layers can be adjusted separately, eg. to adjust the default head position downwards to give a nod.
    - Some sprites are hue shifted (hair color, clothing color) or have more complex adjustments applied, so I can reuse more sprites.
    (I'm only describing what I'm doing and not how.  I wrote more detail about what I'm actually doing in AFX and the specific issues I'm having, but it was too long and people can probably already guess the practical issues of using AFX like this.  I'll post more info if anybody asks.)
    The result is functional, but a real hassle to actually work with.  AFX is a compositing and effects tool and it's not really designed for animations, and only its scripting support has let me abuse it this much.  I don't know of a better tool, though--searches for animation tools mostly come up with things like Spine (authoring individual models for importing into games), and nothing suitable for creating complex video animations from sprite sets.
    There are probably many tools to do small pieces of this (sprite animation sequences, effects, scene animation, camera), but I'd really like to not split into a multi-tool workflow, since I want to experiment freely with a scene, not lay out an entire scene and then create it start to finish.  Does anyone have any suggestions (or better places to ask)?

    There are many other DTP applications:
    http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=137&mforum=iworktips ntrick
    You have to be more specific about what you are looking for.
    Peter

  • Can armatures be made into nested animation (symbol/movies)?

    1) Can armatures be made into nested animation (symbol/movies)?
    I made a dragon character and animated the body with the amature(bone tool) in flash cs5.  I was having trouble trying get it to become a nested animation and make it into a symbol/movie.  I heard you are suppose to select all the animated frames using EDIT> TIMELINE>COPY FRAMES, then pasting the animated frames into new symbol/movie. I have no luck with that, the menu becomes dimmed out from copying the frame...I'm not sure if nesting animations with amatures is possible?  Any ideas?  Thanks.
    I was planning to get the body into nested animation, then attached seperate movie with flagging wings along a guide path.
    2) Second question.  I don't know why flash cs5 is exporting it's animation a lot differently from gif to swf.  In the gif format it doesn't show the nest animation.  Here's an example.  The wings on the dragon animate fine in swf format but when converted to gif.  The wings don't move.

    It's very interesting -- there's some bug in the file -- even if some layers are not visible, when I double-click the text layer you are supposed to edit (the Symbol), other layers with text start to appear...
    Not sure what's causing this. I would suggest to log a bug here:
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    ...explain the steps and attache the PNG.
    And if you break the Symbol apart (select it > Modify > Symbol > Break apart) and then try to edit the text, all works normally as expected. Use this as a workaround -- I don't have a better suggestion for now...
    I have made the tests with Fw CS5...

Maybe you are looking for