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 8470015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:23:40+00:00 2026-06-10T16:23:40+00:00

This is the sprite I am using to animate an object through css. Every

  • 0

enter image description here

This is the sprite I am using to animate an object through css. Every frame is 224px in width so the background-position property of the div is incremented by -224px every frame and the cycle goes on. The problem is that the width of my div is not fixed. I use percentage width of the div to stay resolution independent. So I want my 224px wide frame to scale over the width of the div and move left the same amount every frame. Hope it is clear to you. Here is the JS function used to animate the div.

function moveTail() {
    if ( typeof moveTail.counter == 'undefined' ) {
        moveTail.counter = 0;
        moveTail.object = $('#genietail');
    }

    if( moveTail.counter == 42 )
        moveTail.counter = -1;
    ++moveTail.counter;
    moveTail.object.css('background-position', moveTail.counter*-224 + "px 0px" );
}
  • 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-10T16:23:41+00:00Added an answer on June 10, 2026 at 4:23 pm

    There are two ways of scaling a sprite image.

    The first one is to play with the background-size CSS attribute. If your sprite size is for example 100px by 100px, by default background-size will take the value 100px 100px, but if you set it to 200px 200px it will double the image size that will be displayed.

    In your case it would look like this :

    var spriteSize = { height: 224, width : 224 * 20 };
    var imageSize = { height: 224, width : 224 };
    var backgroundWidth = Math.floor((moveTail.object.width()  / imageSize.width) * spriteSize.width);
    var backgroundHeight = moveTail.object.height();
    
    moveTail.object.css("background-size", backgroundWidth + "px " +  backgroundHeight + "px");
    moveTail.object.css('background-position', moveTail.counter * -moveTail.object.width() + "px 0px" );
    

    The second one is to use the CSS 3 attribute transform with scaleX and scaleY. If you want a div to double the size that is displayed you can do in CSS transform: scaleX(2) scaleY(2).

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

Sidebar

Related Questions

I am using the following script to animate a sprite for the background-image for
I am attempting to follow along to this tut: HERE but using a sprite
I have a line, which is a sprite made by using this code CGPoint
I have a CSS image sprite and this renderes perfect in FF, also IE.
I'm having an issue getting this CSS for a sprite sheet to work on
I have 3 different images and want to create a sprite using CSS. I
new to android dev and andengine in general. trying to animate a sprite using
I am using this sprite for some experiments. I cropped a section of the
I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
i added sprite to scene by this tutorials : http://www.raywenderlich.com/9743/how-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-1 but i have bad

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.