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

#1 2011-07-01 09:42:58

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Blockmaking Question...

(I'm going on vacation soon.  I may not see your answer until July 19th.)

Is there anyway to set a variable to the height or width of a sprite's current costume?  For example, the scratch cat is 95x111.  In any sprite or background, is there a way to get a block's variable (say, t2) to return these values?  Also, is there a way to reference to size % of a sprite?

Offline

 

#2 2011-07-01 09:58:28

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

In Looks category, you have 3 blocks related to the size of the sprite:
- change size by %n
- set size to %n%
- size (reporter)

They are defined in ScratchSpriteMorph's blockSpecs class method. You may want to take a look at the methods associated with those blocks:
- ScratchSpriteMorph>>changeSizeBy:
- ScratchSpriteMorph>>setSizeTo:
- ScratchSpriteMorph>>scale

They all use ScratchSpriteMorph's instance variable "scalePoint". Maybe you can get something out of it.

Offline

 

#3 2011-07-01 10:14:25

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

The "super initialize" send in ScratchSpriteMorph>>initialize assigns the result of ScratchSpriteMorph>>defaultImageMedia to its costume. This method returns an ImageMedia:
"I am a Scratch image media object. I hold a still image that can be used as the costume for a Scratch object."

Maybe you'll want to check that out too.

Offline

 

#4 2011-07-01 10:45:46

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Okay, I've figured this out:

ChangeSizeBy: calls SetSizeTo:, which in turn calls ScalePoint:.  ScalePoint: sets ScalePoint (no colon) to t1, its argument.  Scale then returns (100 * scalePoint x) rounded.

So that's how size works.  The question is:  how can I reference Sprite1's Scalepoint variable in all sprites, and the background?  And what about the size of the costume?

Offline

 

#5 2011-07-01 11:39:02

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

The default costume is loaded into the form of an ImageMedia in ScratchFrameMorph's defaultSprite class method. The form is initialized in ImageMedia>>initalize with an instance of Form class. The form class has instance variables such as width and height which you should be able to use somehow.

Offline

 

#6 2011-07-01 11:52:45

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Baderous wrote:

The default costume is loaded into the form of an ImageMedia in ScratchFrameMorph's defaultSprite class method. The form is initialized in ImageMedia>>initalize with an instance of Form class. The form class has instance variables such as width and height which you should be able to use somehow.

So let me get this straight:  Now I'm at Graphics-Display Objects > Form > accessing.  The variables 'height' and 'width' seem to be located there.  You think they refer to the height/width of the current costume?

Offline

 

#7 2011-07-01 12:00:20

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

Yes.

Offline

 

#8 2011-07-01 12:06:10

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Baderous wrote:

Yes.

It works!   big_smile   big_smile   big_smile   big_smile   big_smile

<when green flag clicked>
<forever>
<say[ THANK YOU!!!!
<end>

Offline

 

#9 2011-07-01 12:06:44

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

Nice.

Offline

 

#10 2011-07-01 12:10:04

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

I think we should put these in the library.  Should we say it's your block?  It kinda is...   wink

Offline

 

#11 2011-07-01 12:13:00

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

That's ok for me.  smile

Offline

 

#12 2011-07-01 12:15:11

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Baderous wrote:

That's ok for me.  smile

But I made the blockspec...  *starts whining* 

...Just kidding.  I'll say you did most of it.  wink

Offline

 

#13 2011-07-01 12:19:01

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

Just say it's our block (I read "our" instead of "your", only noticed after posting).

Offline

 

#14 2011-07-01 12:21:41

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Baderous wrote:

Just say it's our block (I read "our" instead of "your", only noticed after posting).

Nah, I barely did anything.  See my post:

http://scratch.mit.edu/forums/viewtopic … 81#p819081

Offline

 

#15 2011-07-01 12:25:13

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

Ok then, as you wish. See if you can help me here: http://scratch.mit.edu/forums/viewtopic.php?id=67422

Offline

 

#16 2011-07-01 12:46:14

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Blockmaking Question...

Just to let you know that the blocks you/we created were more simpler than I thought, and as I think you haven't realized what you've done, I feel like I should explain you. The selector you defined for the reporter block "width" has the name "width" and, as you said, there's no new code. That's because the method that you're calling is not the width selector from the Form class, but Morph>>width. This method is inherited by ScratchSpriteMorph because this class is subclass of Morph and, as such, you needn't write new code. What this method does is call "bounds width", which returns the width of the bounds instance variable of the class Morph. This "bounds" is nothing more than a rectangle that encloses the morph (in this case, the sprite).

So, after all, it was simpler than we thought.  wink

Offline

 

#17 2011-07-01 14:34:19

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Blockmaking Question...

Baderous wrote:

Just to let you know that the blocks you/we created were more simpler than I thought, and as I think you haven't realized what you've done, I feel like I should explain you. The selector you defined for the reporter block "width" has the name "width" and, as you said, there's no new code. That's because the method that you're calling is not the width selector from the Form class, but Morph>>width. This method is inherited by ScratchSpriteMorph because this class is subclass of Morph and, as such, you needn't write new code. What this method does is call "bounds width", which returns the width of the bounds instance variable of the class Morph. This "bounds" is nothing more than a rectangle that encloses the morph (in this case, the sprite).

So, after all, it was simpler than we thought.  wink

Hey, it works.  The more simple it is, the better.  Besides, we were the first to do it (or at least officially make the block).   smile

Offline

 

Board footer