1

I am trying to make a simple game, so far i can capture user input, but i cannot get the view to work properly to print the images. If i have a resource named image, how do i assign individual sprites to display this image on displayOn? I have tried many approaches, for example in the initialize method i tried:

self image := Classname image

but that caused an overflow, and i was forced to closed visual without saving work. What is the good way to do this?

Bartlomiej Lewandowski
  • 10,771
  • 14
  • 44
  • 75

1 Answers1

4

you usually access to class side methods directly, without needing to store there into instance variables. For example:

myMethodsWhoNeedsAnImage
    | image |
    image := self class imageStoredInClassSide.
    "now do something with image"

If you need to store it, certainly you cannot do what you tried in your example, but you can do:

initialize
    super initialize.
    image := ClassWithImage image.

or

initialize
    super initialize.
    self image: ClassWithImage image. "This is a setter method"

Any of these approaches should work. If it doesn't, most probably you have a problem somewhere else, not in the accessing to class side.

EstebanLM
  • 4,252
  • 14
  • 17
  • one more question: what does the asRetainedMedium message do? I get an error that this is not understood. I have the picture in my class variable resources, when asked for image i return CashedImage on:(#picture) – Bartlomiej Lewandowski Nov 13 '12 at 17:51
  • I never seen that message in my life :). Perhaps you can clarify which Smalltalk are you using? – EstebanLM Nov 16 '12 at 10:14
  • 1
    That's a VisualWorks message. In VW, there are two ways to store bitmaps. Images store the pixel colors and palettes with Smalltalk objects. Pixmaps use handles to the native operating system's image objects. Pixmaps normally display much faster than Images. The message asRetainedMedium is a message for Images to convert themselves into Pixmaps. A CachedImage is an object that can contain both an Image and a corresponding Pixmap. If you try to draw it and the pixmap is nil, it will run asRetainedMedium on the image to create a Pixmap and cache it in the cached image. – David Buck Nov 16 '12 at 10:29