This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-20 23:58:44

bullelk12
Scratcher
Registered: 2012-05-26
Posts: 100+

Making a torch illuminate an area.

I'm making a game that needs a torch to light up parts of the black background. It also needs be see through (using the ghost effect).


http://mag.racked.eu/cimage/i6000/Achievement++get%21/Scratcher+love+minecraft%21/mca.png

Offline

 

#2 2012-08-21 09:57:17

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Making a torch illuminate an area.

First, you make 5 sprites, 4 are just black boxes that fill the screen and the remaining one is a black box with a hole in the size of your torch.
second, add this script to the boxes

when gf clicked //black box 1
forever
go to x:(([x position v] of [player v]) + (50)) y:([y position v] of [player v])
end 
when gf clicked //black box 2
forever
go to x:(([x position v] of [player v]) - (50)) y:([y position v] of [player v])
end
when gf clicked //black box 3
forever
go to x:([x position v] of [player v]) y:(([y position v] of [player v]) + (50))
end
when gf clicked //black box 4
forever
go to x:([x position v] of [player v]) y:(([y position v] of [player v]) - (50))
end
//the numbers will need changing
For the last one, the one with the hole, make it always go to the player
Then make a sprite with the same diameter as the hole in your sprite, use any effects you want like the circular shading one, then make the sprite always go to front and go to player
Note this only makes a circle of visible background/sprites around you not directionally, it also messes up colour sensors if you use complex light graphics


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-08-21 10:10:41

plemon11
New Scratcher
Registered: 2012-07-16
Posts: 9

Re: Making a torch illuminate an area.

Interesting problem..  I have one (currently untested) solution.

Create yourself a LARGE 100% black rectangle, that matches the dimension of the scratch canvas.  This allows it to scroll significantly off-screen.   Cut (with your favourite image editor; I recommend GIMP or Paint.Net) a round hole and set it's fill to 100% transparent.  Possibly add a little blur to the edges, save this as a PNG.

On the canvas, add your regular background, and then overlay the sprite you created above.  Add some mouse controls and you should be in business!

I've (quickly) hacked together an example of the concept..  it 'mostly' works.  You'll need to add some logic to cover exposed borders with black too.

Added bonus, setting the ghost effect makes the darkness.. not quite darkness. It's an interesting effect.. anyway,  example here :

http://scratch.mit.edu/projects/plemon11/2739578

Kind Regards,

PL

Offline

 

#4 2012-08-21 10:13:07

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Making a torch illuminate an area.

plemon11 wrote:

Interesting problem..  I have one (currently untested) solution.

Create yourself a LARGE 100% black rectangle, that matches the dimension of the scratch canvas.  This allows it to scroll significantly off-screen.   Cut (with your favourite image editor; I recommend GIMP or Paint.Net) a round hole and set it's fill to 100% transparent.  Possibly add a little blur to the edges, save this as a PNG.

On the canvas, add your regular background, and then overlay the sprite you created above.  Add some mouse controls and you should be in business!

I've (quickly) hacked together an example of the concept..  it 'mostly' works.  You'll need to add some logic to cover exposed borders with black too.

Added bonus, setting the ghost effect makes the darkness.. not quite darkness. It's an interesting effect.. anyway,  example here :

http://scratch.mit.edu/projects/plemon11/2739578

Kind Regards,

PL

You cannot blur because Scratch doesn't support semi-transparency.


http://i50.tinypic.com/312u714.jpg

Offline

 

#5 2012-08-21 10:22:18

plemon11
New Scratcher
Registered: 2012-07-16
Posts: 9

Re: Making a torch illuminate an area.

You cannot blur because Scratch doesn't support semi-transparency.

Many thanks! This is indeed correct.  In which case, you can make this sprite with the built in sprite editor, just select transparent and draw yourself something mostly torch shaped!

The example now uses exactly this technique (because it looks better!)

PL

Offline

 

#6 2012-08-22 03:20:36

bullelk12
Scratcher
Registered: 2012-05-26
Posts: 100+

Re: Making a torch illuminate an area.

I'll try these thanks.


http://mag.racked.eu/cimage/i6000/Achievement++get%21/Scratcher+love+minecraft%21/mca.png

Offline

 

Board footer