Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:30:03+00:00 2026-06-16T15:30:03+00:00

I want to make an animated sprite walking around. Therefore I use a sprite

  • 0

I want to make an animated sprite walking around. Therefore I use a sprite sheet with all the moves of a character and animate through the different animation stages.

Everything works fine on a PC with Firefox but with Chrome and on the iPhone the animation is partly broken. You can test it here on PC
http://fiddle.jshell.net/WnjB6/48/

and for iphone directly go here:
http://fiddle.jshell.net/WnjB6/48/show/

I found out that the second column of the spritesheet is not being shown during animation on iphone only. With smaller spritesheets this is working. See here

PC
http://jsfiddle.net/WnjB6/7/

iphone
http://jsfiddle.net/WnjB6/7/show

Is there a limitation on file size for iphone or how Chrome handles images?

here is the source

var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');

// Constructor for an animation object
// image: graphics source
// x, y: position to draw the animation
// width, height: size of each tile
// htiles: number of tiles horizontally in the image source
var Animation = function(image, x, y, width, height, htiles) {
    this.image = image;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.htiles = htiles;
    this.animations = {};
    this.currentAnimation = [0];
    this.currentFrame = 0;
}

// Add animation to the object
Animation.prototype.add = function(name, frames) {
    this.animations[name] = frames;
};

// Select animation by name
Animation.prototype.play = function(name) {
    this.currentAnimation = this.animations[name];
    this.currentFrame = 0;
};

// Advance animation, and draw the tile
Animation.prototype.nextFrame = function() {
    // Move to next frame in current animation
    this.currentFrame = (this.currentFrame + 1) % this.currentAnimation.length;
    // Extract which image tile that is
    var tile = this.currentAnimation[this.currentFrame];
    this.drawTile(tile);
};

// Draw the given tile at the current position
Animation.prototype.drawTile = function(tile) {
    // Clear region we are going to draw on
    context.clearRect(this.x, this.y, this.width, this.height);
    context.drawImage(this.image, (tile % this.htiles) * this.width, Math.floor(tile / this.htiles) * this.height, this.width, this.height, this.x, this.y, this.width, this.height);
};

// Initialize the animation
var image = new Image();
image.src = 'http://www.playa.cc/pic/playerstant.png';

var player1 = new Animation(image, 0, 0, 51, 51, 2);
var aniStates = ['stand', 'right', 'walk'];
player1.add(aniStates[0], [65, 67, 69, 71, 73, 75, 77, 79]);
player1.add(aniStates[1], [0, 2, 4, 6, 8, 10, 12, 14, 16]);
player1.add(aniStates[2], [72, 74, 76, 78, 1, 3, 5, 7, 9]);


// Start with the walking animation, and start animating
player1.play(aniStates[0]);
var interval = setInterval(function() {
    player1.nextFrame();
}, 200);

// Toggle animation between standing and walking every 3 seconds
var mode = 0;
setInterval(function() {
    player1.play(aniStates[mode++]);
    mode = mode % aniStates.length;
}, 3000);

Thanks
stot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:30:04+00:00Added an answer on June 16, 2026 at 3:30 pm

    To give a short answer to a long question:

    Chrome and Safari on iPhone dont show images on canvas when the clipping is partly out of the original image. For example, your image has dimensions x:100, y:100 and you draw with

    context.drawImage(image, 0, 0, 101 /* error */, 100, 0, 0, 100, 100)

    see also drawImage spec

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs which I want to animate: <div id="character"> <div id="sprite"></div> </div>
I want to make a layout animated through translation animation from screen's particular X
I'm trying to make a sliding panel using .animate function because I want it
I have style sheet with a class name changebackgroundcolor i want make change in
Basically, I want to make bunch of Shapes and make them animated. So I
I've looked around a bit for a great JavaScript Sprite Sheet animator lib/engine but
I want to make an animated background for iphone app. Something simple 5-6 frames
I am new to unity3d I want to make a path for animated object.
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make a bash script which returns the position of an element from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.