Discuss Scratch

elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Hi everyone,
I'm having trouble making my HeroSprite collect an Apple (on the GameScreen) and then visibly ‘carrying it’. I'd like the apple to disappear when the Hero collects it but also for the apple to reappear in a smaller size and somehow show the Hero carrying the Apple to the Princess and making the apple disappear when the Princess receives it (all whilst not affecting my current variables e.g object count, score, hat collect etc.). I hope that makes sense. I've tried for days to try and get this working but no luck so far, so any advice would be greatly appreciated! It would make my to fix this

https://scratch.mit.edu/projects/312198843/

Last edited by elewis222 (May 23, 2019 17:29:48)

deck26
Scratcher
1000+ posts

Sprites 'carrying' other sprites?

Use a variable recording the current state for the apple (none, hero, princess or just 0/1/2)

Start with apple full size.

When the hero is carrying the apple broadcast after each hero move to get the apple to go to the hero - either switch costume to small apple when hero first picks up apple or change size at that point. Or use a separate costume for the hero when they're carrying the apple.

When apple is given to princess hide it and change the variable so the hero doesn't broadcast after moving.
wayyyy
Scratcher
500+ posts

Sprites 'carrying' other sprites?

Here is an easy way to do this. Chance your code here:



to this:


Delete your Scratch Account

elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Hi, thanks so much for the advice!

@deck26, I'm very new to Scratch so don't quite understand a lot of those terms, sorry. Would you mind possibly ‘dumbing’ that explanation down' for me?

@wayyyy thank you for your idea, it worked! However when I do this I'm not sure how to make the apple disappear when given to Princess.

Does anyone know how to do this if the apple is in a forever loop?

I do really appreciate the ideas, I'll keep trying in the meantime but any additional input would be amazing

Last edited by elewis222 (May 24, 2019 01:32:33)

wayyyy
Scratcher
500+ posts

Sprites 'carrying' other sprites?

I just relieted realised you wanted the Friend sprite to carry to apple, not the HeroSprite.

Here's an updated version of the code.



try it and tell me if this is what you expected to happen.

Last edited by wayyyy (May 24, 2019 01:33:52)


Delete your Scratch Account

elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Hi wayyyy, sorry my explanation was a bit all over the place. So I need the HeroSprite to collect the Apple (having the Apple disappear first when HeroSprite touches it and then reappear and visibly ‘stick’ to HeroSprite so it looks like HeroSprite is carrying Apple to the Princess (FriendSprite).

Your first code did this perfectly, thank you! My only problem now is getting the Apple to disappear once given to the Princess. I hope that made sense.

Thanks for your help!
ResExsention
New to Scratch
1000+ posts

Sprites 'carrying' other sprites?

elewis222 wrote:

Hi wayyyy, sorry my explanation was a bit all over the place. So I need the HeroSprite to collect the Apple (having the Apple disappear first when HeroSprite touches it and then reappear and visibly ‘stick’ to HeroSprite so it looks like HeroSprite is carrying Apple to the Princess (FriendSprite).

Your first code did this perfectly, thank you! My only problem now is getting the Apple to disappear once given to the Princess. I hope that made sense.

Thanks for your help!

Oh.

Use this for the giving away the apple:

if <touching princess or whatever :: grey> then
change [Object_count v] by [-1]
change size by (whatever :: grey)
...
forever
go to [princess v] // if you don't want to hide it
end
end

However though, if you don't want to work with complicated code, what you can always do is create separate costumes for the hero sprite. Like, there will be the normal costume, then you could change it up into the carrying_apple costume.

Hopefully the script is accurate. I didn't review the context fully and was just taking my best guess. You may have to adapt the code.

Ask us if you have any other problems.

Last edited by ResExsention (May 24, 2019 03:07:27)


Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!
elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Thanks for that!

So this is the code I currently have (as per wayyyy's suggestion) and it does 90% of what I want it to do. I just need it to disappear once given to the FriendSprite (Princess).

when [ any] key pressed
if <touching [ HeroSprite] ?> then
change [ Apple Collect] by (1)
change [ Score] by (1)
change [ Object Count] by (1)
hide
wait (0.5) secs
show
forever
go to [ HeroSprite]
end
end
elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Oh and obviously the event block is attached in the actual project, sorry about that ^
deck26
Scratcher
1000+ posts

Sprites 'carrying' other sprites?

Your forever loop will need modifying. You want the apple to hide when given to the princess so it might be better doing repeat until so the apple doesn't keep going to the HeroSprite - even if hidden it would still do that.

So how do we know when the apple has been given to the princess? It looks like the variable apple-eaten tells you that. So insteasd of your forver loop

repeat until <(apple-eaten) = [1]>
go to (HeroSprite)
end
hide
But what you may find is that the apple seems to lag a bit when moving with the HeroSprite. That's because Scratch is showing you one frame at a time and it runs all the code to decide what the new frame should show. Now if the apple moves to the HeroSprite before the HeroSprite is moved by another script that will make it seem that the apple is always a move behind. That's why I was suggesting the HeroSprite broadcasts to the apple to move only once the HeroSprite has moved. This may not be an issue to lets not worry about it for now.
elewis222
New to Scratch
6 posts

Sprites 'carrying' other sprites?

Thanks for the idea! I've tried that formula and it unfortunately impacts all of my variables (object count, score, etc. and makes the game run in a way that it's not supposed to). I'm grateful for the advice though and I'm going to keep trying.
deck26
Scratcher
1000+ posts

Sprites 'carrying' other sprites?

elewis222 wrote:

Thanks for the idea! I've tried that formula and it unfortunately impacts all of my variables (object count, score, etc. and makes the game run in a way that it's not supposed to). I'm grateful for the advice though and I'm going to keep trying.
What idea are you referring to. I think the key here is you understanding the advice and working out how to apply it - blindly copying scripts isn't usually a good idea.
ResExsention
New to Scratch
1000+ posts

Sprites 'carrying' other sprites?

deck26 wrote:

elewis222 wrote:

Thanks for the idea! I've tried that formula and it unfortunately impacts all of my variables (object count, score, etc. and makes the game run in a way that it's not supposed to). I'm grateful for the advice though and I'm going to keep trying.
What idea are you referring to. I think the key here is you understanding the advice and working out how to apply it - blindly copying scripts isn't usually a good idea.

Yeah. I tried to just copy scripts but then I didn't know how to use it effectively. Once, I saw this awesome script in C++. I copied it, and worked fine. When I tried to reuse the script in another trivial project, I wasn't able to do it. You should learn how to translate code, so that you can use it effectively, not just copy them and hope for the best.

Good luck

Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!

Powered by DjangoBB