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

#1 2010-04-03 17:18:07

Kingdaro
Scratcher
Registered: 2008-06-08
Posts: 100+

Create Instance of Sprite

I know, this has been suggested countless times, but I just wanted to give my view on the subject. This is how I think it would work.
[blocks]
Create instance( # )of[ Sprite ]at x: (0)y: (0)
[/blocks]
"#" Meaning the instance would be labeled with a number. The original sprite would be Instance 0. If you were to create an instance with a number label that already exists, then the one that exists would move to the provided position. "Sprite" is the sprite you want to make an instance out of. X and Y is the position you want it to go to.
[blocks]
Delete Instance( # )of[ Sprite ]
[/blocks]
The instances are labeled with numbers, so you could delete a specific instance of the sprite.
[blocks]
Delete Self
[/blocks]
This would delete only the instance it's put in, so you can't put it in the background.

If you put a script in a sprite, then it would apply in all instances. Say you were making a shooting game, then this would be the script to fire:
[blocks]
<when green flag clicked>
<set{ v  }to( 1

<when[ space ]key pressed>
<create instance( <{ v  }> )of[ bullet ]at x sad  x of gun )y sad  y of gun )
[/blocks]
And the script in the bullet:
[blocks]
<when green flag clicked>
<forever>
<change y by( 10
<if> <( <y position> <>> 180 )>
<delete self>
<end>
<end>
[/blocks]

Last edited by Kingdaro (2010-04-04 18:42:54)

Offline

 

#2 2010-04-04 17:06:19

Jakey22
Scratcher
Registered: 2008-12-28
Posts: 72

Re: Create Instance of Sprite

That is an Idea that has greatly been needed.

It would be useful for 2d shooters (The bullets).


http://www.imagebookers.com/gallery/d/2561-1/ubuntu-wallpaper.png http://bullylug.org/linux-penguin.jpg
My website       PENGUINS!!!!!!!!!!!!!!!!!!!!! randomness.

Offline

 

#3 2010-04-05 05:22:13

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Create Instance of Sprite

Well explained...
We are touching object oriented programming here... :-)
What about variables? This might need to create a distinction between global variables (seen by all sprites) and local variables (distinct, owned by each instance)...


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#4 2010-04-05 15:03:29

Kingdaro
Scratcher
Registered: 2008-06-08
Posts: 100+

Re: Create Instance of Sprite

Phi_Lho wrote:

Well explained...
We are touching object oriented programming here... :-)
What about variables? This might need to create a distinction between global variables (seen by all sprites) and local variables (distinct, owned by each instance)...

Good point. I say that the local variables would indeed be owned by each instance. And the instances would be treated as multiple sprites, just copies of the same object, and you being able to have any amount of instances you want.

Offline

 

#5 2010-04-05 15:27:50

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Create Instance of Sprite

Maybe also have a variable called instance number, so you could check something like

When green flag clicked
[forever]
move (instance number) steps


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#6 2010-04-08 16:02:14

Kingdaro
Scratcher
Registered: 2008-06-08
Posts: 100+

Re: Create Instance of Sprite

juststickman wrote:

Maybe also have a variable called instance number, so you could check something like

When green flag clicked
[forever]
move (instance number) steps

Good idea also  big_smile

Offline

 

Board footer