As3 RotationX and RotationY blur the original image - actionscript-3

I have a quick question regarding RorationX, Y, Z
Whenever i have applied that, my image gets blured
_eventParent.getChildAt(1) is a Sprite.
Any reason why? and how can i stop this?
_eventParent.getChildAt(1).rotationY = _differentX;
_eventParent.getChildAt(1).rotationX = _differentY;

When you rotate a sprite, it gets automaGically associated bitmap buffers for fast manipulation with the rendering engine. There are solutions for that, which are not very effective but here is a
link to the best so far method.

Related

Drawing shapes by pixel in libgdx

I'm trying to draw shapes in libgdx that change constantly so I don't think using sprites will work, and I was wondering if it is possible to draw a shape using a function that is called for each pixel to determine if it should be drawn.
What I need to draw is part of a washer (an area bound by two concentric circles and two radiuses), with the circles and radiuses changing constantly.
What I want to know is wether here is a way to draw complex shapes that are determined by a function (the shape would consist of those (x,y) for wich theFunction(x,y)=true) instead of an image
Everything is possible. The best solution really depends on the details of what you want to create. Perhaps you can show an example of what you mean?
Without seeing an example, it looks you might want to start with ShapeRenderer. See the javadocs for detailed information on how to use it. That should get you started and if you find it to be insufficient in some way then you at least you have a more specific question.
Btw, using a Pixmap as suggested by #Ludevik is also possible, but since you want it to change constantly that would imply uploading the entire image each frame which is not very performant.
Would use of Pixmap help?
You can create a pixmap:
Pixmap pixmap = new Pixmap(300, 300, Pixmap.Format.RGBA8888);
and then draw pixels with specific color on that pixmap:
pixmap.drawPixel(x, y, color);
Then you can then create a texture from that pixmap and draw the texture. I'm not sure about the performance of such solution though.
See also Pixmaps in the libgdx wiki.

Correct way to fill shape with image cropped from sprite

I am slightly confused about the "correct" way in KineticJS to fill a shape with partial images (crops) from a combined image file (sprite).
Seems like one can either use fillPatternImage with a defined offset, which seems to draw the complete image, albeit with the rest of the image invisible. I only got acceptable performance after I moved those shapes to an extra layer as my sprite is relatively large and the impact of not cropping correctly decreased the fps dramatically.
All alternatives that I have found use the attribute "fill" with another attribute "image" in it, but this seems to result in black background every time.
Using an Image-shape would help, but is rarely usable since my shapes are seldom rectangular.
Since the KineticJS-documentation does not mention specifying crop coordinates ("just" offset, w/o width and height), what is the absolute correct way to do it?
The absolute "absolute correct way" would depend on the platform and your particular code, but.
Have you looked at sprites? http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-sprite-tutorial/.
To mask simple animated sprites I'd use this in adition of plain javascript after each draw.
context.globalCompositeOperation = 'destination-in';
The performance of drawImage with composite operations is better than drawing shapes manually on webkit, at least.

Zooming in and out on canvas

I wrote a paint application using the HTML5 canvas element.
Now I want to give the user an option to zoom in and out while painting.
How can I do this?
There are a few ways. It really depends on what you're looking for.
You could do it by scaling the entire context, as in ctx.scale(2,2), and then redrawing everything at this larger scale. Several things drawn, like paths and text, will scale gracefully. To accomplish this you will need to keep good track of everything drawn so far.
Another way is to take the entire canvas and draw it back to itself. This requires a temporary canvas because the operation is really: Draw to temp canvas, clear main, draw back to main scaled.
Another way is to use CSS transforms to merely zoom the canvas itself, which will make the image blurry (its zoomed!) but does not require changing any of the pixels already on the canvas.

Joining Sprites together in AS3?

So created a Sprite to which I add other Sprites which are game tiles. Each tile is 60 x 60 px big. In result I've the Sprite with about 200 childs (those tiles).
When I try to startDrag() the container sprite the lag when moving it is very noticeable..
Is there a way like to join the tile Sprites so the container would have only 1 child Sprite instead of 200? Because it lags so much probably cause it needs to move (change the x and y) all those 200 tiles.. Am I correct?
In this case I can't use the cacheAsBitmap property, cause user can zoom in or zoom out the map..
Glycerine & Aurel do touch the crux of the real solutions. However I'd like to add.
You are correct by the way, when you said it has to manage so many sprite locations when you move the container around. CacheAsBitmap sure does does tackle this to great extent but the real solution is blitting. Try this link for that :
http://www.adobe.com/devnet/flash/articles/blitting_mc.html
It doesn't matter if a user zoom or something of that sort is required cause you can always switch between bitmap data & the original vector sprites. Your problem arises in moving.managing lotsa sprites, so just before doing that use optimizations, after that let them be back to their selves.
I've had the same issue before. Is it possible to 'join' them together - in a sense.
When you add your 200 sprites onto a screen - I assume you put them all into another parent sprite.
A this point - you will take a snapshot, or a screenshot - or a photographic replica (whatever you want to call it) of all the sprites and write the image (bitmapData) to a parent sprite. At this point. delete/remove/hide/nullify the original sprites and you'll be left with a sprite containing bitmap data.
One big image to move about and zooming and the like is no bother.
If you need code - ask. It's time consuming code so you tell me first then I'll write it :P
Hm, joining them would actually be quite hard... You would need to get the graphics, the code and all and put that into the parent...
I don't think that is the problem - you should do something else... In this case, I think that by "tiles" you mean that the parent would be a tile map, correct? So, you probably have a 2-dimensional array (array of arrays) with tile types - instead of parsing that array at initialization, creating A LOT of Sprites, try re-parsing it in each frame (it is faster), but add only the Sprites that are possible to see. That is - their X position (after adding the zoom and camera X) is greater than -sprite.width, where the height is also scaled by the zoom, and lesser than stage.width + sprite.width (again, width after zoom). Same goes for Y, only with the height attributes.

AS3: Setting alpha on parent sprite without affecting sprites children

Stupid question I guess, but I haven't managed to find the answer yet :)
If I change some value for a parent sprite, the same value will affect all of its children. So if I set alpha or width on the parent, the child will automaticly get the same value.
Is there some way I can prevent that from happening?
Short answer: no
Longer answer: for alpha there is no work around that I know of. For width, you could hack something to work so that the child clips looks to see what the parent scaleX is and then increases its own scaleX if it is less than one but this isn't something that I'd do.
The best way to do this is to create a holder clip that contains no graphical assets but you can use to move other clips around together.
It seems that doing alpha = 1/alpha of parent works fine. That means setting the alpha to higher than 1 on the child. At least this work with AS3/Flash 10.
If You want not to avoid changing alpha of the children at all (like David suggested), but to prerender sprite before it's faded (so You can fade out a human without showing his bones), then set blendMode = BlendMode.LAYER;
This is not available on GPU rendering, so on mobile devices You probably need to create a bitmap, draw the sprite to the bitmap and then fade the bitmap. Maybe it's even easier, as AIR has some upgraded feature of cacheAsBitmap (it's named differently, that is, You have both cacheAsBitmap and the other one I'm talking about), that maybe will work, but I don't know as I don't use AIR.
if you are after the dimensions then then you can simply get the inverse of the parent transformation matrix and apply it to the child, there is a pretty good tutorial here for example:Transoform Matrix.
see applications -> Shaking Smilies section for what you are after.
other things like alpha i dont know a way to get around.