Images are too large - xamarin.forms

I have two images, one is a transparent TestTube.png (25 Width, 150 Height) and the other image is a Block.png (10 Width, 10 Height) that goes on "inside" of the test tube image.
Below is what I WANT my Screen View to look like, these would be just two different PNG's on top of each other a bunch of times.
|X| |X| |X|
|X| |X| |X|
|X| |X| |X|
|X| |X| |X|
|X| |X| |X|
|X| |X| |X|
And this is roughly what it looks like now
| | | |
XXXXX XXXXX
XXXXX XXXXX
XXXXX XXXXX
| | | |
The Block.png is WAY too large, and I'm not sure how to make it smaller. Putting in a smaller image size does not seem to work.
I'm trying to use Grids to do this but I'm not sure if this is necessary or not.
function void doStuff()
{
StackLayout objLayout = new StackLayout();
Grid objGrid = new Grid();
//Assign the grid layout two Rows and two Columns
//Semi Psuedo Code
foreach(column in grid)
{
TestTubeImage = new Image { Source = "tube.png", WidthRequest = 25, HeightRequest = 150 }; }
BlockImage = new Image { Source = "block.png", WidthRequest = 10, HeightRequest = 10 }; }
objGrid.Children.Add(TestTubeImage, x, y);
objGrid.Children.Add(BlockImage, x, y);
}
objLayout.Children.Add(objGrid);
Content = objLayout;
}

Related

Matter.js i need always same movement ( on any canvas size)

I need help. I have a player and I want jump the player in same diametric order. I wanted to fix this with getHeight with return ( innerHeight/100 * per ), but there's no improvement. Even worse, if the canvas size becomes bigger the player doesn't jump as high and if the window becomes smaller the player jumps higher! I dont want to callibrate in hard code way. I need responsive function!
"leave a comment before vote negative"
r.player.force = {
x: 0,
y: -(getHeight(0.03)),
};
Matter.Body.applyForce(r.player, { x: r.player.position.x, y: r.player.position.y }, r.player.force);
public getHeight(percente: number): number {
return this.reperH() / 100 * percente;
}
this.reperH = function () {
if ((window as any).innerHeight > (window as any).innerWidth / this.aspectRatio) {
return (window as any).innerWidth / this.aspectRatio;
} else {
return (window as any).innerHeight;
}
};
Full source : link
I don't know about a single function to do everything, but you can multiply the force by window.innerHeight or window.innerWidth:
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var vw = windowWidth/100;
var vh = windowHeight/100;
var jumpForce = vh*-5;
var pushX = vw*0.1;
After that, you just apply jumpForce to the player when they jump and pushX to the player when they move (You will have to multiply it by -1 when the player is moving to the left). If you want it to look even more consistent, you can have jumpForce use vw instead of vh and make sure all of the objects created in the game use vw for positioning and scaling.
Whether you do use only vw or not, you will have to convert all your pixel values into vw or vh (depending on whether you're changing the x or y of the object), so it looks like this:
var object = Bodies.rectangle(vw*60, vw*40, vw*8, vw*5);
I figure that matter.js already have diametric scale with simple number inputs.
When i remove all getHeight and getWidth and put numbers everything start works fine again.
It is my solution for any platform to get percent always no matter for screen size.
My opinion : Matter.js looks like good solution.

How to size the texture to occupy only a portion of a QQuickItem UI

I have overriden updatePaintNode in the following way to draw an OpenGL texture on a QQuickItem derived class called MyQQuickItem here.
QSGNode *MyQQuickItem::updatePaintNode(QSGNode * oldNode, QQuickItem::UpdatePaintNodeData * /*updatePaintNodeData*/)
{
QSGSimpleTextureNode * textureNode = static_cast<QSGSimpleTextureNode *>(oldNode);
if (!textureNode) {
textureNode = new QSGSimpleTextureNode();
}
QSize size(800, 800);
// myTextureId is a GLuint here
textureNode.reset(window()->createTextureFromId(myTextureId, size));
textureNode->setTexture(my_texture);
textureNode->markDirty(QSGBasicGeometryNode::DirtyMaterial);
QSizeF myiewport = boundingRect().size();
qreal xOffset = 0;
qreal yOffset = 10;
textureNode->setRect(xOffset, yOffset, myViewport.width(), myViewport.height());
return textureNode;
}
This renders the texture content well but covers the whole of my MyQQuickItem UI.
How can reduce the bottom margin of the texture to say fit 80% of the height of MyQQuickItem.
I want to render the texture to a portion of MyQQuickItem & leave the rest blank or black? Is that possible within updatePaintNode.
Note that the texture size is not the UI window size here. My texture size is 800 by 800. Whereas the UI window size is different and depends on the screen.
I found the answer to this:
Changing myViewport.height() gives the required end in Y direction one wishes to set. Similarly, changing myViewport.width() gives the required end in X direction one wishes to set.
4 parameters in TextureNode's setRect can stretch & fit the texture in the way one wishes within a portion of the QQuickItem.

SDL Sprite how to set sprite center of origin

I'm messing around in SDL trying to build a game and have noticed that when I blit a sprite to the screen the origin of the sprite is set to the top left corner, 0,0.
To get around this I've simply adjusted the sprite placement by 1/2 the sprites width but as a solution it feels kind of clunky - I want to build a platform game so surely the COO will need to be at the sprites feet for collision detection with the platforms - and I was wondering if SDL had any functions in place that would allow me to set the center of origin a bit like the sprite editor in construct2.
This is my drawing routine:
// Draws the hero sprite according to clipframe
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
My instantiation of it:
apply_surface(width /2 - heroSpriteSize /2, height /2 - heroSpriteSize /2, hero, buffer, &wait[frame]);

Trying to calculate the width of navigation buttons automatically based on a container

I have for example 3 buttons.
<ul id="container" style="width:500px">
<li>home</li>
<li>another button</li>
<li>ok</li>
</ul>
I want to find out what the width each button should so that they are spread out in the container.
I tried this but doesn't look so good:
width of the container 500px divided by the total number of characters 20. that gives me 25px for each character
So I make 'home' 100px (4 characters x 25), 'another button' 350 px(14 characters x 25), 'ok' 50px (2 characters x 25) that totals 500px but doesn't look so good. I want the same padding for each button.
my formula looks something like this (not the same padding)
| home | another button | ok|
I would like more like
| home | another button | ok |
any suggestions on the a formula for this?
I wouldn't make specific widths for the buttons, I'd just give them identical padding then experiment until the spacing looked right:
jsfiddle
OK this works good:
int containerWidth = 500
int characterWidth = 9; //this seems to work ok for a variety of font sizes
int totalButtons = 3;
int totalCharacters = 20;
int allButtonsWidth = (characterWidth * totalCharacters); //(=180)
int pixelsRemaing = ((containerWidth - allButtonsWidth ) / totalButtons); //(=106)
int leftOvers = (containerWidth - ((totalCharacters * characterWidth) + (pixelsRemaing * totalButtons))); // (=2)
home = (characterWidth * 4) + pixelsRemaing + leftOvers ; //(=142+2 = 144)
anotherbutton = (characterWidth * 14) + pixelsRemaing; //(=232)
ok = (characterWidth * 2) + pixelsRemaing; //(=124)
// total: 500

Image Rotate 3D in Flex, but display another image on back of this image?

i want to rotate 3D an Image called img1 in Flex. I want to rotate it around y axis 180 degree. I can do this by using 3D effect already built in Flex but i want to do a bit more different.
I want during rotating, there's another image called img2 appear on back of img1 (in default case, the image appear on the back is img1) and when rotating finish, the image will be img2.
How can i do this ?
Thank you.
If you need no perspective effect, it's quite easy to do. A rough implementation (not tested!):
// Event.ENTER_FRAME event listener
void on_enter_frame(event:Event):void
{
// m_angle is a member of the class/flex component where on_enter_frame is declared
// ANGLE_DELTA is just a constant
m_angle += ANGLE_DELTA;
// Angle clamping to the range [0, PI * 2)
m_angle %= Math.PI * 2;
if (m_angle < 0)
m_angle += Math.PI * 2;
// If we currently look at the front side...
if (m_angle < Math.PI)
{
img1.visible = true;
img2.visible = false;
img1.scaleX = Math.cos(m_angle);
}
else
{
img1.visible = false;
img2.visible = true;
// If you omit negation, the back-side image will be mirrored
img2.scaleX = -Math.cos(m_angle);
}
}
So every frame we increase the rotation angle, clamp it to the range [0, PI * 2). Then depending on the value of the rotation angle, we hide/show the pair of your images, and then perform x-scaling of the visible image.
Thank you, now i found a solution. Please check it here, it's very easy to do.
http://forums.adobe.com/thread/921258

Resources