Open grayhaze opened 6 years ago
Does it work with Lime 2.9.1 + OpenFL 3.6.1?
No, I get the exact same result with 2.9.1 and 3.6.1.
I assume that a FlxCamera's pixels represent the state of the camera's view before any transforms are applied for camera zoom, etc. Do I perhaps need to apply a matrix to the copyPixels()
or draw()
calls to apply these transforms manually? Is there a way of accessing the relevant matrix from the FlxCamera, as the internal matrices seem to be private?
You shouldn't need to make adjustments. I think I had this working previously. I'll check later today.
On Sat, 28 Apr 2018, 11:34 Kevin Purcell, notifications@github.com wrote:
I assume that a FlxCamera's pixels represent the state of the camera's view before any transforms are applied for camera zoom, etc. Do I perhaps need to apply a matrix to the copyPixels() or draw() calls to apply these transforms manually? Is there a way of accessing the relevant matrix from the FlxCamera, as the internal matrices seem to be private?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFlixel/flixel/issues/2145#issuecomment-385163934, or mute the thread https://github.com/notifications/unsubscribe-auth/ACbEvDvitj424G5TBcj-xUD6C1tTmnu-ks5ttEWhgaJpZM4TrVOm .
As an aside, compiling the above code to Flash produces the following output:
I don't actually use the Flash target in my main project, but it appears that the behaviour in this target is to copy the camera viewport correctly, but still at the default zoom.
So I've got this sort of working on cpp targets, using a transform matrix built using public properties of the camera:
override public function update(elapsed:Float):Void
{
super.update(elapsed);
cameraCopySprite.fill(0);
var transformMatrix = new Matrix();
transformMatrix.translate(-(0.5 * cameraOriginal.width * (cameraOriginal.scaleX - cameraOriginal.initialZoom) / cameraOriginal.scaleX), -(0.5 * cameraOriginal.height * (cameraOriginal.scaleY - cameraOriginal.initialZoom) / cameraOriginal.scaleY));
transformMatrix.scale(cameraOriginal.scaleX * 0.997, cameraOriginal.scaleY * 0.997);
cameraCopySprite.pixels.draw(cameraOriginal.canvas, transformMatrix);
}
The translation calculation is based on those done in FlxCamera
to calculate offsets, and that part works. The scale calculation requires multiplying the camera's scale by some seemingly arbitrary value. If that multiplication isn't done, or the value by which I'm multiplying passes a certain threshold (which varies depending on the zoom), the resulting image is empty. If it weren't for this I'd be happy just performing these transforms whenever I need to copy the camera.
So this works. I have no idea why though. 😁
override public function update(elapsed:Float):Void
{
super.update(elapsed);
cameraCopySprite.fill(0);
cameraCopySprite.pixels.draw(cameraOriginal.canvas);
cameraCopySprite.fill(0);
var transformMatrix = new Matrix();
transformMatrix.translate(-(0.5 * cameraOriginal.width * (cameraOriginal.scaleX - cameraOriginal.initialZoom) / cameraOriginal.scaleX), -(0.5 * cameraOriginal.height * (cameraOriginal.scaleY - cameraOriginal.initialZoom) / cameraOriginal.scaleY));
transformMatrix.scale(cameraOriginal.scaleX, cameraOriginal.scaleY);
cameraCopySprite.pixels.draw(cameraOriginal.canvas, transformMatrix);
}
Code snippet reproducing the issue:
Observed behavior:
I'm trying to copy the contents of a camera to a sprite so that I can apply effects to that sprite, such as applying an alpha mask by using
copyChannel()
on the resultingBitmapData
(e.g. https://stackoverflow.com/questions/48075991/is-there-a-way-to-apply-an-alpha-mask-to-a-flxcamera?rq=1). Before getting to the point of applying effects however, I'm having difficulty getting the camera pixels to copy over 1:1 while observing camera zoom, scroll, etc. The above example creates a single sprite containing a red circle, which is placed in the source camera. That camera's zoom is then set to3
, resulting in the circle being rendered at 300% of its original size. When I copy the pixels from this camera to a new sprite, which is displayed in a second camera, it seems that the current zoom of the source camera is not observed and this results in the circle displaying at its original size in the target sprite.Expected behavior:
I would expect the target sprite to be a 1:1 copy of the source camera's current view, including zoom, scroll, etc.