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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:44:00+00:00 2026-06-05T07:44:00+00:00

I’ve tried to create a ’tile stamper’ application that allows you to select a

  • 0

I’ve tried to create a ’tile stamper’ application that allows you to select a tile from the top and then ‘stamp’ that tile onto the canvas area below. You can basically think of this as a map editor for an HTML5 game.

Everything is working except for the selecting and stamping: http://www.exeneva.com/html5/tileStamper

The JS error console says my event listeners aren’t correct, but I am 100% sure they are valid:

// Event listeners
theCanvas.addEventListener("mousemove", onMouseMove, false);   
theCanvas.addEventListener("click", onMouseClick, false);

Here is my mouse movement and mouse click handling code:

function onMouseMove(e) {
  // Accounts for the canvas not being at the top left of screen
  mouseX = e.clientX - theCanvas.offsetLeft;
  mouseY = e.clientY - theCanvas.offsetTop;
}

function onMouseClick(e) {
  console.log("click: " + mouseX + "," + mouseY);
  if (mouseY < 128) {
    // Find tile to highlight
    var totalRows = 7; // 8 total rows, but relative zero means we use 7
    var col = Math.floor(mouseX / tileLength);
    var row = Math.floor(mouseY / tileLength);
    var tileId = (row * totalRows) + (col + row);
    highlightTile(tileId, col * tileLength, row * tileLength);
  } else {
    // stamp the selected tile
    var col = Math.floor(mouseX / tileLength);
    var row = Math.floor(mouseY / tileLength);
    context.putImageData(imageData, col * tileLength, row * tileLength);
  }
}

Here is the tile highlighting code:

function highlightTile(tileId, x, y) {
  // redraw tilesheet and highlight selected tile
  context.fillStyle = "#aaaaaa";
  context.fillRect(0, 0, 256, 128);
  drawTileSheet();

  imageData = context.getImageData(x, y, 32, 32);
  // set alpha to 128
  for (j = 3; j < imageData.data.length; j += 4) {
    imageData.data[j] = 128;
  }

  // draw red line around selected tile
  var startX = Math.floor(tileId % 8) * 32;
  var startY = Math.floor(tileId / 8) * 32;
  context.strokeStyle = "red";
  context.strokeRect(startX, startY, 32, 32);
}

Can someone help me figure out why this isn’t working?

  • 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-05T07:44:02+00:00Added an answer on June 5, 2026 at 7:44 am

    According to this line:

    var theCanvas = $("#canvasOne");
    

    theCanvas is jquery wrapper, not a pure DOM Element.So it does not have addEventListener method.
    You could try like this:

    theCanvas[0].addEventListener("mousemove", onMouseMove, false);   
    theCanvas[0].addEventListener("click", onMouseClick, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a

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.