I'm using the version 1 release of Flame, and adding a parallax background which works great.
// load background layers
final layers = _layersMeta.entries.map(
(e) => loadParallaxLayer(
ParallaxImageData(e.key),
velocityMultiplier: Vector2(e.value.toDouble(), 1.0),
alignment: Alignment.center,
fill: LayerFill.none ,
),
);
// create background parallax
parallax = ParallaxComponent(
parallax: Parallax(
await Future.wait(layers),
baseVelocity: Vector2(20, 0),
),
);
add(parallax);
Once I set the camera to follow a Sprite camera.followVector2(player.position); then its obvious that the parallax was initialized to the size of the screen because as the camera moves, the edges of the parallax become visible with a black game world background. I've tried changing the size of the ParallaxComponent and the Parallax to no avail.
Changing the canvas size doesn't do much either onGameResize(Vector2(camera.canvasSize.x, 5000));
Is there a standard way to set a component fill the world size? The source code talks about the world size, but I don't see any way to control it.
The ParallaxComponent is a PositionComponent which lives in the world that the camera is viewing by default. If you want a PositionComponent to be relative to the viewport (or the GameWidget) you have to change its positionType to PositionType.viewport.
So in this case the initialization of your ParallaxComponent could look like this to make it ignore the camera:
// create background parallax
parallax = ParallaxComponent(
parallax: Parallax(
await Future.wait(layers),
baseVelocity: Vector2(20, 0),
),
)..positionType = PositionType.viewport;
Related
Currently, I'm using this package to draw some images. And I'm saving this image. I reviewed package classes and functions and tried many solution to achieve my aim. But I haven't found any solution yet. Maybe I'm trying to do impossible thing so I want to ask this: Can we draw a transparent canvas then our output image background can be another color?
Here's some code snippet:
canvas = Canvas(
recorder,
Rect.fromPoints(Offset.zero, Offset(size.width, size.height)),
);
paint.blendMode = mode;
ui.Image src = await picture.toImage(size.width.toInt(), size.height.toInt());
paint.isAntiAlias = true;
canvas.drawImage(src, Offset.zero, paint);
picture = recorder.endRecording();
ui.Image img = await picture.toImage(size.width.toInt(), size.height.toInt());
ByteData? imgBytes =
await img.toByteData(format: ui.ImageByteFormat.rawStraightRgba);
In above code snippet, we create a canvas and drawImage then we get the image bytes. But in this case, this image's background is transparent. But I want set red color. So when I
add
canvas.drawColor(Colors.red, BlendMode.src);
My image can be created as I want, but this time I see a red canvas in my view. But I want a transparent canvas when I draw it. I only want to see output image's background is red.
Is this possible?
I've got a moving sprite that animates over a loop of 4 images to make it look like it's walking in one spot. I want to make the sprite move forward by a certain amount when I click a button. I've tried looking for how this might be done, but it's just made me confused. I've found this information sheet by Flame Game that explain effects, but I don't understand how to apply it to what I've got (https://docs.flame-engine.org/1.0.0/effects.html).
This is the constructor for the class that makes the dog move:
Dog()
: super(
priority: 1,
playing: true,
scale: Vector2(1, 1),
size: Vector2.all(50),
) {
animation = SpriteAnimation.spriteList(runPictures, stepTime: 0.2);
position = Vector2(150.0, 150.0);
}
I want the dog to move 100 pixels towards the top of the screen, while it's going through the loop above, when a button is clicked. This button would send it to a class that would make it move. If someone could provide sample code or a useful tutorial, it would be very helpful.
You are on the right track, you want to add a MoveByEffect to the component.
I assume that you already have the button set up and that you have access to an instance of the Dog component from there, then you simply add the effect to the component:
final dog = Dog(...);
// Or whatever callback you have for the button
void onTap() {
dog.add(
MoveByEffect(Vector2(0, -100), EffectController(duration: 1)),
);
}
This will move the dog 100px upwards during one second.
I'm working on drawing shapes and editing them using CustomPainr() and GestureDetector().
I've successfully drawn the shapes and now I'm going to select and drag the drawn shapes to move them.
I didn't understand much about implementing it yet, but dragging and moving the rectangle succeeded in the following way.
List<Rectangle>? _rects;
List<Line>? _lines;
GestureDetector(
onScaleStart: (details) {
RenderBox box = context.findRenderObject() as RenderBox;
Offset point = box.globalToLocal(details.focalPoint);
// check point on shape
final selectedRectIndex =
_rects!.lastIndexWhere((rect) => rect.rect!.contains(point));
}
// canvas
canvas.drawOval(shape.rect!, shape.paint);
canvas.drawLine(shape.p1!, shape.p2!, shape.paint);
The contents() could be used to determine if the offset was in a Rect() of rectangle.
And the move was successful by updating points in onScaleUpdate().
Then, how do I check if the point I touched is in the Line shape?
Is there a method for this, like "rect!.contains(point)"?
And then I'm going to add this function, when the shape is selected like in the image below, there's a point at the vertex, and drag it to change the rotation or scale.
Can I get some advice to do this?
My application using Unity And Vuforia. I want set position of 3D model of tracked found target to center Screen and AR Camera after track lost. I mean that I want to show lost Image target on center position.
void centerGameObject(GameObject gameOBJToCenter, Camera cameraToCenterOBjectTo, float zOffset = 2.6f)
{
gameOBJToCenter.transform.position = cameraToCenterOBjectTo.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, cameraToCenterOBjectTo.nearClipPlane + zOffset));
}
Then you can call it with
centerGameObject(gameOBJ, Camera.main);
The default zoffset(2.6f) should work but you can change it by supplying the third parameter.
centerGameObject(gameOBJ, Camera.main, 6f);
Hi I'm new to blackberry. I want to show the image within the circle using qul.
The easiest way to vignette an image is to overlay it with another image. In Cascades if you create a Container using either DockLayout or AbsoluteLayout you can position multiple ImageView objects on top of one another. The first object will be on the bottom, last on the top, by default. You simply create an image with a transparent viewport of the shape you want. You can scale the image at runtime but you should make it about the size of the largest frame you will need to preserve quality. I used Gimp to create a 786 x 78x pixel image with a white frame and a transparent circle in the middle and saved it to the assets directory as frame.png. I grabbed another image I had easily to hand and create a BlackBerry project with this QML code in an appropriate place:
Page {
Container {
layout: DockLayout {
}
ImageView {
imageSource: "asset:///FusionMap.PNG"
preferredHeight: 360
preferredWidth: 360
}
ImageView {
imageSource: "asset:///frame.png"
preferredHeight: 360
preferredWidth: 360
}
}
}
This is the result: