ImageMap returning Float values
Monkey Forums/Monkey Programming/ImageMap returning Float values
| ||
Am I doing this right? I was to use Image as a key for a map. ..or not possible? Class ImageObject Field value:Image Method New( value:Image ) Self.value=value End End Class ImageMap<V> Extends Map<ImageObject, V> Method Compare( lhs:Object,rhs:Object ) Local l:=ImageObject( lhs ).value Local r:=ImageObject( rhs ).value If l<>r Return 0 Return 1 End End Class Tween Global mapAlpha:ImageMap<Float> = New ImageMap<Float> End |
| ||
Cannot be done, duh! Reason: You can't compare Images. And no pointers or handles associated with Images. I thought of trying to use width and height in an extended Map with a custom Get,Set, but it would take too long to iterate through repeats to find the correct Image. Could use a StringMap, but again the lookup would take too long using Strings. Not worth it. (Easier to create your own ImageEx class or ultimately a Sprite class) |
| ||
On second thought, it can be done, thanks to NoOdle: http://www.monkeycoder.co.nz/Community/posts.php?topic=1980 Import mojo Class FloatObj Field f:Float Method New(in:Float) f=in End End Class CustomMap<V> Extends Map< Image, V> Method Compare : Int( a : Object, b : Object ) If a < b Then Return 1 If a > b Then Return -1 If a = b Then Return 0 Return -1 End Method End Class MyApp Extends App Field myMap : CustomMap< FloatObj> Field img1:Image Field img2:Image Method OnCreate() SetUpdateRate 30 myMap = New CustomMap< FloatObj > img1 = New Image img2 = New Image myMap.Set( img1, New FloatObj(4.0) ) myMap.Set( img2, New FloatObj(6.0) ) End Method Method OnUpdate() End Method Method OnRender() Cls Local test : FloatObj = myMap.Get( img2 ) DrawText test.f, 10, 0 test = myMap.Get( img1 ) DrawText test.f, 10, 10 End Method End Class Function Main() New MyApp() End Function |