Why won't AutoMidHandle work?
BlitzMax Forums/BlitzMax Beginners Area/Why won't AutoMidHandle work?
| ||
I'm still in the process of learning BlitzMax (and programming in general) and sometimes I get stuck. This time it's AutoMidHandle who is giving me a headache. Why doesn't AutoMidHandle set the handle of my image to the centre?Strict '** Constants ** Const WIDTH:Int = 800 Const HEIGHT:Int = 600 Const DEPTH:Int = 0 Const TESTIMAGEWIDTH:Int = 200 Const TESTIMAGEHEIGHT:Int = 200 '** End Constants ** Graphics WIDTH, HEIGHT, DEPTH AutoMidHandle True Local counterOne:Int Local counterTwo:Int Local alpha:Int = 255 Local red:Int = 255 Local green:Int = 255 Local blue:Int = 255 Local testImage:TImage = CreateImage(TESTIMAGEWIDTH, TESTIMAGEHEIGHT) Local pixmapTestImage:TPixmap = LockImage(testImage) For counterOne = 0 To TESTIMAGEWIDTH -1 For counterTwo = 0 To TESTIMAGEHEIGHT - 1 WritePixel pixmapTestImage, counterOne, counterTwo, alpha Shl 24 + red Shl 16 + green Shl 8 + blue Next Next UnlockImage testImage DrawImage testImage, WIDTH / 2, HEIGHT / 2 FlushMem Flip WaitKey End Thanks, Nicolas. |
| ||
I think you need one of these:AutoMidHandle True SetHandle 0.5, 0.5 |
| ||
The whole point of automidhandle is that it automatically sets the handle to the middle of any objects that are drawn from then on. You shouldn't need to explicity use SetHandle to make it work. Also I'm not sure if automidhandle is to do with handle's given to newly loaded objects or ones you create yourself. |
| ||
I think it would be kind of stupid if autoMidHandle only applied to objects you load. Is there any reason why you should want that the handle of your loaded objects is centred en the handle of your created objects not? Anyway, thanks for the quick replays, Nicolas. |
| ||
Well ... I think AutoMidHandle ... just sets the point of rotation and position for all your images ... then you can define exactly how far into these images it is. In this case 50% of the way ... but maybe you'd want it somewhere else for a bunch of other objects ... not sure really, but that is in Rockout. |
| ||
MidHandleImage sets an images handle to it's centre. AutoMidHandle True means all images will have a MidHandleImage automatically applied to them when then are loaded. The documentation says that AutoMidHandle is applied to all images created but it seems to only work with images that are loaded. It's either a bug in BlitzMax or bad documentation. SetHandle x, y positions the image's handle manually. In your example, the AutoMidHandle won't apply to your created image. Instead, use 'MidHandleImage testImage' between creating and drawing your image. |
| ||
Setting Automidhandle will cause auto_midhandle to be enabled which is checked for all loadimage commands. If set midhandleimage is specified. The createimage function doesn't seem to check the same flag. |
| ||
Ah .. |
| ||
Ok... But I'm planning to create a bunch of images, does this mean I that for ever image that I create I have to type MidHandleImage someImage :-| ? Thanks, Nicolas. |
| ||
I think it's a bug and can't see any way around it other than use midhandle image OR create a function to do your image creations. Once in a function or a loop adding the midhandleimage won't be such a problem.... I don't think?? (I'm assuming it is possible to create an incremental image name). Obviously, having non-specific names is probably even worse than having to use midhandleimage. |
| ||
Creating a function is good solution but I still thing I'm missing something about AutoMidHandle. It just seams strange AutoMidHandle whit a loaded image, ok, AutoMidHandle whit a created image, not ok. It could be a bug, but I want to be sure before I go and post that in the bug forum. Thanks, Nicolas. |
| ||
You could try adding this to the max2d.mod createimage command... <<<edit>>> Ignore this change. It doesn't work here... If auto_midhandle MidHandleImage image It just seams strange AutoMidHandle whit a loaded image, ok, AutoMidHandle whit a created image, not ok. That's why I believe it's a bug. It's better to report it than not. The worse that can happen is somebody tells you it's Working As Designed. |