Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2012, 10:53 PM   PM User | #46
pdiddles03
New Coder

 
Join Date: Jun 2010
Posts: 76
Thanks: 0
Thanked 1 Time in 1 Post
pdiddles03 is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
You could use another, smaller canvas on top of the other, so you'd only have to manipulate that canvas (clear, redraw, move).
I could, but obviously you can't use <canvas><canvas></canvas></canvas>

So would you position the second with css?
pdiddles03 is offline   Reply With Quote
Old 12-05-2012, 11:06 PM   PM User | #47
donna1
New Coder

 
Join Date: Nov 2012
Location: london
Posts: 55
Thanks: 5
Thanked 1 Time in 1 Post
donna1 can only hope to improve
Quote:
Originally Posted by pdiddles03 View Post
So ok, let's say I have my map all written out and generated.

Next, i put my character on top, how would I go about clearing just the character when I move him, and not the map?
As Mr Old Pedant has been explaining it to me I will share - you can print things on top in a higher layer so when you move them away the map still shows. (It doesnt require two canvas's you just set the z layer higher to the objects you want in front)
My problem was drawing a character over a background. You have to use a GIF rather than a JPEG to set the unwanted pixels to transparent so the background shows through any white space around your graphic

Last edited by donna1; 12-06-2012 at 03:31 PM..
donna1 is offline   Reply With Quote
Old 12-05-2012, 11:12 PM   PM User | #48
pdiddles03
New Coder

 
Join Date: Jun 2010
Posts: 76
Thanks: 0
Thanked 1 Time in 1 Post
pdiddles03 is an unknown quantity at this point
Quote:
Originally Posted by donna1 View Post
As Mr Old Pendant has been explaining it to me I will share - you can print things on top in a higher layer so when you move them away the map still shows. (It doesnt require two canvas's you just set the z layer higher to the objects you want in front)
My problem was drawing a character over a background. You have to use a GIF rather than a JPEG to set the unwanted pixels to transparent so the background shows through any white space around your graphic
I figured it out, instead of usint canvas.width=canvas.width, let say my character is called "hero" I just used hero.width=hero.width and that worked perfect.
pdiddles03 is offline   Reply With Quote
Old 12-05-2012, 11:16 PM   PM User | #49
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by pdiddles03 View Post
So ok, let's say I have my map all written out and generated.

Next, i put my character on top, how would I go about clearing just the character when I move him, and not the map?
Well, the obvious answer is to *NOT* change the map, *AT ALL*.

Instead, just make your character *SEPARATE* from the map, with a z-index higher than the map, so he ends up appearing in front of the map.

But what is the big deal about swapping the character image for one of the map images and then, when he moves, swapping the map image back in???

That's trivial, though it won't look as good as having the character as a separate image (a ".png" or ".gif" image, with transparencey!) that moves smoothly from one square to the next instead of having the ugly double replacement.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-05-2012, 11:58 PM   PM User | #50
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
*** HERE ***

A live demo. I am using a single image as the background instead of an array of images, but that doesn't impact the overlay idea.

Movement here is random instead of directed by user, but it shows all the concepts.

http://www.mywhizbang.com/demoOverlay.html

VIEW-->>SOURCE there to see how it is working.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 01:55 AM   PM User | #51
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
And one more:
http://mywhizbang.com/demoMover2.html

To move the overlay image, you click on any "square" (50x50 pixel region) that is *adjacent* to the current position. The image then moves there. Smoothly.

The squares, per se, are invisible. With a grid of images, they wouldn't need to be. You could put a thin border on each image to delineate the cells.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 12-06-2012 at 01:57 AM..
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 03:43 PM   PM User | #52
donna1
New Coder

 
Join Date: Nov 2012
Location: london
Posts: 55
Thanks: 5
Thanked 1 Time in 1 Post
donna1 can only hope to improve
thats very clever, looks good.

btw What does old pedant mean? I mistakenly called you old pendant before sorry. now curious what pedant means - is it something to do with your railway avatar?
donna1 is offline   Reply With Quote
Old 12-06-2012, 04:09 PM   PM User | #53
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
afaik a "pedant" is someone who puts a lot of emphasis on details and who also expects that from others.
devnull69 is offline   Reply With Quote
Old 12-06-2012, 05:48 PM   PM User | #54
donna1
New Coder

 
Join Date: Nov 2012
Location: london
Posts: 55
Thanks: 5
Thanked 1 Time in 1 Post
donna1 can only hope to improve
ok, anyway clever Pedant, would you be able to post the code for your last example, where it moves to the next cell? I like how thats done.
Also which package did you use to make your GIF with transparent border?
I have downloaded GIMP Paint now but havent worked out how do make the white transparent
donna1 is offline   Reply With Quote
Old 12-06-2012, 06:07 PM   PM User | #55
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by donna1 View Post
ok, anyway clever Pedant, would you be able to post the code for your last example, where it moves to the next cell? I like how thats done.
Bring up the page and click on VIEW menu of your browser and then on SOURCE or PAGE SOURCE menu item. Or right click on the page and choose VIEW ==>> [PAGE] SOURCE from the context menu.

Are you telling me you never have done that with other pages???

Quote:
Also which package did you use to make your GIF with transparent border?
I have downloaded GIMP Paint now but havent worked out how do make the white transparent
I used a very old version of PhotoShop (version 6) which no longer runs on my current machine.

I haven't yet tried doing that with GIMP. It should be possible.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 08:08 PM   PM User | #56
pdiddles03
New Coder

 
Join Date: Jun 2010
Posts: 76
Thanks: 0
Thanked 1 Time in 1 Post
pdiddles03 is an unknown quantity at this point
I took a look at your code. What is the bare bones code to get a character to move 50px, but do it in a smooth animation. I tried to cheat at it with jquery but jquery doesn't seem easy to use in canvas.
pdiddles03 is offline   Reply With Quote
Old 12-06-2012, 08:29 PM   PM User | #57
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You can't DO smooth movement using a canvas (at least not easily).

If you want the smooth movement, you should do as I did and use an overlay image.

Trying to do it using ONLY a canvas would be a horrible waste of resources. Ugly ugly ugly code and very slow to boot.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 08:29 PM   PM User | #58
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
What is the bare bones code to get a character to move 50px, but do it in a smooth animation.
Ummm...the code I showed?

Or use jQuery, which I don't use.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 08:34 PM   PM User | #59
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by devnull69 View Post
afaik a "pedant" is someone who puts a lot of emphasis on details and who also expects that from others.
Heh! That's a *REALLY* kind definition.

Usually, "pedant" is used in a derogatory sense, meaning somebody is anal retentive about every little thing. That's probably closer to the truth for me. <grin/> (Or, as my wife would say, "yeah, about everything that doesn't matter.")
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 11:56 PM   PM User | #60
donna1
New Coder

 
Join Date: Nov 2012
Location: london
Posts: 55
Thanks: 5
Thanked 1 Time in 1 Post
donna1 can only hope to improve
Quote:
Originally Posted by Old Pedant View Post
Bring up the page and click on VIEW menu of your browser and then on SOURCE or PAGE SOURCE menu item. Or right click on the page and choose VIEW ==>> [PAGE] SOURCE from the context menu.

Are you telling me you never have done that with other pages???
I did know how to do that from a PC but I was playing with it on my iPad and theres no right click on that, so I dont know how to view source from iPad.

Theres been a few things Ive needed right click for on my iPad in the past, is there a workaround?
donna1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 AM.


Advertisement
Log in to turn off these ads.