Discuss Scratch

Iamthescratcher
Scratcher
8 posts

Handling layers

Hi there,

I'm helping a young friend who has been working on a map project… and I'm now out of my depth!

The first map, “PNINS Project”, works OK
The second map “PNINS with zoom” is the problem.

We are struggling with hiding and showing layers… particularly the names of the map icons which show text on mouse-over.

I have a feeling that a project called “Handling layers” (by mwiedmann) would help but I'm not sure how to integrate it into this project.

Can anyone talk me through the “handling layers” project?

Cheers,
Allie.

Last edited by Iamthescratcher (Aug. 2, 2013 02:37:46)

Iamthescratcher
Scratcher
8 posts

Handling layers

More information:

Zoom in using the “z” key… so far so good.

Zoom out using the “s” key… oops, the icons are slow to disappear…

Move your mouse around… and, whoa, the text on mouse-over still works when we don't want it to!

scubajerry
Scratcher
1000+ posts

Handling layers

I admit that I only glanced through the project, so I may have misdiagnosed.

Well as far as the mouse overs, As I read the code, once you ever go into ZOOM MODE, you enter a forever loop doing mouse over. You could make ZOOM MODE and replace the DO FOREVER with REPEAT UNTIL NOT ZOOM MODE.

The late removal of the icons is probably because the code you have to HIDE/SHOW the ICON when it goes on/off the screen is fighting with the zoom > 74 code once you have entered zoom mode.

Last edited by scubajerry (Aug. 2, 2013 03:46:03)

scubajerry
Scratcher
1000+ posts

Handling layers

OK - My last thought is that your maps appear to start about 20 layers back. I think things would run smoother if at the start of each map you at a GO TO FRONT outside of the FOREVER.

OBTW - This is a really cool project. Great job.
Iamthescratcher
Scratcher
8 posts

Handling layers

Thanks for your input, scubajerry. I think I see what you mean about the hide/show fighting with the zoom. I'll play around and see if implementing the “repeat until not zoom” helps.

Scratch is a pretty special program.

When a forty-something (with no coding experinece) can work with a 12 year old (with even less programming knowledge) and actually make something that works… well, full credit to the Scratch team.
drmcw
Scratcher
1000+ posts

Handling layers

Unsure its a layering problem as such. I'm struggling to see what's what in the project though I'm afraid. I'm guessing the text still appearing may be to do with the ghosting you use sometimes to hide things. If you set a sprites ghost to 100 then it isn't shown but it will still register if something touches it.

You do have a few puzzling bits of code. You do a hide then go back which is a bit odd as it seems unnecessary.. As has been mentioned you broadcast zoom but then do a forever loop. Can you not do away with the broadcast and just put the if touching code where the broadcast is? You do an abs check for x and y coordinates that are > 170 which is ok for y but shouldn't the x coord check be 230 or thereabouts as the screen width is bigger than the height? In the border sprite you have a hide followed by a forever and just go to a coordinate. Why? Seems incredibly wasteful.
Iamthescratcher
Scratcher
8 posts

Handling layers

Hi drmcw,

I'm sure that there are more than a few puzzling bits of code hanging around… probably quite a collection of random bits and pieces hiding in this project!

I'm a complete novice trying to gather enough information to help a keen young kid with his project. Together, we have have had an “add blocks till it works” sort of approach; I know it is clumsy but we have both learnt a lot in the process.

I've started checking each sprite and removing extraneous material. There is definitely an element of “can't see the wood for the trees”!

Thanks for your comments,
Allie.
Iamthescratcher
Scratcher
8 posts

Handling layers

Scubajerry, you're a darling!

Thanks for taking the time to remix the project and correct the toilets sprite. Brilliant.

What's more, I understand so I can talk to my young buddy about it.

Much appreciated,
Allie

scubajerry
Scratcher
1000+ posts

Handling layers

Good luck!
drmcw
Scratcher
1000+ posts

Handling layers

I now know who to call when my toilets need fixing!
scubajerry
Scratcher
1000+ posts

Handling layers

drmcw wrote:

I now know who to call when my toilets need fixing!
http://scratch.mit.edu/projects/11673241
mwiedmann
Scratcher
100+ posts

Handling layers

I'm a little late to the party of this one. For the icons, it think it may just be easier to hide them all when someone clicks on one rather than trying to deal with layers. Just do a “broadcast ‘icons hide’” and have the icons listen for that message and hide. When the user has clicked through all the screens on the info for that room, do a “broadcast ‘icons show’” and have the icons listen for that message and show.

Avoid dealing with layers when you can because Scratch has limited blocks for dealing with them. As you are moving layers, it can be confusing to track what the “z-order” is, so you end up using a bunch of “go to front” and “go back # layers” commands.
DadOfMrLog
Scratcher
1000+ posts

Handling layers

Indeed, tracking the layering of sprites, if you're moving them up and down regularly, isn't so straightforward even if you just had to consider the sprites that you have visible on the screen.

But I can also tell you that it's complicated even (much much) further by the fact that all *hidden* sprites also have a layer, and, worse still, all reporters that you've ever shown (but may now be hidden) also play a part in that layering.

For example, every variable that you create (and then hide) has a layer, because its reporter appeared at some point. If you show something like “x-position” of a sprite, or the timer, etc., and then hide it, that also then becomes another layer to account for (and your scripts may have been all set up & accounting the layers perfectly before you showed that sprite's x-position and so added a new layer… ouch!)

It gets pretty messy

That's why the most robust solution is usually of the form “go to front”; “go back # layers” - because that way anything that's not visible/used gets pushed right to the back.
Iamthescratcher
Scratcher
8 posts

Handling layers

Thanks to everybody who has taken the time to comment and make suggestions.

We now have a working map, a very happy young man, and a very relieved older adult!

Cheers,
Allie.


Powered by DjangoBB