Discuss Scratch

Belmontprep
Teacher
2 posts

resetting the position of the sprites

New user so probably very basic question

when you add some code and run it and sprite moves or turns, how do you reset its position to its original location before the code was run?
deck26
Scratcher
1000+ posts

resetting the position of the sprites

Good practice is as follows

whenclicked only need one per projectbroadcastinitialiseandwait sprites respond by setting starting position, variables, costumes etcbroadcastready now ready to run code in the project
So you'd want a
gotox:y:
in the sprite's initialise receiver.

You say you're new. If you start coding as above you'll save yourself a lot of problems!

Last edited by deck26 (Jan. 16, 2020 12:04:07)

Belmontprep
Teacher
2 posts

resetting the position of the sprites

thank you so much deck 26

can you share with me a simple program with the above included so i can see how it fits into a project, that would be really appreciated. a little of what you are saying above is a little confusing to me at the moment

thank you
deck26
Scratcher
1000+ posts

resetting the position of the sprites

Most of my simple projects are so minimal that this isn't an issue and the more complex ones may just confuse you. I don't necessarily follow this method myself but that's because I know how to ensure everything is properly initialised by other means. Despite all that, I still think it's a good approach.

So let's just describe a simple example like a pong game. We will often see scripts like

whenclickedforeverifscore1=5orscore2=5thenbroadcastgameoverstopthis script
which may seem fine but if the game has been run and one player won then the game perhaps stopped with score1 = 5. Another green flag may reset it to 0 but you don't know what order the green flag scripts are going to run in. So you rerun the game and are surprised that it immediately broadcasts gameover. The green flag script to reset the variable will still do so and rerunning again will be fine but this is a common cause of needing to click the green flag twice.

So in the initialisation stage I referred to the variable would have been reset to 0 before any game scripts ran. The script to check for a winner should only run once all initialisations have taken place and by using broadcast and wait we ensure all receivers of the ‘initialise’ broadcast have completed before moving on.

This covers all sorts of things like that. Another example is the player touching something that stops the game or changes a score when really the player should have been placed in their starting position before any game code ran.

So think about how things should be before any game code runs
- variables that should have initial values
- selecting the right costumes for sprites and making sure they're shown or hidden
- positioning the sprites
- setting the correct backdrop
and set all those things in receivers of the ‘initialise’ broadcast.

Last edited by deck26 (Jan. 16, 2020 18:27:15)

TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

So I cant figure out how to make this happen with multiple sprites as it just sends all sprites to that other position, regardless if it has the same code or not. I tried changing it a little bit but it did not work. Can you help me out? @deck26

Last edited by TheGamer7115 (June 17, 2024 21:36:19)

deck26
Scratcher
1000+ posts

resetting the position of the sprites

TheGamer7115 wrote:

So I cant figure out how to make this happen with multiple sprites as it just sends all sprites to that other position, regardless if it has the same code or not. I tried changing it a little bit but it did not work. Can you help me out? @deck26
Share what you have please. You should be running separate scritps for each sprite that needs positioning so I don't see why they'd all be going to one position.
TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

Okay. Here is the most recent version. https://scratch.mit.edu/projects/1038670478/ I just put this.
whenclickedbroadcastinitialise[scratchblocksv]andwait/scratchblocksbroadcast ready[scratchblocksv]gotox:106y:-33/scratchblocks

Last edited by TheGamer7115 (June 19, 2024 13:30:03)

TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

I'm just starting out.
deck26
Scratcher
1000+ posts

resetting the position of the sprites

You only have 2 sprites! The first is only moved if you press space and otherwise has one of two positions depending on whether the project has already been run and space pressed or not. The second sprite tries to glide to a position off the left edge of the screen and will do so unless it hits the first sprite in which case the whole project stops.

There is no point broadcasting initialise and wait and not having any receivers for that broadcast. That's where, for example, the first sprite should be positioned where you want it.

So what do you want to happen because it's not clear from your posts so far?
TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

So I'm trying to make geometry dash but it is not working for me so far. I'm just new and barely know anything about scratch.
TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

I am trying to make it so in my game it resets the level
TheNoisyNoisy
Scratcher
100+ posts

resetting the position of the sprites

TheGamer7115 wrote:

So I'm trying to make geometry dash but it is not working for me so far. I'm just new and barely know anything about scratch.
Ok well gd is very hard for a beginner to make, even if they're talented
TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

@TheNoisyNoisy Thank you I have a lot of experience in geometry dash. And I hope people will enjoy my likeness for geometry dash. Geometry Dash Username: LeoTheGamer1
TheGamer7115
Scratcher
40 posts

resetting the position of the sprites

I have come really far as I am uploading a project for the Treasure Trove. https://scratch.mit.edu/projects/1077542798/

Powered by DjangoBB