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
Post scripts?
Offline
gfchll, does that actually work? You can just type in instructions without coding them?
Offline
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
Offline
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 ).
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.
Offline
@MoreGamesNow Thank you, it worked!
Offline
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
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] endAnd 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
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:
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 endFor 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).
Offline
It worked! Again! Thanks so much.
Offline