I am having the color codes as R:38 G:171 B:228 , but when I set the values as .38f in the color with Red : Green : Blue:, I am unable to get the desired color:
[CategoryLbl setTextColor:[UIColor colorWithRed:.38f green:.171f blue:.226f alpha:1.0f]];
Please help.
You're mixing up two scales: UIColour looks like it uses floating point values 0-1 whereas the usual RGB values are 0-255. Instead you want
38 / 255 = 0.1491f
171 / 255 = 0.6706f
226 / 255 = 0.8863f
so
[CategoryLbl setTextColor:[UIColor colorWithRed:0.1491f green:0.6706f blue:0.8863f alpha:1.0f]];
There may be better ways to do this, e.g. using the 0-255 values - I don't know OSX / iPhone development well.
Actually it looks like you can just do:
[CategoryLbl setTextColor:[UIColor colorWithRed:(38/255.f) green:(171/255.f) blue:(226/255.f) alpha:1.0f]];
which is easier to understand (although I gave you enough d.p. the first one should be as accurate).
Related
I am rather experiences libgdx developer but I struggle with one issue for some time so I decided to ask here.
I use FillViewport, TiledMap, Scene2d and OrtographicCamera. I want the camera to follow my player instance but there are bounds defined (equal to mapsize). It means that camera will never ever leave outside of map, so when player comes to an end of the map camera stops following and he goes to the edge of the screen itself. Maybe sounds complicated but it's simple and I am sure that you know what I mean, it's used in every game.
I calculated 4 values:
minCameraX = camera.viewportWidth / 2;
minCameraY = camera.viewportHeight / 2;
maxCameraX = mapSize.x camera.viewportWidth / 2;
maxCameraY = mapSize.y - camera.viewportHeight / 2;
I removed not necessary stuff like unit conversion, camera.zoom etc. Then I set the camera position like this:
camera.position.set(Math.min(maxCameraX, Math.max(posX, minCameraX)), Math.min(maxCameraY, Math.max(posY, minCameraY)), 0);
(posX, posY is player position) which is basically setting camera to player position but if it's to high or too low it sets it to max or min defined before in right axis. (I also tries MathUtils.clamp() and it works the same.
Everything is perfect until now. Problem occures when aspect ratio changes. By default I use 1280x768 but my phone has 1280x720. Because of that bottom and top edges of the screen are cut off because of the way how FillViewport works. Because of that part of my map is cut off.
I tried to modify maximums and minimums, calculate differences in ratio and adding them to calculations, changing camera size, different viewports and some other stuff but without success.
Can you guys help?
Thanks
I tried solution of noone and Tenfour04 from comments above. Both are not perfect but I am satisified enough i guess:
noone:
camera.position.x = MathUtils.clamp(camera.position.x, screenWidth/2 + leftGutter, UnitConverter.toBox2dUnits(mapSize.x) - screenWidth/2 + rightGutter);
camera.position.y = MathUtils.clamp(camera.position.y, screenHeight/2 + bottomGutter, UnitConverter.toBox2dUnits(mapSize.y) - screenHeight/2 - topGutter);
It worked however only for small spectrum of resolutions. For strange resolutions where aspect ratio is much different than default one I've seen white stripes after border. It means that whole border was printer and some part of the world outside of border. I don't know why
Tenfour04:
I changed viewport to ExtendViewport. Nothing is cut off but in different aspect ratios I also can see world outside of borders.
Solution for both is to clear screen with same color as the border is and background of level separatly which gave satisfying effect in both cases.
It stil has some limitations. As border is part of the world (tiled blocks) it's ok when it has same color. In case border has different colors, rendering one color outside of borders won't be a solution.
Thanks noone and Tenfour04 and I am still opened for suggestions:)
Here are some screenshots:
https://www.dropbox.com/sh/00h947wkzo73zxa/AAADHehAF4WI8aJ8bu4YzB9Va?dl=0
Why don't you use FitViewport instead of FullViewport? That way it won't cut off your screen, right?
It is a little bit late, but I have a solution for you without compromises!
Here width and height are world size in pixels. I use this code with FillViewport and everything works excellent!
float playerX = player.getBody().getPosition().x*PPM;
float playerY = player.getBody().getPosition().y*PPM;
float visibleW = viewport.getWorldWidth()/2 + (float)viewport.getScreenX()/(float)viewport.getScreenWidth()*viewport.getWorldWidth();//half of world visible
float visibleH = viewport.getWorldHeight()/2 + (float)viewport.getScreenY()/(float)viewport.getScreenHeight()*viewport.getWorldHeight();
float cameraPosx=0;
float cameraPosy=0;
if(playerX<visibleW){
cameraPosx = visibleW;
}
else if(playerX>width-visibleW){
cameraPosx = width-visibleW;
}
else{
cameraPosx = playerX;
}
if(playerY<visibleH){
cameraPosy = visibleH;
}
else if(playerY>height-visibleH){
cameraPosy = height-visibleH;
}
else{
cameraPosy = playerY;
}
camera.position.set(cameraPosx,cameraPosy,0);
camera.update();
I'm using Apple's UIImage+ImageEffects category from WWDC (2013?)
This method works just fine on iPhone 6, but creates a really strange unblurred, oversaturated image on iPhone 6 Plus:
[self applyBlurWithRadius:60 tintColor:[UIColor colorWithWhite:1.0 alpha:0.3] saturationDeltaFactor:2.4 maskImage:nil];
iPhone 6 (proper):
iPhone 6 Plus (weird):
Any idea what's going on?
Update: I've determined through trial and error that setting the blurRadius to anything less than or equal to 50 shows up OK, so it's related to the radius. I'd still like to know what exactly is causing it to goof on the larger screen.
I know this question is old and the OP has since moved on, but I would like to explain why it's different on each phone... for future generations.
The iPhone6 and the iPhone6+ have different screen resolutions. Mainly, the iPhone6 is has a scale of 2.0, while the iPhone6+ has a scale of 3.0.
Why does this matter?
In the source code for applyBlurWithRadius in the source file UIImage+ImageEffects.m, you will find these lines:
CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
uint32_t radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
if (radius % 2 != 1) {
radius += 1; // force radius to be odd so that the three box-blur methodology works.
}
You can see that the inputRadius will be different based on what the scale of the screen is. So, on the iPhone6, this value will be 60*2 (end result for radius will be: 227), and on the iPhone6+ the value will be 60*3 (end result for radius will be 339). This will obviously produce the different results since they are different values.
As for why the color difference? I am pretty sure the radius shouldn't exceed 255 otherwise undefined results may occur (probably integer overflow, causing color components to wrap back to zero). Since the iPhone6+'s screen scale value pushes it above this value, you see weird results, but not on the iPhone6 since it's below that threshold.
You should be able to see the same weirdness happen on an iPhone6 by using the value of 90 for the blurRadius parameter.
Side note: You shouldn't need values above 30 for parameter blurRadius anyway -- the results won't be much different beyond that point.
Hope this helps you.
im working with SetConsoleTextAttribute API (Delphi to be specific), well anyway i cannot find a list of available colors anywhere?? can anyone help me out
There a 4 Bits used for the foreground color
FOREGROUND_BLUE; //1
FOREGROUND_GREEN; //2
FOREGROUND_RED; //4
FOREGROUND_INTENSITY; //8
which will give 16 possible colors. (0-15)
The next 4 bits are used for background color with the same scheme
See this. Colors are formed by ORing different constants. For instance:
An application can combine the foreground and background constants to
achieve different colors. For example, the following combination
results in bright cyan text on a blue background.
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY |
BACKGROUND_BLUE
For more Turbo/Borland Pascal CRTish implementations of such, see this. The colors available in the Windows console via SetConsoleTextAttribute work out roughly to be the same ones as the CRT unit, so any more relevant details can be found there.
I have a string that I can paint in Core Text like so:
CGContextShowGlyphsAtPoint(context, 0, 0, glyphs, glyphCount);
Works great. Now I need to paint each of those glyphs individually, in the same spot as they would end up painted using that nice utility function above. And I'm not doing it in English, either...sometimes there is a glyph below a glyph below a glyph (diacritic).
Obviously I need something like this:
CGPoint pt = CGPointMakeZero;
for (int i = 0; i < glyphCount; i++) {
CGContextShowGlyphsAtPoint(context, pt.x, pt.y, glyphs[i], 1);
pt.x += <some quantity>
pt.y += <some quantity>
}
Unfortunately I haven't figured out what the "some quantities" are supposed to be yet...some combination of metrics fromCGContextGetAdvancesForGlyphs and/or CTFontGetVerticalTranslationsForGlyphs and/or CGContextGetGlyphBBoxes have been my first guesses, but I haven't got it to work yet.
Anyone have a solution/other ideas?
If you want a test string, try అక్త్రిన్.
(Background: I need to do the painting of glyphs one by one because of customizations to appearances to individual glyphs that I want to make in my app).
Way late to the party here but this question/answer combo shows how layout is calculated line by line then glyph by glyph.
Core Text calculate letter frame in iOS
hey all i want to know rotate the UI Segmented control to be in a vertical look
cheer
BOB
You can do in this way.
#define degreesToRadians(x) (M_PI * x / 180.0)
[...]
segControl.transform =
CGAffineTransformRotate(segControl.transform, degreesToRadians(90));
if you want set correct position, remember that it consider the center of segControl!
ex:
segControl.frame = CGRectMake(-125, 220, 320, 30);
hope this helps.
I haven't done something like that before but I think one approach could be to subclass UISegmented control and use Affine Transforms related functions inside the Core Graphics framework, there you use for example CGContextRotateCTM() to give a 90 degrees rotation.
Hope this helps.