-
-
Notifications
You must be signed in to change notification settings - Fork 964
Is it possible to add support for rotating sprites? #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We have this on our backlog, we will need to see prioritize that. |
But, it may take a while to be done, you could do this by using the methods available on flutters's canvas |
Hi, @vladest, that's already achievable for children of position component, including animation component. Just update the angle variable in the update method by the dt parameter and angular speed. For example: void update(double dt) {
// other stuff
angle += dt * ANG_SPEED;
} Please let us know if you have any more questions, feel free to open issues :) |
yes, I've done similar just subclassing SpriteComponent |
@vladest a couple of questions, which version of Flame are you using? Are you using the class Angle from a component should affect other components |
11.2 yes, thats correct, w/o canvas save/restore all the component changes angle around some point in the center of the screen (afaik) |
@vladest when using BaseGame, components should not affect others, because it already restore the canvas state, check out this simples example: import 'dart:math' as math;
import 'dart:ui';
import 'package:flame/anchor.dart';
import 'package:flame/components/component.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyGame().widget);
class Palette {
static const PaletteEntry white = BasicPalette.white;
static const PaletteEntry red = PaletteEntry(Color(0xFFFF0000));
static const PaletteEntry blue = PaletteEntry(Color(0xFF0000FF));
}
class Square extends PositionComponent {
static const SPEED = 0.25;
final rotate;
Square(double size, this.rotate) {
width = height = size;
anchor = Anchor.center;
}
@override
void render(Canvas c) {
prepareCanvas(c);
c.drawRect(Rect.fromLTWH(0, 0, width, height), Palette.white.paint);
c.drawRect(Rect.fromLTWH(0, 0, 3, 3), Palette.red.paint);
c.drawRect(Rect.fromLTWH(width / 2, height / 2, 3, 3), Palette.blue.paint);
}
@override
void update(double t) {
if (rotate) {
angle += SPEED * t;
angle %= 2 * math.pi;
}
}
}
class MyGame extends BaseGame {
MyGame() {
final s1 = Square(64.0, true);
s1.x = 50;
s1.y = 150;
final s2 = Square(64.0, false);
s2.x = 50;
s2.y = 250;
add(s1);
add(s2);
}
} Let me know if you still have doubts or problems. |
no, that is absolutely not true. Game is the interface. BaseGame implements game. You can use the game interface, but it will do nothing for you, not even resetting the canvas. If you want to have things easy, use BaseGame and the canvas will be reset for you. If you want to use Game, please take a look at the BaseGame implementation just to be aware of what flame does for you that you will need to do yourself or be aware what things won't happen automatically. |
that's make sense thanks. probably I was confused with naming. I'm usually use "Base" in abstract class |
@vladest if you have any more problems with rotating sprites, please let us know :) |
Is there a way to rotate Sprites about the Z-axis? |
Not sure what you mean by Z-axis on this case, Flame (and Flutter) don't support 3d. |
I was asking about a similar implementation of Matrix4.rotationZ(radians) which can be used in combination with Transform widget, to rotate a widget by the specified radians about the Z axis. |
Actually, more common is to add components animation support
The text was updated successfully, but these errors were encountered: