Help! Shapes, drawtext(), drawimageex(), createimage() etc.
-
I’m trying to make a pause menu for my game. I thought it would be fairly straightforward but nothing’s turning out the way I expected. Seems like almost everything needs a bodge of some kind to get things to line up. I’m trying to do it by creating a screen-sized image and rendering everything to that, before having a small ‘cursor box’ that goes on top of it.
There are so many variables, I don’t know what to ask. I’ll start with this:
It seems that in the arguments for createimage(), there’s a number of different types I can use - image_rgb, image_rgba, image_rgb_hdr, and image_rgba_hdr.
What are they for and why does it seem to affect the final image size?
Also, with drawimageex(), the positioning seems way off, as if the origin point is at the bottom right corner of my image, instead of the top left. With just drawimage() things go where I expect. Does anyone else have experience of this?
Any sorts of hints or tips or ‘oh, I remember that...’ types of comments welcome. I am scratching my head trying to figure this out...
-
@toxibunny said in Help! Shapes, drawtext(), drawimageex(), createimage() etc.:
drawimageex has an origin parameter, which can affect where an image will be drawn.
When you mention size, do you mean dimensions or data size? If you mean data size, yeah it makes sense, rgb only uses three channels: red, green and blue, whereas rgba would use four: red, green, blue and alpha for example.
-
I’ve figured out one part of my mystery. Createbox() has position and size parameters. The position refers to the centre of the box it creates.
Actually, I think that’s done it. It seemed before that when I changed image_rgba to image_rgb, that the position of my box changed, but maybe I was wrong.
It seems that drawimageex() uses the centre of the image as the origin too, which I was not expecting.
All my fudges have boiled down to ‘screensize/2’, and it all makes sense now. Panic over! :)
-
-
@toxibunny Yeah using the center of anything is pretty counter-intuitive. Same as using floating points between 0 and 1 for colors, same as using linear RGB... But hey I'm happy you figured it out :)
-
I’m happy to use the centre of a created box shape as the origin. ‘Where do you want this box?’ ‘Middle of the screen pls!’ ‘Bam! Done!’
It was just unexpected because I’m used to the usual rigmarole.. :)
-
@Doriphor said in Help! Shapes, drawtext(), drawimageex(), createimage() etc.:
@toxibunny Yeah using the center of anything is pretty counter-intuitive.
That depends on what you're making. Generally for games, center-based drawing is convenient. The center of game objects is generally more important than the top-left corner. The center is from where you can calculate the distance to another object for easy collision. The center's where you're most likely to want to rotate and scale around.
On the other hand, drawing with the origin at the top-left is well-suited for UI stuff.
Either way, F4NS provides both options.
drawImage
features exclusively top-left-centric drawing, whiledrawImageEx
features center-centric drawing by default and an origin parameter that you can use to set the origin of drawing wherever you prefer. Shape objects are center-centric because they're less like drawing calls and more like objects in the game world. They match sprite objects in this way.