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

  • Home
  • SEARCH
  • 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 8761977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:24:54+00:00 2026-06-13T15:24:54+00:00

I am having trouble drawing a tile-based map :( the map however is only

  • 0

I am having trouble drawing a tile-based map 🙁
the map however is only going to show what is VISIBLE to the player
I have a canvas element on which i draw one layer.
On the canvas, i use javascript to attach an image 32x32px.
The image’s position is based on: $tr $tc

as shown below:

for($tr = 0; $tr < count($mapArray)-1; $tr++) {
for($tc = 0; $tc < count($mapArray[$tr])-1; $tc++) {
    if($mapArray[$tr][$tc]!== null){
        echo "attachImage(" . $mapArray[$tr][$tc]. "," . $tc . "," . $tr . ",context);";
    }
}
}

I don’t know how I would go about making the it draw tiles from 0,0. it always starts drawing tiles from the same location on the array (ex 3,2). Maybe i’m over thinking this or im too tired… i can’t find out any way 🙁

here’s the javascript part

function attachImage(tile, x, y, canvasContext)
{
  var base_image = new Image();
  base_image.onload = function(){
    canvasContext.drawImage(base_image, 32*(x-0),32*(y-0));
  }
  base_image.src = 'Images/tiles/'+(tile-1)+'.png';
}

to reiterate, i want it to start drawing from 0px,0px because i want to only display the tiles around the player.

  • 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-13T15:24:56+00:00Added an answer on June 13, 2026 at 3:24 pm

    i dont know how to delete this question, but i found out the answer

    $c = 0;
    for($tr = $drawy; $tr < $drawy2; $tr++) {
        $r = 0;
        for($tc = $drawx; $tc < $drawx2; $tc++) {
            if($mapArray[$tr][$tc] !== null)
            {
                $tile = $mapArray[$tr][$tc];
                echo "attachImage(" . $tile . "," . $r . "," . $c . ",context);";
            }
            $r++;
        }
        $c++;
    }
    
    for($tr = 0; $tr < count($mapArrayy)-1; $tr++) {
        for($tc = 0; $tc < count($mapArrayy[$tr])-1; $tc++) {
            if($mapArrayy[$tr][$tc]!== null){
                echo "attachImage(" . $mapArrayy[$tr][$tc]. "," . $tc . "," . $tr . ",context2);";
            }
        }
    }
    

    i added $c and $r in the first loop. that’s all. now it draws from 0px,0px.

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

Sidebar

Related Questions

I'm having trouble with a gradient drawing call. I have a Form that looks
I'm having trouble in mouse coordinates when drawing at canvas of HTML5. I'm using
I am trying to create a drawing area with canvas. I am having trouble
I'm having trouble drawing a UIImage in front of a CAShapeLayer . I have
I'm having some trouble with drawing polygons on a Google Map through the JavaScript
I'm making a small platform game with the canvas element and I'm having trouble
I am having trouble drawing an animation on a HTML 5 canvas inside a
I am having trouble drawing a line within a group box in a simple
I'm trying to make a simple drawing app in c++, but i'm having trouble
Iam beginner in android game development and i'm currently having some trouble on drawing

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.