It's possible to create a Sprite from a TextureAtlas region with the original non-trimmed size of the image?
I have an Atlas with images that are trimmed, but I want to get the original image with whitespaces to create a Sprite; AtlasRegion have the original values of width and height.
If you are only trying to get the original size of the unstripped image, you can already get that with atlasSprite.getWidth() and atlasSprite.getHeight() as long as you haven't yet called setWidth(), setHeight(), setSize(), or setBounds() on it.
But to create a sprite that actually has and draws that white space is not really possible, because the trimming occurs when the texture is packed. That white space does not exist in the image file or the Texture because there are neighboring regions packed closely together. (Though I suppose you could draw the sprite onto a Pixmap, leaving white space around it, and load that in a Texture, and then create a Sprite from that, but this is convoluted.)
If you want to keep the white space, you must keep it when packing the texture atlas. You can set the stripWhitespaceX and stripWhitespaceY parameters to false when packing.
Related
I am the absolute beginner in this subject.
When I have some object in GIMP and his background is transparent, may I automatically crop the object to minimal size/resolution?
I do this manually, that means I select the object, but this is not exact.
It is still a little different, but this unsatisfying me, because when I have this image with object on my website (example dog with transparent background, 150x150) and I have other image on my website (example cat with transparent background, 155x155) and I set some attributes him, but in one .class, because do setting #id each image is impossible.
See Layer>Autocrop layer and Image>Autocrop image.
Note that in both cases, Gimp removes lines of strictly identical pixels, and this includes their opacity. So if you have even one single pixel which is faintly opaque, the auto-cropping will stop on it. In particular, non-rectangular shapes with a smooth contour have edges made of partially opaque pixels, so you may mistakenly think that the autocrop has missed out some space. This won't be the case.
In GIMP 2.10.30 you do
Image -> Crop to content.
I have a number of square regions in my game screen which, when actors move across these regions, I want the background image to show through from behind.
So, is it possible to draw to a SpriteBatch such that a region is subtracted/deleted from the texture (effectively "punching a hole" in it)?
I can't think how else to achieve this... Scissors seem incredibly impractical for my purpose, as I want to clip the areas INSIDE a number of squares. This is the inverse of Scissors - which clip areas OUTSIDE the scissors' bounds. The thought of calculating dozens of Scissor regions to fill the inverse areas between an assortment of square regions seems too impractical to be the solution... especially if the regions are moving.
Any help or suggestions appreciated!
UPDATE: Image attached.
I want the background to always be visible in the areas marked with the dotted lines. The dotted areas will move, so I'd rather not create more sprites from the background to lay on top, but rather have parts of the actors intersecting the dotted squares not be drawn. (Or any method that will achieve the same effect.)
I think the best hack is to not try and be so precise about clipping your actors, but to just re-draw the background on top the actors (and to clip that).
Specifically:
draw the whole background
draw your actors/sprites
draw the background with one cliprect for one part that "shows through"
draw the background with another cliprect for the other part that "shows through"
draw the dotted boxes around your cliprect areas
Great image, by the way. Easily worth 1000 words. :)
Say I have a MovieClip of a non-rectangular shape. For an example I've attached a file called Symbol1.png. In this attached file, I've rotated the symbol instance. Of course, this causes the bounding box to rotate as well.
Now say I place that rotated symbol instance inside another symbol. I've illustrated this in the attached file called Symbol2.png. Note that the bounding box now includes the overhanging corners of the rotated symbol that is inside.
Is there any practical way to determine the apparent bounding box of Symbol2 without including the corners of Symbol1's bounding box? I'm trying to zoom and rotate to an automatically calculated size and angle, but this overhang problem is causing a lot of extra space to be included in my final zoomed perspective.
Thanks.
Every container's bounding region is defined by the space that its children occupy. What you're looking for isn't the "bounding box" per-say (as Flash is accurately representing this), but rather the visible space the children occupy (which is much harder to quantify).
Thankfully, you're not the first to ask this, and (technically) this is a duplicate of Calculate Bounding box coordinates from a rotated rectangle
I am trying to get an effect like this:
http://www.welcomeanimations.com/welcome_animated_gifs_rotating_sign_orange_chrome_k_1.htm
I have tried all sorts of things:
Matrix translation/rotation - spins the text around the 'Z' axis, instead of 'Y'
Adding TextField to a sprite, and Sprite.rotationY++: reg. point is upper left corner
Adding to MovieClip - same as above (an article said MovieClip's reg. point was centered).
This should be trivial?!?! Help me stackoverflow, you're my only hope!
So you have to remember, Display objects scale and rotate around their local coordinate system. so when you put a textfield in a sprite, you need to center it in that sprite's coordinate system. And doing that for textfields is annoying because their width/height isn't always accurate but there is trick for that: get visual bounds, but normally you can take half of somethings width and height
I've created a prototype for you on wonderfl so you can see the solution working in action. Click on the blue square to see how the local coordinate system messes with the rotation
Finally as you use thing you might find things not rotating in 3D space quite right, this should be able to fix that.
I have two images, a gameboard and the same gameboard with all posible player positions in a pressed state. When a player moves to a position on the board, I put the board image over the pressed board image and slice using context.drawImage() on the pressed image, to display the pressed position through the slice. However, my game board contains positions which are not rectangular but different shapes.
Is it possible with html 5 canvas, to cut a non-rectangular shape out of an image to display the underlying image?
I found it's possible to use clip() on shapes but I can't find a similar option on images.
you can create a third image that is a mask with transparent (alpha-channel) pixels and non-transparent pixels, and use a
globalCompositeOperation
to merge the mask and the to-be-masked image into a new image ( think you can use an xor or source-out here..