I want to display two circles, with different colors (might change them dynamically) and let both circle. There is a different range of ways to get animation going. Animating objects, using canvas, etc. and I am still confused which one would be the right approach.
I was thinking of extending View and overwriting onDraw(Canvas) is that right?
Really you should look at using some existing frameworks rather than re-inventing the wheel. Depending on just what you are doing look for android animation and/or graphics/games libraries and find one with the facilities you need.
Related
I've been struggling with shadows in Android for awhile.
So far, I ended up using https://github.com/L-Briand/ShadowLayout most of the time.
Although it works fine for static views of any shape, it bugs a lot in any animation.
I'm looking for a better or easier way. Any suggestions?
My UIs have lot of irregular shapes (not just rounded rectangles) also it has to be at least 26+ (even if the app is 21+, I think it be ok with a lesser alternative for 26-). So, to sum up, what I'm looking for is a library or way of having a shadow:
Can wrap around any shaped layout
It's not a multilayer drawable
Can be animated
Can be colored
At least 26+
Thank you in advance for any suggestions.
I'll pick the best answer in a week (I think that's fair).
I am trying to make a game where you have multiple levels where you have to figure out a way to where a certain color should go through pipes that are displayed on the screen. The pipes look like (it all should be better, but just as a reference). So basically there should be an animation of color going down these pipes (different color for different pipe). Now, I can make a gif and use that as my animation, but it's just too large (aprox. 5MB, which isn't a lot, but if you put dozens of levels, it tends to add up).What would be a solution that would be the most efficient?
Well I would first recommend you to go with Unity for Game Development.
If not then check out cocos2d or any other frameworks.
Secondly, if you want to animate things using the native code, then play around with draw() functions (as suggested by #Wakeman) of the Canvas.
Now coming to your question, if your game does not involve continuous user interaction and you are thinking of GIFs as a solution then I would recommend using Lottie library.
You can create beautiful animations in Adobe After Effects and import those (json files) in Android without hurting much memory, plus would get high resolution output.
Have you tried using the drawRect() or drawCircle()? You only need coordinations of the starting point, the turning points, and the ending point. Draw it with a recursive function with delay, and it should look good.
It would be better to construct your levels as tilemap. Every segment of pipe can be coded by number and drawn as bitmap (Sprite) that depends on its state (empty, 1/4, 1/3, 1/2 or full). Similar principles works for engines like Unity/Cocos 2D or your own renderer. This way of building your levels would be hundred times lighter in size than full screen animation and used multiple times for different levels.
Here is a scenario on which i done a lot of research on google but hopeless. the scenario is, i am going to develop a 2D game in which i want to use multiple backgrounds and i want to translate them as they are moving forward, it must look like one background is near and translating/moving fast and the other background is a bit far and translating/moving a little slow. the nearer background have almost full intensity and the farer background have a bit low intensity. you can say they have different transparency levels. the question is, how can i get this task done or is this possible to use multiple backgrounds.
any suggestion will be appreciated.
as an example, see the image of BADLAND game bellow.
I think as far as I got your question you want to put two or more images one over another. I mean if you are trying to overlap the multiple backgrounds and asking for it yes it can be done easily.
What you need to do is to use the FrameLayout. as
"FrameLayout represents a simple layout for the user interface of
Android applications. It is usually used for displaying single Views
at a specific area on the screen or overlapping its child views."
and then you can implements the animations on them and translate them You can find different types of translation over them.
Here is all about using the frame layout frameLayout1 framelayout2 and for animations and translation here are links. link , link2 , link3
I am looking for a very simple and efficient way to draw arrows in JavaFX 8, what is the best way to achieve that (performance-wise if let's say I'm willing to draw hundreds or thousands of them)?
I've heard using a Canvas to draw on it is quite efficient.
However, I do not know whether the best implementation is to go with:
Inheriting from the class Shape [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Shape.html]
Inheriting from the class Line? [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Line.html]
Bothering myself every now and then with the GraphicContext class in order to create the arrow manually? Does not sound like the good idea.
Other strategy?
The best method depends on various factors which we don't know so it's difficult to give a clear answer here. I will try to give a few general hints though and you will have to decide yourself if these are applicable to your problem.
For mass drawings using the canvas sounds like a good idea.
Simple lines and rectangles are much faster than paths (also polylines and polygons).
Some line joins/caps are faster than others.
Avoid transparency.
It may be helpfull to consider specialized approaches like, e.g. creating images of your arrows and then just painting these images.
Michael
I have a big problem with the drawing in LibGDX. First I don´t use every physics or other complicate things in my game. I only draw sprites and put Rectangles at this for Collision Detection. I have 3 Screens in my game: splash, menu and game. So I use a Stage in the splash and menu screen but I don´t really if I use Stage in the game too or I draw with SpriteBatch? The Stage have really pros with Actions but it a little bit more complicate to use Actors. Are there other ways to do this? I don´t want to use World, because its to complicate for the beginning of game developing.
What I want to use for the game?
Actually you always draw with SpriteBatch, as Stage uses its own SpriteBatch. If you think you could need some of the advantages of Scene2ds Stage, like Actions, Groups or other things, you should use Stage. In my opinion it is really easy to use. You have your own objects, which extend Image or Actor, override their update(delta) methods, where you check if the Actor should move (Keypressed or an event for the AI). Also you should detect collisions there and take care about them. Then, if you are extending Image you don't need to care about drawing (but Image needs Drawables so you will have some problems with Animations), if you are extending Actor override the draw(SpriteBatch batch), where you call batch.draw(...).
Thats it.
A big disadvantage of Stage is the sorting. The Actor, which is drawn as first is in the background. The last Actor overdraws all others and is in foreground. You can sort them by using the z-Index, but it is not really sure.
So you may decide to use your own kind of Stage (it is more or less a list, containing all Actors, and when updateor draw is called, it is called for every Actor in this list), and add your own sorting there.
It depends on your game design, on your opinion and on your style. Look at some tutorials/examples and decide how you want to create your game.
You can use either, it depends on what kind of game are you creating. But anyway, don't create multiple instances of SpriteBatch — instead create only one and pass it to Stage constructor, because it's heavy object. (Yes, Stage uses a SpriteBatch under the hood)
Also, Stage may be extremely useful if you need any on-screen controls (buttons, joystick, etc), because you can use classes from scene2d.ui and don't reinvent the wheel (some wheels are not very easy to reinvent properly)