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

#1 2012-09-22 18:31:13

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Can a sprite detect the edges of a background?

I'm pretty new to Scratch programming, and I'm trying to reproduce a game I was working on in Excel VBA (a remake of the old Atari 2600 Adventure game).

I want to have a small rectangular sprite that can be moved around within a background, but I'd like the walls of the background (anything that isn't gray) to be impenetrable.  However, there doesn't seem to be an elegant way to do this, since the collision detection only allows you to check for contact with other sprites, certain colors, etc.

Any suggestions on this?

Thanks!

Offline

 

#2 2012-09-22 18:34:58

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Can a sprite detect the edges of a background?

<touching [edge v] ?>

Last edited by Molybdenum (2012-09-22 18:35:13)


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#3 2012-09-22 18:46:35

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Re: Can a sprite detect the edges of a background?

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

Offline

 

#4 2012-09-22 19:02:53

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Can a sprite detect the edges of a background?

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

touching sprite [wall v]?

Last edited by Firedrake969 (2012-09-22 19:03:22)


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#5 2012-09-22 19:15:44

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Can a sprite detect the edges of a background?

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

If you want to, you could just use:

<touching color [yellow]?>


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2012-09-22 19:59:23

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Re: Can a sprite detect the edges of a background?

Firedrake969 wrote:

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

touching sprite [wall v]?

Except that "wall" in your example refers to a sprite, correct?  I will go that route (making sprites for the background) if I have to, but I'd prefer not to, if at all possible.

Offline

 

#7 2012-09-22 20:01:32

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Can a sprite detect the edges of a background?

jdb-44 wrote:

Firedrake969 wrote:

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

touching sprite [wall v]?

Except that "wall" in your example refers to a sprite, correct?  I will go that route (making sprites for the background) if I have to, but I'd prefer not to, if at all possible.

You don't have to if your walls are all the same color, but if they aren't then you will have to do what Firedrake969 suggested.


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-09-22 20:47:07

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Re: Can a sprite detect the edges of a background?

ErnieParke wrote:

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

If you want to, you could just use:

<touching color [yellow]?>

Hmmm...is there a way to refer to a color by number, perhaps, with a variable?  So I could say have an expression like: "touching NOT the color [hallway color]".

Offline

 

#9 2012-09-22 21:03:58

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Can a sprite detect the edges of a background?

jdb-44 wrote:

ErnieParke wrote:

jdb-44 wrote:

I thought about using that; the problem is, unfortunately, that the background has some scattered walls and borders that I would like the sprite to treat as solid.

It looks like this: http://i.imgur.com/flX2o.png

If you want to, you could just use:

<touching color [yellow]?>

Hmmm...is there a way to refer to a color by number, perhaps, with a variable?  So I could say have an expression like: "touching NOT the color [hallway color]".

As far as I know, no, you can't, but you can use this:

if <<<<(hallway) = [yellow]> and (touching color [#fcff00]?)> or <<(hallway) = [orange]> and (touching color [#ffa800]?)>> or <more...>>
 do something
end

Last edited by ErnieParke (2012-09-22 21:05:22)


http://i46.tinypic.com/35ismmc.png

Offline

 

#10 2012-09-22 23:57:11

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Re: Can a sprite detect the edges of a background?

I have a solution.  It's not pretty, but it'll do.  Back to work!

Thanks for everyone's help so far!  I'll put something out there soon for demo.

Offline

 

#11 2012-09-23 03:01:29

soniku3
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: Can a sprite detect the edges of a background?

Doesn't this better fit in ''Help With Scripts''?


internet's all about cats today.

Offline

 

#12 2012-09-23 14:19:13

jdb-44
New Scratcher
Registered: 2012-09-22
Posts: 6

Re: Can a sprite detect the edges of a background?

I think I have it!

I've made a background (gray) that will always be visible.

The rooms will all be represented in a single sprite that has multiple costumes.

The rectangle "character" will check for contact with the sprite (that is, the current costume of the sprite, representing Room # X.

Now...to enable picking up and carrying objects!

Thanks again for everyone's input!

Offline

 

Board footer