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

#1 2012-09-18 15:41:16

VALVelover6421
New Scratcher
Registered: 2012-01-22
Posts: 5

Background Change

I'd like to make a 2D platform game, in which when the character's x-position > 230, the background automatically changes to the next background, and the character 'teleports' to the left side of the screen. However, if I put in the "go to x:..." command, the character freezes and is unable to move, jump or anything. If I don't, all the stage backgrounds rapidly flash by until the character moves away from the x-point.

What do I do to ensure that the scenes can progress correctly, without harming the mobility of the character?

Offline

 

#2 2012-09-18 15:54:02

GilledGiraffe
New Scratcher
Registered: 2012-09-18
Posts: 1

Re: Background Change

Post scripts?

Offline

 

#3 2012-09-18 16:53:30

gfchll
Scratcher
Registered: 2012-04-21
Posts: 100+

Re: Background Change

hmmm.

if <(x position) > [230]>
go to [left side of screen so the whole character is on the screen]// use x and y
next background

Last edited by gfchll (2012-09-18 16:53:48)


HELLO EVERYBODY!

Offline

 

#4 2012-09-18 21:21:23

VALVelover6421
New Scratcher
Registered: 2012-01-22
Posts: 5

Re: Background Change

gfchll, does that actually work? You can just type in instructions without coding them?

Offline

 

#5 2012-09-18 21:38:50

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Background Change

In the main character's sprite:

when gf clicked
forever if<(x position) > (230)>
go to x:(-230) y:(100)
broadcast [switch background to next costume v]
In the background:
when I receive [switch background to next costume v]
next costume


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-09-18 21:42:06

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Background Change

VALVelover6421 wrote:

gfchll, does that actually work? You can just type in instructions without coding them?

No, it does not (computer's aren't that good yet  tongue ).

When people insert things like that in their blocks (including non-existent blocks, unless it is just a mistake), they're just a place-holder for code that you presumably know (and/or code they do not).

Since VALVelover421 didn't know exactly what x and y position you wanted the main sprite moved to, he just placed the "go to (code placeholder)" block, leaving it up to you to fill in the x and y position.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-09-19 22:35:37

Averydan
New Scratcher
Registered: 2012-09-03
Posts: 8

Re: Background Change

Does this help?
http://scratch.mit.edu/projects/Averydan/2789809

Offline

 

#8 2012-09-19 23:16:27

VALVelover6421
New Scratcher
Registered: 2012-01-22
Posts: 5

Re: Background Change

@MoreGamesNow Thank you, it worked!

Offline

 

#9 2012-09-19 23:52:15

VALVelover6421
New Scratcher
Registered: 2012-01-22
Posts: 5

Re: Background Change

How do I get this to go the other way?
So far, my script looks like this:
[scratchblocks]
when i receive [prevscene]
forever
    if <([x-position] of [Sprite1]) <-230>
        change [background] by [-1]
end

And then this little floating thing:

[scratchblocks]
<(background) = (background #)>
end

(As you can see, my scratchblock format likely doesn't work.)
So, how do I connect these two together to make the script go to the *previous* background whenever the character is at -230 x-position?

Offline

 

#10 2012-09-20 07:31:46

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Background Change

VALVelover6421 wrote:

How do I get this to go the other way?
So far, my script looks like this:

when i receive [prevscene]
forever
    if <([x-position v] of [Sprite1 v]) < (-230)>
        change [background v] by [-1]
end
And then this little floating thing:

<(background) = (background #)>
end
(As you can see, my scratchblock format likely doesn't work.)
So, how do I connect these two together to make the script go to the *previous* background whenever the character is at -230 x-position?

I fixed your blocks  smile

Here is what I would do:

when gf clicked
forever if<([x position v] of [sprite1 v]) < (-230)>
switch to costume ((costume #)-(1))
Since this doesn't guarentee that the sprite location will change before the reiteration of the script (so you might go back two costumes by the time sprite 1 teleports, or you might not go back at all, and the sprite will teleport before the script checks if it is left of -230, this is what I would do:

Main sprite:
when gf clicked
forever
if<(x position) > (230)>
broadcast [next background v]
go to x:(-220) y:(100)
else
if<(x position) < (-230)>
broadcast [previous background v]
go to x:(220) y:(100)
end
end
For the background:

when I receive [next background v]
next costume

when I receive [previous background v]
switch to costume ((costume #) - (1))
Out of curiosity, have you had experience with another programming language (since it seems you tried to assign a value with the equal operator, which is the way many programming languages work; Scratch uses the equal sign solely as a boolean that returns equality, not to assign values).


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#11 2012-09-22 22:37:15

VALVelover6421
New Scratcher
Registered: 2012-01-22
Posts: 5

Re: Background Change

It worked! Again! Thanks so much.

Offline

 

Board footer