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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:53:40+00:00 2026-06-04T04:53:40+00:00

I’ve drawn a tile map: http://www.exeneva.com/html5/movingTankExample/ Here’s my startup code: function startUp() { drawScreen();

  • 0

I’ve drawn a tile map:

http://www.exeneva.com/html5/movingTankExample/

Here’s my startup code:

function startUp() {
  drawScreen();   
  // Draw the tank
  context.drawImage(tileSheet, tankSourceX, tankSourceY, tileWidth, tileHeight, tankX, tankY, tileWidth, tileHeight);
}

drawScreen() draws the tile map. I want to draw the tank after the tile map, but without putting it in drawScreen() because I want to animate and move the tank later on (without having to call drawScreen() again.

Why doesn’t my tank show up?

  • 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-04T04:53:41+00:00Added an answer on June 4, 2026 at 4:53 am

    I’m gessing you don’t read the link I’ve passed you on your last answer and took the aprouch of the other guy with seemed easiest. tisk, tisk…

    Anyway, to solve this, you will have to draw your tank inside the drawScreen() method as before, but you will have to call the animation function of the tank from inside the key moviment events. This way, the tank will draw stopped when not moving and draw animated when moving as your original question.

    Edit:

    I’ve got your entire code now on my machine and here are the steps to solve your problem, since I’ve gave you many hints, now I’ll give you the code as you want:

    1- The code responsible for the initialization of the animation and select the frame of the animation to be shown is inverted. The counter frameIndex need to be initialized before the tankSourceX and tankSourceY:

    // Counter to keep track of the current index of animationFrames
    var frameIndex = 0;
    // Tank tiles
    var tankSourceX = Math.floor(animationFrames[frameIndex] % tilesPerRow) * tileWidth;
    var tankSourceY = Math.floor(animationFrames[frameIndex] / tilesPerRow) * tileHeight; 
    

    2- Place theses variables that define the frame inside the animation function, whre you change the animation frame, so the frameIndex changes the tankSourceX and tankSourceY values:

    function animateMovement() { 
        // Animation frames
        frameIndex += 1;
        if (frameIndex == animationFrames.length) {
            frameIndex = 0;
        }
    tankSourceX = Math.floor(animationFrames[frameIndex] % tilesPerRow) * tileWidth;
    tankSourceY = Math.floor(animationFrames[frameIndex] / tilesPerRow) * tileHeight; 
    }
    

    3- Your drawing and animation function can be called by your event handlers or by a interval like on the begining:

    var animateInterval = setInterval(animateMoviment, 200);
    var drawingInterval = setInterval(drawScreen, 200);
    

    4- Initialize a variable as the tank state:

    var tankState = "stopped";
    

    5- On the animation function, put a check for this variable to change the frames:

    function animateMovement() { 
        if (tankState == "moving") {
            // Animation frames
            frameIndex += 1;
            if (frameIndex == animationFrames.length) {
                frameIndex = 0;
            }
            tankSourceX = Math.floor(animationFrames[frameIndex] % tilesPerRow) * tileWidth;
            tankSourceY = Math.floor(animationFrames[frameIndex] / tilesPerRow) * tileHeight; 
        }
    }
    

    6- Change your event handlers to set the tankState as moving:

    e = e?e:window.event;
    tankState = "moving";
    ...
    

    7- Reset the tankState on the keyup event:

    document.onkeyup = function(e) {
        tankMoveX = 0;
        tankMoveY = 0;
        tankState = "stopped";
    }
    

    Off course you can call the animate and draw functions on the key event handlers and eliminate the intervals, but this way you can add more animations to be runned on the same function that do not wait for the players input, like NPC’s (non plaing characters).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.