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)

64 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

  26. Incredible site. Is this kind of design custom?
    apexaimbot
    battlecatsxp
    archerycoins
    lordscoins/
    imvucreditsgrabber

    — jake Wed, 18 Sep 2019

  27. Perhaps you have ever before assumed writing an e book?
    fevercoins
    battlecatsxp
    kimstarscash
    cmasterspins
    farmvilletropicgems

    — jake Wed, 18 Sep 2019

  28. I look onward to fresh new posts so i can promote it along with my contacts.
    nbamobilecoins
    hphmysterygems
    hempirediamonds
    pokecoinsblaster
    marvelfuturecrystals

    — jake Wed, 18 Sep 2019

  29. this is very great and brilliant information

    it works number Sun, 22 Sep 2019

  30. www.raybansunglasses.biz ray ban sunglasses www.ray-banoutlets.us.org ray-ban outlet lunettes de soleil ray ban pas cher www.ray-banoutlet.co ray-ban outlet oakley outlet www.oakleysunglasses.biz oakley sunglasses www.oakleyoutlets.com oakley outlet
    I hope you have a sweet dream. I mean dream of me.

    louis vuitton Mon, 23 Sep 2019

  31. I was having trouble with this until I seen this. Thank you for sharing. Zuraida owner of Duct Cleaners Cincinnati Ohio

    — Zuraida Oen Mon, 23 Sep 2019

  32. Thank you for these tutorials. It is very useful. Beaumont Septic

    Beaumont Septic Wed, 25 Sep 2019

  33. Very informative details. Beaumont Remodeling

    Beaumont Remodeling Wed, 25 Sep 2019

  34. Found a helpful tutorial. Thank you so much. Kingwood Sprinkler

    Kingwood Sprinkler Wed, 25 Sep 2019

  35. Thanks for the heads up!
    tow truck youngstown towing Richmond
    mobile mechanic Victoria
    moving company

    Michael Coleman Mon, 30 Sep 2019

  36. Wow, this is cool! I really love how it's broken down to be understood clearly and easily. Very nice.

    Karon with http://hattiesburg-contractor.com/

    Karon O'Connor Mon, 30 Sep 2019

  37. Very nice, easy, informative read!

    Contractor

    All in One Mon, 30 Sep 2019

  38. Thank you for this cool tutorial.

    rent a photo booth lancaster Tue, 8 Oct 2019

  39. wow I need this like you need your pool cleaned.

    Harold Mooner Sat, 12 Oct 2019

  40. Whew this is hot!

    Fire and Safety Sat, 12 Oct 2019

  41. check out our blog

    Related Blogs Sat, 12 Oct 2019

  42. stay cold with http://www.lafayetteac.com

    Lafayette AC Sat, 12 Oct 2019

  43. Great article! Very clear!

    Handyman home repair Mon, 14 Oct 2019

  44. Great forum and format. Towing Peoria,IL appreciates the opportunity to post.

    Towing Peoria, IL Mon, 28 Oct 2019

  45. Very user-friendly format. Nice!!

    Towing Columbia, SC Mon, 28 Oct 2019

  46. Quality Logo Products enjoys this site. Very easy to use and communicate.

    Quality Logo Products Mon, 28 Oct 2019

  47. Quality Logo Products enjoys this site. Very easy to use and communicate.

    Quality Logo Products Mon, 28 Oct 2019

  48. Wilmington Towing will continue to visit and share this site. Excellent format!

    Wilmington Towing Mon, 28 Oct 2019

  49. Great forum and format. Towing Peoria,IL appreciates the opportunity to post.

    Towing Peoria, IL Tue, 29 Oct 2019

  50. Simple to understand and an excellent resource.Everett Towing looks forward to using your site often.

    Everett Towing Wed, 30 Oct 2019

  51. Towing West Palm Beach found this to be an interesting and informative site. Thanks for this post!

    Towing West Palm Beach Thu, 31 Oct 2019

  52. Very good, useful information. Here at Towing Company North Charleston, SC we are always looking for innovative tools that help us do our work better.

    Towing Company North Charleston, SC Thu, 31 Oct 2019

  53. Very useful update and app. Kent Towing can certainly put to use the information on this site.

    Kent Towing Sat, 2 Nov 2019

  54. Very nice, insightful post. Towing Charleston, SC will make good use of this info.

    Towing Charleston, SC Sat, 2 Nov 2019

  55. Auto Electrical Gold Coast found this to be an excellent resource. We are looking forward to making good use of this site!

    Auto Electrical Gold Coast Wed, 6 Nov 2019

  56. Good info with excellent tutorials. Heating and Air Spartanburg, SC really appreciates this post!

    Heating and Air Spartanburg, SC Wed, 6 Nov 2019

  57. Congratulations from a href="https://goo.gl/maps/FG2NHA52uuk">Carpet Cleaning Spartanburg,SC. We look froward to additional posts.

    Carpet Cleaning Spartanburg, SC Wed, 6 Nov 2019

  58. Tree Service Spartanburg,SC likes the format and ease of use of this site. Thanks for the post!

    Tree Service Spartanburg, SC Wed, 6 Nov 2019

  59. Towing Cary enjoyed learning about this process. Very useful application.

    Towing Cary Wed, 6 Nov 2019

  60. Towing Charleston, SC loves this site. The tutorials are especially helpful.

    Towing Charleston, SC Fri, 8 Nov 2019

  61. This is really interesting post you shared

    geileweiber Sat, 9 Nov 2019

  62. this helps me a lot . hope to read more from this site
    Tires fredericton

    — Edward Tue, 19 Nov 2019

  63. Interesting info with great training associated with this site.
    Lawn Care Newark, DE looks forward to making good use of this resource.

    Lawn Care Newark, DE Thu, 21 Nov 2019

  64. Interesting info with great training associated with this site.
    Lawn Care Newark, DE looks forward to making good use of this resource.

    Lawn Care Newark, DE Thu, 21 Nov 2019

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

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