[Newbies] Drag and dropped jpg (playing cards) - how to put in
the "new morph" menu and create a PlayingCard class?
herbertkoenig at gmx.net
Sun Oct 25 11:00:59 UTC 2009
never done something like that but let me drop some thoughts you might
MS> If I drag and drop a jpg onto Squeak, it creates a SketchMorph.
SketchMorph has a fromFile: method on the class side.
For versioning graphics some people put images into methods, so the
method returns the image (which is stored in an Array literal).
PlayingCard class side imageData returns a String literal with all the
parts of card images and class side's initialize assembles these into
MS> Specficially, I'm adding a playing card image, well 52 of them, and
MS> I'd like to be able to add a card from the world menu / new morph
I assume you don't mean new morph / from file but new morph / from
alphabetical list. This is done for you by magic. Each Morph subclass
(all down the hierarchy from there) is added to that menu. Don't know
how it's done.
World Menu, "Objects" "Games" has a FreeCell card game (as of Squeak
3.8.2 which I use) there you might get some ideas from.
MS> I'd also like to create a PlayingCard class, that uses the dropped jpg.
In a 3.8 (and older) image this class already exists. But as it is an
Object subclass it's not in the menu. But it's been dropped in 3.10.
Sorry I can't access squeak.org right now but
http://www.squeak.org/Download/ should have it.
This brings me to the thought, that you might want to have a class
which collects the the playing behaviour and has an ivar "display"
which points to a Morph subclassed object which collects the visual
Thanks to Smalltalk you can always do that later.
MS> At the moment I'm doing it the "hard way", after dropping the jpg, I'm
MS> digging through system dictionary, digging out the world objects, and
MS> "drilling down" to the dropped object.
"drilling down" sounds complicated, so:
World submorphs select: [:each | each class == SketchMorph]
More information about the Beginners