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
                   });

Similar Messages

  • PSE 7+ Sudden Animation Time Delay problem?

    I've been using Photoshop Elements 7+ for a long time now. And I've been able to make animations with it. Such as can bee seen on this url: http://i47.tinypic.com/35iumww.gif I know how to change the Time/Frame delay settings quite fine. But as of today my time delay hasn't been working. This is quite random considering I haven't done any kind of updating or editing to the program in general. When trying to set the time delay to 0.15 and clicking the preview button, I find that my animation is as at the default number's speed, 2. Upon changing the time delay many different times, from 0 to 10 (the min and the max), the animation's speed still doesn't change.  I'm at the end of my rope with this and none of my PSE educationed associates know what could possibly be wrong. I did download two fonts today, but that's it. So unless someone might be able to figure out what's changed, then I might have to try and re-install the program. Something I don't want to do. I have a visual if that's of any help.
    http://i47.tinypic.com/e9w64k.png
    Also, I am using a Mac.

    Which version are you using now? You can't be using PSE 7 on a mac, because there is no PSE 7 for mac. The frame delay problem exists in the mac versions 6 through 10. You can either upgrade to PSE 11 or use a program like the free giffun from stone.com to assemble the gif and set the frame rate.

  • Animations delays 1 frame with gotoAndPlay() in CS3

    Hello people! Has anybody found this problem with timeline
    animations in Flash CS3?
    I have an animation that when it reaches frame 10 does a
    gotoAndPlay(5) but when the head goes to frame 5 it shows the frame
    twice and then goes to the next frame, so the animation delays 1
    frame.
    If you want to check it out, put the movie at 1fps to see the
    delay easily.
    This doesn't happen in Flash 8. But it does in Flash CS3.
    Anyone knows a solution?

    I posted this issue:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=288&threadid=1301078
    sounds like the same AS3 issue ; (

  • Keynote 3: Transparent Animated GIF Problems

    I've been trying to get an animated GIF with a transparent background to run in Keynote, but it's giving some disastrous results.
    I produce the animation by rendering the frames as PNG (with alpha channel) in MegaPOV 1.2.1. Then I use the convert utility from ImageMagick 6.2.9 to make them into an animated GIF.
    When I drop the animated GIF into Keynote 3.0.2, the first frame shows fine (with transparency and all). But when I animate it, the background goes red (the main color in this particular movie) and some trace of the previous frames stays. It seems like:
    1. Rather than displaying the GIF frame-by-frame, each frame is getting layered onto the previous frames.
    2. Keynote doesn't like the alpha channel for some reason.
    Problem 1 is also present if I open the GIF in Preview (is that supposed to be the correct behavior of an animated GIF?). Problem 2 seems to be Keynote-specific.
    Any suggestions for a work-around on this? The animated GIFs work fine if rendered without the alpha channel, but it'd look so much better with transparency!
    iMac 2GHz Intel Core 2 Duo   Mac OS X (10.4.9)  

    MegaPOV doesn't have a GIF output option. The choices are PNG, Targa, PPM, and hdr (not familiar with that last one). I don't know if PPM even has alpha-capability.
    So in some way, I have to convert PNG to GIF. The tools I have to do this are ImageMagick and Gimp. I tried them both, then viewed the results using several programs. Results are tabulated below -- (1) means that problem 1 from above was apparent (ie, parts of the previous frames were visible under the current frame); (2) means that problem 2 was visible (ie, the transparent parts took on some background color).
    If I didn't know how to change the default white background in the program, I couldn't tell whether problem (2) occurred, since the movie made with Gimp had a white background in Keynote.
    Using ImageMagick 6.2.9 to convert PNG->GIF and animate GIF:
    * viewing with Safari 2.0.4 : (1), can't tell for (2)
    * viewing with Preview 3.0.9 : (1), can't tell for (2)
    * viewing with Firefox 2.0.0.3 : (1)
    * viewing with Keynote 3.0.2 : (1), (2) -- alpha goes red
    Using Gimp 2.2.11 to convert PNG->GIF and animate GIF:
    * viewing with Safari : (1), can't tell for (2)
    * viewing with Preview : (1), can't tell for (2)
    * viewing with Firefox : (1)
    * viewing with Keynote : (1), (2) -- alpha goes white
    I only converted the first few frames using Gimp, since I was doing it by hand.
    All of this makes me wonder whether I'm dreaming the impossible, since problem (1) is universally present. It also makes me pretty sure that problem (2) is Keynote-specific.
    If there are any other tools that will convert/animate GIFs on a modern Mac, I'd love to hear about them. My UNIX-y tools seem to be failing me here. The Mac tools I remember from "back in the day" -- GIFBuilder and GIFConverter -- seem to have been abandoned around the beginning of Mac OS X. GIFBuilder won't even load my files, and GIFConverter still lacks alpha support in PNG.

  • 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/

  • CS5 Animation Timeline problems (display/graphics glitches)

    In CS5 12.0.5 x64 I use the Animation Timeline to create frame by frame animations and most of the time it works fine. However recently I am encountering a problem with the display. The problems seem to happen whenever I make a selection with the lasso and do a Free Transform (it especially doesn't like rotations). The 'marching ants' along with the entire display seems to freeze up and not respond. Clicking other layers will not change the 'frozen' image until I make a stroke with the tablet or mouse, then the image refreshes to the new selected layer, but stays frozen in the same way, and so on. The animation in the timeline will not playback through the frames/layers once this happens and I have to restart the program. Then the bug happens again as soon as I make another free transform. It doesn't seem to affect all my files, only certain ones where I use the Animation Timeline.
    I have an i7 processor with 12gb of ram and an EVGA Geforce GTX 560 Ti with the latest drivers. I have OpenGL turned off and have deleted my preferences.
    Here are my performance settings (this may be the problem?):
    I Let Photoshop Use 6319 MB (58%)
    My History States are 65
    Cache Levels are 4
    Cache Tile Size is 128K
    Scratch Disk is just C:\

    It kind of sounds like a memory or video driver issue. What resolution is your document set at?
    Mylenium is correct. When creating frame based animation each frame is linked to a layer. So to animate the motion of the selected portion it needs to be on new layers as it moves (each time you rotate or move, create a new layer. The smaller the increment the more layers needed, but will produce a smoother longer animation). The stationary portion(s) don't need to be on new layers because they are not moving and can be seen due to the transparent areas around the selection.
    I hope that  makes sense.

  • 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 ???

  • 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.

  • What I've noticed about the Video Delay Problem of...

    I was able to take a look at my old vids from way back V110. I've noticed everytime they improved the camera pictures, the video & audio sync suffer. My old videos didn't have audio delay problems even if they were more than a minute long.

    I ordered 2 iPhone 4's from the AT&T Premier site on July 9 (my company has an agreement with AT&T). My credit card company immediately flagged the purchase as possible fraud, so it took a day or two to clear that up. The order went to "Processing" status on the AT&T Premier site on July 12. It stayed in that status until yesterday, July 20, when it changed to a status of "Shipped" and I got an email from AT&T with the FedEx tracking number. FedEx says that the phones shipped from Texas yesterday night and are on schedule to be delivered to me in Connecticut today (July 21). That's only 8 business days and includes the screw up from my credit card company - better than I expected. The "Processing" time probably included the time it took to ship the phones from Apple's factory in China to the AT&T facility in Texas.
    By the way, here's the deal I got from AT&T Premier:
    $38.50 - 550 shared minute plan (1st iPhone)
    $ 9.99 - Additional line (2nd iPhone)
    $19.25 - 2Gb personal data (1st iPhone)
    $19.25 - 2Gb personal data (2nd iPhone)
    $ 0.00 - pay as you go texting

  • How to fix the delay problem while recording? Can't set the Latency to 0. Win7, CS6,Realtek,C03u Mic

    I am using Win7, with CS6, Realtek soundcard and Samson C03U microphone.
    There is a problem that's really been bothering me. When I record songs the recorded audio always comes 0.1 seconds after where it's supposed to be and I need to fix the problem every time. How to fix the delay problem while recording? I can't set the Latency to zero. The minimum is 30ms and I still get an obvious delay.
    I saw some previous discussions saying that installing ASIO would help. Is it gonna work on my PC?
    Thank you in advance guys.

    You probably should look at a more 'serious' audio interface rather than the Realtek
    Yes ASIO drivers are the way to go
    If you want zero latency you need to monitor via your audio hardware (hence the 'serious' audio interface suggestion)
    There are a heap of reasonable audio interfaces which will do the job for you that are pretty inexpensive and I'm sure that someone will jump in with a suggestion

  • HT6114 Delaying problem when switching desktop

    After upgrading to Mavericks v10.9.2 Update my "Macbook pro Retina, 15-inch, Early 2013" is delaying when switching desktops or switching to mission control. An overall delay problems occured. I need help!

    First off, I meant to title this "When switching spaces application window is not showing."
    Just in case anyone else runs into this problem or any other weirdness with switching between spaces, the answer seems to be trashing the com.apple.dock.plist file and then restarting the dock. The preferences file can evidentially get corrupted and create some problems. Spaces does not have it's own plist file but stores it's data in the dock's plist file. Be warned that this will reset all of your dock preferences including which apps you have on the dock.
    Mark

  • 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?

  • Animated Gif - Problem with Frame Delay

    Mac OS X 10.5.8 
    PSE 6.0
    I just created an animated gif by following the steps in PSE Help.  It says that I should be able to adjust the rate at which the images rotate by changing the Frame Delay measurement but I am unable to change it.  In fact I am unable to change anything in the Animation section of the dialog box. 
    When I check Animation, the options appear to become active (they're no longer greyed out) but I can neither uncheck the Loop option nor change the Frame Delay option.  All other sections of the dialog box work fine.
    Your help would be most appreciated!
    Beth

    Unfortunately this is broken in PSE 6 and PSE 8. You can tab into the frame delay box if you start above it someplace on that side of the screen, and it appears to let you change the rate, but your choice doesn't really affect the actual frame rate. The only workaround is to duplicate frame layers that you want to stay onscreen longer (so it will be changing just as fast, but not visibly).

  • 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;

  • Animated Gif Problem

    Greetings
    I would appreciate some help.
    I am new at creating animated gif's, and am experiencing a
    problem with them when I try to view them in a browser.
    I am working in Fireworks 2004, the following is what I do.
    Create first frame.
    Insert simple arrow.
    Create second frame
    Insert simple arrow with diffrent color
    Third frame same but diffrent image.
    Set the Optimize Panel to Animated Gif, transparency set to
    No tranparency.
    Click on File, Export.
    Type the name of the file in File Name box.
    Select "Frames to Files" option for Save as type option.
    In my folder where I saved the files there are now three gif
    files.
    When I open the file into the following browsers IE 7, 6.0 or
    Firefox it remains as a static image in the browser with no
    animation, the same is for viewing it in Window Explorer Preview
    Pane.
    In Fireworks however the animation plays perfectly.
    I would really appreciate it if someone could tell me what I
    am doing wrong or why they created animated gifs are not playing in
    the browser.
    Regards
    Dave

    Instead of Frames to files on export, select Images only.
    that should do it -
    alex
    revbear wrote:
    > Greetings
    >
    > I would appreciate some help.
    >
    > I am new at creating animated gif's, and am experiencing
    a problem with them
    > when I try to view them in a browser.
    >
    > I am working in Fireworks 2004, the following is what I
    do.
    >
    > Create first frame.
    > Insert simple arrow.
    > Create second frame
    > Insert simple arrow with diffrent color
    > Third frame same but diffrent image.
    >
    > Set the Optimize Panel to Animated Gif, transparency set
    to No tranparency.
    >
    > Click on File, Export.
    > Type the name of the file in File Name box.
    > Select "Frames to Files" option for Save as type option.
    >
    > In my folder where I saved the files there are now three
    gif files.
    >
    > When I open the file into the following browsers IE 7,
    6.0 or Firefox it
    > remains as a static image in the browser with no
    animation, the same is for
    > viewing it in Window Explorer Preview Pane.
    >
    > In Fireworks however the animation plays perfectly.
    >
    > I would really appreciate it if someone could tell me
    what I am doing wrong or
    > why they created animated gifs are not playing in the
    browser.
    >
    > Regards
    > Dave
    >
    >

Maybe you are looking for