Does inheriting the Sprite class and use group in pygame makes the game faster? - pygame

Does it help the game's performance? Or should I just blit the images? In the pygame official documentary, it said "It (pygame.sprite.Sprite) is the base class for visible game objects." and "It (pygame.sprite.Group) is a simple container for Sprite objects." Now for example a bullet, I have two options:1. inherit the class and add it to a group when something triggers
or
2. don't inherit and create a list manually and add it to the list when something triggers.
What I think of a group, is it blits everything in the group. Then what's the difference between this and screen.blit() in each class?
If there is no difference, then pygame.surface.GroupSingle really doesn't have any use. So I'm not sure what should I use (U+1F937)

The pygame.sprite module make the code shorter and easier to understand and offer you features like pygame.sprite.spritecollide, pygame.sprite.LayeredUpdates etc. The underlying code is highly optimized for use with the SDL 2 on which the pygame is based. However, there is no magic boost behind it. Parts of pygame are written in C/C++ (see GitHub - pygame
). So there is no python for-loop behind the scenes that calls .blit for each sprite. Drawing the sprites with a group is more efficient than drawing with a python for-loop and blit. Anyway, if you know what you are doing, you can write effective code without the pygame.sprite module.
pygame.surface.GroupSingle is not useless. It can be used like any other group and can be used with pygame.sprite.spritecollide etc.

Related

TweenEngine library vs libGDX Interpolation class

I'm developing a game based on the libGDX framework in eclipse that will have smoothly movements between my entities, so for that, I have used TweenEngine (and it is working nice), but recently I found that libGDX have its own class for interpolations.
I know both are for tweening (or for nice and smoothly animations), and I just want to know if there are technical difference or limitations between this 2 options basically because if both are the same, I would opt for the second one since it is already inside libGDX.
From one side there's generally better to use included tools because of integration and final application size (not saying of setting up the environment or exporting project problems).
On the other hand please notice that Libgdx Interpolation starts to be useful only when you are using it with Scene2D actions. And here is the problem in my opinion because you must implement stage and actors mechanisms - which is good idea by itelf but can be almost impossible if you have created almost whole application without it.
Then I would recommend you:
choose Scene2D actions + Interpolation easing if you are able to implement Scene2D in your project and the easing actions are only reason you want to use Tween Engine
choose Universal Tween Engine if you want to stay independent of new machanisms and use Sprites etc in traditional way

Can i write a modern/good game without using actors/sprites

I have got one sily question. I write a game in libgdx. But my friend always use actors and sprites. But i dont use this class. In all parts or elements of game i extends Sprite. Then i use a array list for using to save elements.
I write game like that: reading input, update, check collision and render. Its ok or not ?
There is no fixed way to go from A to B in programming. I have made a couple of good functioning games without the use of the stage and sprite class. These classes just help you get things done quicker. So yes you can write good games without the use of actors/sprites. It is even possible to write good games without the use of OpenGL or DirectX and create your own graphics library, but why should we? If you know what Scene2D and the sprite class can do for you it is kinda ignorant to leave them aside if they can help you.
It often takes little time to learn a certain library/extension. Once we know how to use it there will be profit for life.

Customize or create Starling animations, movements and Transitions

Since I don't know english very well, I'm not able to find clear examples and/or tutorials for what I'm trying to do.
So the (maybe stupid) question is:
How can I strongly customize tweens using Starling framework and make my Sprites(or MovieClips) following a line, curve or create every other non-linear movement that doesn't exist in Transition Class?
I have no problem with Basic Starling animation. So it should be a good start point.
Thanks in advance for examples, resources or suggestions.
PS. I already visit the "Starling Wiki" page about custom Transitions but, as a Beginner(almost Intermediate) coder I wasn't able to completely understand it.
I know there are many online resources about AS3/Starling/Flash/Nape/Box2D but it's not easy for a non-english Beginner programmer to understand them.
You can simple move Starling's movieClip by set .x .y .rotation
Since now, I haven't heard of scripted transition to make predefined non linear movement. As you said, you can move object from one position to another, but it won't happen in a curved line.
What I've done in the past is to predefine the path of the movement, as I needed exactly the same weird path. I did a path tween in Flash, then used one simple function to loop through all frames (using gotoAndStop()) and getting x and y property of the object, storing them in an array. This was done when initializing. Later on I could start animation on all my weird paths whenever I wanted, using onUpdate method of tween, and passing positions from the array I've populated in the beginning.
This of course is good if you have very weird paths. If you want very little curves, you could try to do a mathematical equation. Tween classes have an update function, which will be called on each frame. So on each frame you could do some calculations and modify the parameters. For example if you tween x and y properties, you could use the update function to add a random number to those values. Of course this will make very uncontrolled movement, I'm just giving an example.
The best solution I could think of, speaking of complexity/result ratio - to use Greensock's TweenMax (look at the second example) - it has a built in bezier tweening. This means it could move from point A to point B within a bezier curve. I think this will be a good solution for your problem :)

Is AS 3 capable of supporting a game with 600 + rotating images?

I made a simple game where squares collect crystals and bring them to a base and replicate. They are just .png images that rotate and move and yet when their number becomes greater than 500, the game starts to lag out. In Java I'm able to do a similar thing with 30,000 units. Could I be doing something wrong or is Flash just not that capable?
I'm using Flash Builder.
I get the image like this:
[Embed(source="../lib/red.png")]
public var redImgClass:Class;
public var redImg = new redImgClass();
Then I pass redImg to a "unit" class which takes an instance of "Bitmap"
I change its "rotation" and x,y members every frame.
Am I doing something wrong here?
you're not using Stage3D. If you use Starling, ND2D or write your own Stage3D wrapper you'll be able to get better performance.
You can also take a look at Jackson Dunstan's blog, this post is especially helpful: http://jacksondunstan.com/articles/2279
Another possible answer is to use blitting, that is, use a single Bitmap object to draw everything on via copyPixels(). This requires that your rotating crystal PNG be replicated into a sequence of rotated images, which you then use instead of directly changing rotation property. This approach is more performance-friendly, and does not depend on video card performance like Stage3D does.
Adobe's manual on blitting
Some discussion on blitting done by game devs
Daniel's answer is correct in that you should use the Stage3D APIs for greater performance. He didn't however mention that you should seriously consider using Starling, which wraps the Stage3D API with much easier to use classes:
Learn more about Starling here.
Example of the level of performance you could expect from Stage3D.
Starling is what you`re looking for (http://gamua.com/starling/)

Actionscript 3.0: Why is it a good idea to detach the code for moving an object from the object itself (eg. Ball and the Ball Mind)

My questioin is pretty much in the title, Why do I keep reading in actionscript 3.0 that its a good idea to seperate the 'mind' from the 'object' when writing code?
Thanks for any help, this is confusing the hell out of me.
If you're asking why graphics are separated from the positioning, movement and physics; take this tree I've drawn:
In the tree you'll see that Entity has two properties:
Graphics - what the entity should look like.
Body - where the entity should be.
Moving down, you will see that there are several things that extend Entity - most notable are the Player and the Enemy classes.
Extending my Entity class above, I can easily change what should be used as the graphics and also provide slightly different bodies. For example, the player and enemies will have obviously different appearances, and the Tree class won't need to use a Body that deals with values like velocity because it doesn't move.
Here are some advantages of the above:
We can create entities that don't have graphics, saving performance and memory.
We can use different types of graphics rather than having to stick to MovieClip if you had extended MovieClip with your Entity class.
We can add additional logic into the Graphics class such as being able to easily covert a Sprite or MovieClip into a sprite sheet for better performance.
The graphics will be easier to manage and more lightweight (as opposed to if it were auto-bundled with each entity).
Physics will be easier to deal with without needing to know about graphics.
The Body can be updated without immediate effects on the graphics.
Your understanding of physics being completely unrelated to appearance will improve significantly.