Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » 'Instantiate' random pickup items as 'prefabs'
- BeerHuntor
- Scratcher
5 posts
'Instantiate' random pickup items as 'prefabs'
Im trying to create a game that starts spawning random items after x number of seconds.. however whenever I create a clone it doesn't actually work unless the original sprite is already visible on screen. I would like to create a clone of an invisible sprite.. how would I go about this. Current code is as folllows..
Stage:
Sprite
But only works if I put this in the sprite
Ok, not sure if this is the correct way, but I have it set to hide when green flagged and show when cloned.. i dont understand why it wouldnt just show when cloned anyway but oh well.
Stage:
define Spawn
create clone of [apple v]
Sprite
when I start as a clone
forever
next costume
wait (SecondsBetweenAnimation) secs
if <touching Head v ?> then
delete this clone
end
end
But only works if I put this in the sprite
when green flag clicked
show
Ok, not sure if this is the correct way, but I have it set to hide when green flagged and show when cloned.. i dont understand why it wouldnt just show when cloned anyway but oh well.
Last edited by BeerHuntor (Sept. 22, 2021 01:17:11)
- BeerHuntor
- Scratcher
5 posts
'Instantiate' random pickup items as 'prefabs'
did you read what I wrote? It only works when I show in the sprite.. ive already tried this, as this was the first logical thing to do… Make the clone itself show. Then it doesn't rely on the original sprite being hidden or not.when I start as a clone
show
EDIT: Never mind..somehow now that works.. I am certain thats what i was doing before hand, and it never showed.. unless something else in the code was causing issues and ive managed to unknowingly fix it.. which could be also true…
Last edited by BeerHuntor (Sept. 22, 2021 10:53:12)
- deck26
- Scratcher
1000+ posts
'Instantiate' random pickup items as 'prefabs'
What you wrote didn't include anything to show the clone so if the sprite was hidden the clone would also be hidden. Showing the sprite and creating clones meant the clones also showed.did you read what I wrote? It only works when I show in the sprite.. ive already tried this, as this was the first logical thing to do… Make the clone itself show. Then it doesn't rely on the original sprite being hidden or not.when I start as a clone
show
EDIT: Never mind..somehow now that works.. I am certain thats what i was doing before hand, and it never showed.. unless something else in the code was causing issues and ive managed to unknowingly fix it.. which could be also true…
Basically when a clone is created it inherits the properties of the parent including graphic effects at the time of creation. If the parent is hidden the clone will be hidden but can then be told to show independently of the sprite.
That seems to cover your situation since you said showing the sprite fixed it.
- Discussion Forums
- » Help with Scripts
- » 'Instantiate' random pickup items as 'prefabs'