Vanilla JS Tutorials

JsIso Tutorials

RSS feed

01 - Creating a simple Tile Engine

These tutorials will guide you through the basics of interacting with a Canvas element in reference to tile engines as well as slowly diving deeper into JavaScript techniques.
Some basic programming understanding is expected however there is nothing that can't be Googled.

The aim is to give an overview understanding of how tile engines are acheieved, leading into the use of JsIso and the simplicty of avaialble methods.

Using the HTML5 Canvas element to display some simple flat tiles is fairly straight forward.

In this sample we make use of a two dimensional array for our map representation and fillRect to draw our tiles rather than using graphics.
We don't care about scope or other cool things just now, let's just have the simple map displayed.

// Our init function contains all our code and will be called via the onLoad attribute in the <body> tag of our HTML page.
function init() {
    
    // The two dimensional map array as it sounds is basically your world and what will be drawn.
    // Each number can represet a different graphic or possible enviroment interaction.
    // In this tutorial case we only have two possible tiles, zero which is blank and one which is filled.
    var map = [
      [1,0,1,0,1],
      [1,1,1,0,1],
      [1,0,1,0,1]
    ];
    
    // The next part grabs the canvas element id of 'main' within our page <body>.
    var ctx = document.getElementById('main').getContext('2d');
    
    // Using two for loops we run through each of the array rows stored and their element values.
    for (var i = 0; i < map.length; i++) {
        for (var j = 0; j < map[i].length; j++) {
    
            // Check if the value is a 1, represeting a graphic should be drawn.
            if (map[i][j] === 1) {
                // Draw a rectangle at i & j position * 20 pixels so that
                // our 20x20 pixel squares are correctly positioned.
                ctx.fillStyle = '#FF0000';
                ctx.fillRect(j * 20, i * 20, 20, 20);
            }
    
        }
    }

}

Tutorial Outcome (View & Run Source)

25 comments

  1. First comment test!

    Iain Hamilton Sun, 26 Oct 2014

  2. found a lot of useful information, glad to join your community!

    10.0.0.1 Thu, 4 Apr 2019

  3. Witamy wszystkich miЕ‚oЕ›nikГіw cyfrowej rozrywki na portalu tworzonym przez graczy dla graczy. Nasza porГіwnywarka cen kluczy do gier i programГіw jest
    unidad de negocio
    Reinicio de los controles de clima - pГЎgina 4 - jeep renegade forum mejor plataforma de minerГ­a litecoin

    BTCben Sat, 6 Apr 2019

  4. ВїAlguna vez has despertado con dolor en la espalda? ВїAlguna vez se inclinГі sГіlo para encontrar que ya no puede levantarse? El dolor de espalda ocurre en
    food shelter
    Editorial the relationship between obesity and urinary incontinence and its causes insight medical publishing escoliosis lumbar izquierda tratamiento

    TomDer Mon, 15 Apr 2019

  5. 2017 foi um grande ano de transição para o MIRI, à medida que assumimos novos projetos de pesquisa que dependem muito do trabalho prático de programação
    facet arthropathy definition

    Udofef Thu, 18 Apr 2019

  6. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. zombs royale

    — samuelddarden Wed, 29 May 2019

  7. This release is really informative and shows a good example of a nature-friendly project we can all spend our time on.
    Thatcher's Tree Service Gainesville FL

    — Ronald M. Lynch Thu, 30 May 2019

  8. Great article, I unfortunately had some problems printing this article out, The print formatting looks a little screwed over, something you might want to look into.
    click here

    — Joshua A. Price Mon, 10 Jun 2019

  9. Great to see this beautiful article i will look forward to your next page. carpet cleaner

    — fred luis Wed, 12 Jun 2019

  10. This is explained very simple. Thanks for the resource.

    Check Mon, 15 Jul 2019

  11. Thanks for the article post.Thanks Again. Really Great. mike mood

    — Patricia J. Clark Thu, 25 Jul 2019

  12. I’d been just browsing every now and then and also got to learn to read this post.... tree service

    — Cassandra Everhart Thu, 8 Aug 2019

  13. I have read lots of information before and I find this the most informative of them. Thank you for this one!
    tree service oak harbor wa

    Trisha Mon, 12 Aug 2019

  14. Nice read! Roofer 

    Paul Bennett Tue, 13 Aug 2019

  15. Wow! So many words and codes for this very simple design. That's awesome and interesting!
    professional beard trimmer

    — Brielle Luna Wed, 14 Aug 2019

  16. Thank you so much for this tutorial. Now Im really learning something.

    best b350 motherboard Mon, 19 Aug 2019

  17. I was totally mind-blown! I never thought making that very simple text and design is that complicated!
    Medical Converting Company

    — Horea Kaii Mon, 19 Aug 2019

  18. Tuitjenhorn is een dorp in de gemeente Schagen, in de provincie Noord-Holland. Het grenst aan Warmenhuizen en is een agrarisch dorp. In het dorp stond het gemeentehuis van de op 1 januari 2013 opgeheven gemeente Harenkarspel. Kattenpension Tuitjenhorn is gevestigd in Waarland ligt slechts op enkele km afstand van Tuitjenhorn. Ook kattenbezitters uit Tuitjenhorn zijn welkom bij kattentrimsalon Catchy. Kattenpension Tuitjenhorn

    — muneer ahmed Tue, 20 Aug 2019

  19. Thanks for creating this simple methods! tik tok followers 2019

    — James Holden Thu, 22 Aug 2019

  20. "Een tandarts is iemand die in alles is gespecialiseerd, dat met de
    gezondheid van tanden en kiezen, van het gebit te maken heeft. Daar
    valt ook de gezondheid van het tandvlees onder. Tandartsen hebben
    om hun beroep te mogen uitoefenen een academische achtergrond op het
    gebied van de tandheelkunde. Tandheelkunde (Odontologie) is het
    vakgebied dat zich bezighoudt met het herkennen, voorkomen en behandelen
    van ziekten van de tanden en de omringende structuren. Soms stuurt
    een tandarts een patiënt door naar het ziekenhuis kaakchirurg omdat
    een behandeling te complex is dan wel onder narcose moet worden
    uitgevoerd. Primaire begrippen in dit vakgebied zijn: Plaaten beugel,
    plaatsen brug, Kaakchirug, plaatsen van een kroon of protese.
    Stifttand ter vervanging van tanden of een wortelkanaal behandeling
    ter voorkoming van botontstekingen in het kaak gewricht." Tandartsenpraktijk

    — muneer ahmed Sat, 24 Aug 2019

  21. Thank you for sharing this! This is really helpful and you made it very easy to comprehend!
    spray foam oklahoma city

    — Mary Kay Mon, 2 Sep 2019

  22. This seems easy. I hope you can share a video creating this as well!
    Dan |LLC operating agreement

    — Daniel Mon, 2 Sep 2019

  23. Very useful tutorial in making tile engine and it also hones your javascript. American Electric

    — Edward Lewis Mon, 2 Sep 2019

  24. Great tutorial so far! This is greatly amazing. Thanks for sharing. | villa rentals in cabo san lucas

    — George Tue, 3 Sep 2019

  25. Thanks for this useful information. Do you have a book for this? Like any other programming.

    explore Thu, 12 Sep 2019

Please insert the result of the arithmetical operation from the following image:

Please insert the result of the arithmetical operation from this image. =