I'm working on a game and have created a simple numeric "font" for displaying the number of days.
Love2D's newImageFont() function lets one use a specifically-formatted image to create a font for any number of glyphs.
I've created my font, loaded it in my love.load() function thus:
dayFont = gr.newImageFont("/fonts/dayFont.png", "1234567")
Here's the font image file:
And then in love.draw(), I am trying to use it to display one number:
love.graphics.reset()
love.graphics.setFont(dayFont)
love.graphics.printf("1", 260, 20, 30, "left")
But nothing appears.
While troubleshooting, I discovered that when I don't set the font, the number does appear in the location expected, so the problem seems to be the imageFont itself.
The problem was in the 4th parameter of love.graphics.printf(), which sets the max width of the text. Because it was set to a max width of 30 pixels, and the glyphs themselves are 36 pixels wide, it simply doesn't render any glyphs at all.
Updating the line in love.draw() to:
love.graphics.printf("1", 260, 20, 40, "left")
fixes the issue.
Related
I'm having trouble in Kivy setting an image size. I want to keep the aspect ratio fixed but I also want to position things precisely over the top of the image.
To do this, I make a RelativeLayout that has the same size and position as the image. However, when I check the size of the layout, it is always slightly larger than the displayed image. Making precise alignment very difficult. The wiki mentions something like this:
By default, the image is centered and fits inside the widget bounding box. If you don’t want that, you can set allow_stretch to True and keep_ratio to False.
They also include code if you want to make the image slightly larger than the containing widget:
<-FullImage>:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: self.width + 20, self.height + 20
pos: self.x - 10, self.y - 10
But nothing about making them exactly the same size!? Surely I should be able to dictate the containing widgets size so the aspect ratio etc. is exactly as required.
I have tried many things but whatever I try, I cannot get the outside edges of the displayed image and a layout to coincide.
Does anyone have any experience with this?
Apologies, I have discovered the problem, the images had a transparent border that I wasn't aware of (the images were passed on to me from elsewhere) I have removed this and it has solved the problem.
How to indicate the sizes of objects and their coordinates when developing a mobile game. For buttons, I tried to indicate a percentage of the screen size (local scrPercentW = display.actualContentWidth / 100) or division of a constant display.contentCenterX (display.contentCenterY). But in the simulator on some devices it’s right, but at some intervals and sizes it’s wrong.
For example, I have four buttons on the menu that I need to arrange at the same distance from each other and from the edges of the screen. How should I do it?
I see that you resolved the problem of display.contentWidth, while for the size of a text you just need this:
local someText = display.newText( "here goes your text", 20, 80 )
someText.size = 30
I need to print an organigram of a large corporation with php/MySQL. The organigram will be boxes with peoples names in them, and there are just over 200. The page will be very wide and long. I want to be able to set the page size to something like 90 inches high by 300 inches wide (The PDF will be printed on an eco-plotter which is usually used to print architectural plans, but can be used to make huge black and white wall posters. I have done this many times using PageMaker/InDesign but never with php). Is it possible to do this with TCPDF and if yes how? If no, any suggestions of how I can do this in php?
Yes, TCPDF is perfectly capable of generating very large PDF documents. If you're rendering a lot of elements, it would likely be a good idea to make sure you have a high memory limit.
I created an example here: Example large format PDF
The key part is providing your own custom page size. Here's what I used in the script that generated this example:
// create new PDF document, I set landscape,
// inches for units, 300 wide and 90 deep
$pdf = new TCPDF('L', 'in', array(300,90), true, 'UTF-8', false);
The rendering part is, of course, then entirely up to you. I just had some fun with some bezier curves and cells with borders set.
//Line from Dot to Tiny
$pdf->Curve(50, 30, 50 + $offsetx, 30, 50 + $offsetx + 1 , 20 + $offsety_down,
60, 20, null, $style);
$pdf->SetXY(60, 20);
$pdf->Cell(20, 10, 'Tiny', 1, 1, 'TLRB', 0, '', 1, 'C', 'C');
If you want to use points for working with your document (which I'd suggest it over inches - it's real easy to accidentally make 1 inch thick lines and such) pass something like the following to the constructor:
Note: points are a physical unit of measure equal to 1/72 of an inch. This is not specifying rendering resolution but the actual physical size of the document. For line definitions you can use partial numbers for your physical units. For example: 0.75 to specify 3/4 of a point.
// create new PDF document, I set landscape,
// pt for units, 300 wide and 90 deep, 72 points per inch.
$pdf = new TCPDF('L', 'pt', array(300*72,90*72), true, 'UTF-8', false);
TCPDF will work with several different types of units. Another option is millimeters, for instance. Methods like SetXY and Curve and so on will then use whatever page unit you had set here.
I'm working on an ARKit/SceneKit Ruler app and I'm trying to render the ruler's tick marks and numbers as a texture. The ruler is of variable length and can change on the fly.
What's a good way of render the numbers and tick marks? Right now we're using UIGraphicsBeginImageContextWithOptions and doing a
ctx.fill(CGRect.init(x: 0, y: 0, width: 64, height: 8))
but it seems like not a great solution. The tick marks seem possibly easier to use an image texture with, but what about the numbers?
For numbers you could use SCNText. If you'll set extrusionDepth to zero, you'll get plane text. And for marks you could use SCNPlane. Both of them have one-sided materials by default, which means that back side will be invisible.
I'm using corona simulator. I displayed display.contentWidth and display.contentHeight .The width is 320 and height is 480. I've also made a text saying "Hello", and played with positioning.
I've noticed the x values looked pretty accurate, I would set x value of text to 0 and the center of it would be half covered and half revealed. Same results for x value of 320, but on the other side of the phone simulator.
When I set y value to 0 it sits right under the Carrier and fake signal strength symbol, fully revealed. When I set the y value to 480 the heights max, it would have about an inch gap from the bottom of the phone. -- My thoughts are that it should be half covered vertically both ways :-S
In corona simulator i'm viewing it in Iphone5 , and notice when I change to Iphone it would reveal as I would expect. With Iphone 5, droid, and some other view it would give me these results.
* My question is would my program look the same on all devices, or is corona simulator accurate displaying what it would look like. If it displays different on variety of devices, Why?
width = display.newText (display.contentWidth .. "px is Width", 200, 200, nil, 30)
height = display.newText (display.contentHeight .. "px is Height", 150,300, nil, 30)
text = display.newText ("Hello", 0, 480, nil, 30)
The resolution of the iPhone 5 is different to the iPhone 4 (obviously), but rather than receiving different display.content* values, Corona handles it using something called display.screenOrigin. This is the difference between the display being used and the standard display (iPhone/iPhone 4). If you print these values, for example:
print("Origin x = "..tostring(display.screenOriginX))
print("Origin y = "..tostring(display.screenOriginY))
Then you will see that one of them, depending on your simulator's orientation, will be "-44". This is the difference in pixels. In your example for what I assume is the portrait orientation, you would need to position Y for top and bottom like so:
--For positioning at 'true 0'
obj.y = 0 + (display.screenOriginY)
--Or, for positioning at "true bottom"
obj.y = 0 - (display.screenOriginY)
Hope this helps. For more on display.screenOrigin, see the Corona documentation for X and the Corona documentation for Y
Cush
Every object has a rectangular boundary as in figure 1 below. Here there is a text object with boundary indicated with black colour.
The red dot at the top is that objects default anchor point.
If you are not specifying the text's x and y positions as (obj.x=... & obj.y=...), then corona will position the object according to the points in the display object creation line (i.e.., display.newText(""......)). For example, if you have a code like:
local text = display.newText ("myText", 0, 0, nil, 30)
then the text will be placed such that the red dot is at (0,0). It is why you saw it under the status bar.
General object placement in corona is as below:
Underlined myText indicates the different positioning of the text object according to points in object creation line. i.e.;
local text = display.newText("myText",x,y,nil,30)
_w ==> display.contentWidth
_h ==> display.contentHeight
Keep Coding.................. :)