Html5/JS rotating image and place it on a canvas.

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Darius
Posts: 19
Joined: Fri May 10, 2013 10:26 am

Html5/JS rotating image and place it on a canvas.

Post by Darius »

As a little side project, I'm remaking Ceasar III in Html5/JS. I have >600 tile images like this:
Image

But I can't manage to draw them onto the canvas without having white space.
The images themselves are 58x30 pixels.
So the tile itself is a cube sized 32.6pixels.

How could I draw it onto a canvas (rotated)?
I've tried it with rotating the canvas itself ... but the white space between the tiles always is drawn.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by Jackolantern »

Are you wanting an isometric view? If so, perhaps you could look at a_bertrand's game here. :)
The indelible lord of tl;dr
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by a_bertrand »

Can you show us the white spaces you say? If you do it well, isometric tiles works perfectly with JS. I would say it's purely an issue on your side, but as you don't give any example, or sources to check I can't help more.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by Jackolantern »

Very true. If you could post the code and pictures, we could help further.
The indelible lord of tl;dr
Darius
Posts: 19
Joined: Fri May 10, 2013 10:26 am

Re: Html5/JS rotating image and place it on a canvas.

Post by Darius »

there is a tile in the OP. (the black image)
http://i.imgur.com/Jh5KwDa.png
Image

As for code, pretty straight forward:

Code: Select all

        //this.engine.getContext().rotate(45*Math.PI/180);
        for(var i = 0; i < this.engine.mapData.length; i++){
            for(var y = 0; y < this.engine.mapData[i].length; y++){
                var img = this.engine.loadImage("images/" + this.engine.mapData[i][y].sprite);
                this.engine.getContext().drawImage(img, i*32.6, y*32.6);
            }
        }

        //this.engine.getContext().rotate(-45*Math.PI/180);
the load image:

Code: Select all

    this.loadImage = function (name)    {
        var image = new Image();
        image.src = name;
        return image;
    }
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by a_bertrand »

Your code would draw in a grid like while for ISO maps you need to have odd and even lines on different X positions. Therefore each 2 rows add an offset which should be 16 pixels for you.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by Jackolantern »

Have you checked out Bertrand's excellent JS isometric tutorial? You could look on the 2nd page and he has the current progress uploaded, so you can see if it would help you.
The indelible lord of tl;dr
Darius
Posts: 19
Joined: Fri May 10, 2013 10:26 am

Re: Html5/JS rotating image and place it on a canvas.

Post by Darius »

Oh great thanks.
To bad there is no reputation or "thanks"/"like" button, else I'd give you both some rep++ :(.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Html5/JS rotating image and place it on a canvas.

Post by Jackolantern »

Thanks hehe :) I have always liked not having any kind of reputation, though, since it becomes a popularity contest, and can also be used to shame people. :P
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”