LibGdx game dev shooting bullets - libgdx

So basically every time i shoot, a new dynamic body is created with linear impulse , after constantly shooting my bullets game starts to get slow( it's obvious because i constantly create a new object..). What should i do to avoid this problem, i tried deleting objects, bodies?
Thank you for your answers in advance.

I'm still new to Java, but the way I understand it is that if anything references an object, that object won't be picked up by the recycler. Triple check all of your arrays and lists to make sure one isn't filling up with bullets. Display the sizes of your arrays while playing to see if one is acting weird.
For each bullet you probably want to see if it is off screen. If so, remove it from the list/array.

I know I am late but for future readers, Libgdx has something called object pooling specifically meant for things like this.

Related

cocos2d-x physics nodes slide along other

I am developing a game using cocos2d-x with built-in physics engine. In this game, user try to put object as stack and keep them balance.
However, i got a problem when i try to put an object on other one, it makes two objects slide along each other
I tried set friction value but nothing changes. I noticed that when i put a dynamic object on a non-dynamic object it's fine but when i put a dynamic object on other dynamic object, the problem (sliding along) will be happened.
I also create a gif demonstrate my problem because of my bad English.
http://makeagif.com/i/0lSVdW
Sorry i don't have enough reputation to post images.
I would appreciate any help!

ConcurrentModificationException in a Java game

I am at the early stages of developing a 2d shooter game (Picture Metal Slug) using JAVA. I want to be able to shoot many bullets at the time. In order to do so i use a Set to control the current bullets on the screen, each time you click you spam a bullet, adding it to the screen and to the set of bullets (so in each frame, you move each bullet in the set according to their speed).
My problem is that if I click fast enough I get an
ConcurrentModificationException
Is there a data structure able to add and remove fast enough different objects without getting such exception? I can not find any that suit me.
Thanks in advance
The data structure able to suit your requirements is a ConcurrentHashMap, check:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html

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 :)

hitTestObject() collide somehow not working how it should

Or that's what I think, at least.
I just began with AS3 and I'm trying to do a little game where one ball moves on its own and the other one is handled by the player. So far, so good. That works.
What isn't working is hitTestObject(); it just returns true when it's like 2 cm from the other object. Here's a picture so you can see: http://dl.dropbox.com/u/37057843/coll2.jpg
I've read that hitTestObject just creats a rectangle around the objects and then tests for collisions on those rectangles, is it because of that?
If you need any piece of code I'll deliver. I know there are some other opensource libraries/engines like Box2D to solve this in a better way, but I don't want to jump to engines directly.
Thanks for reading!
Yes, hitTestObject will use the clips bounding box.
Check out this link, it has a lot of great information as well as a class that will do what you're looking for
http://sierakowski.eu/list-of-tips/39-collision-detection-methods-hittest-and-hittestobject-alternatives.html
Direct link to the package
http://code.google.com/p/collisiondetectionkit/

Representing a Monopoly board in flash?

I'm brand new to Flash (and game programming, really), but want to learn a bit of it. My overall learning project is to create a Monopoly clone in Flash. Unfortunately, I'm struggling to get over even my first hurdle - how to create the board graphically, and how then to deal with it in the code. So far, my thoughts are to break the board down into the different sizes of tiles (the normal property ones, the corner 4 and a large one for the middle section), then somehow place these all in the correct position relative to each other and keep that positioning correct as the pieces (and thus the camera view) move about the board. (And, hopefully some day have a zooming ability too...)
Is this a good approach, or is there a better one? Does anyone know where I can find a tutorial specifically on creating board games in Flash (any sort really, wouldn't have to be Monopoly but just a game that has a board which tokens move across - and preferably which has to pan as well).
Also, as an aside, is there any way to have a dynamically coloured rectangle in a flash MovieClip (like you can have dynamic textboxs)? I ask because it would be useful if there was, as I could generate every property tile with just one MovieClip which took a name, a value and a colour...
everything you describe here you can do pretty easily once you get the hang of component sprites. personally i would make a single sprite that will then hold all of the "tiles" in the game, this would allow you to "zoom" the board while keeping all the pieces relative:
if you create this parent to have an addTile() and getTile(index:int):Sprite method then you can easily push the tiles and retrieve them from an array, so that Go is at index 0, old kent road is at 1 etc. that way you can use a single integer value to determine the position of the player piece as you can then use getTile(int).x etc.
the position of the tiles themselves can be worked out relative to the others. if you have a tile that is 20px wide and 40px high then you can position the tile as x = index * 20 for the first row, after the initial 11, you need to rotate them all and then use the y index instead (rotation = 90; x = 11*20; y = (index-11)*20) this will depend exactly on your origin point of your Sprite.
to draw coloured boxes you use the graphics of the Sprite, there are plenty of tuts on API drawing out there, but here is a basic box of 10x10px:
var drawing:Sprite = new Sprite();
drawing.graphics.beginFill(0x0000FF);
drawing.graphics.drawRect(0, 0, 10, 10);
drawing.graphics.endFill();
Another approach to your question could be to learn about Object Oriented Programming. That may not solve your representing the board graphically straight away, but it would definitely help you structure your game.
With OOP, you could define a "Property" Class with a set of properties such as streetName , color , price etc... I haven't played Monopoly in a while but you can get the general idea, i.e. to create a base object and make it specific by setting the object's properties. Your question about the colored rectangle can actually apply to other properties, a great way to avoid unnecessary repetition.
Broadly speaking OOP tends to emulate real life situations, so you could actually look at your Monopoly game, break it into its various parts, find common properties etc... I won't start a lesson here :) I'd be pretty bad at it, but there's plenty of resources out there . Look for OOP, Design Patterns & Actionscript3.
After a little research, you may find that your question about how to handle graphics may not be such a problem after all.
Your questions are way too general. I'm sure you don't want us to walk you through your whole project right?
Now to gain some experience, I suggest to you simply work through a few flash gaming tutorials. There are a LOT of those, I googled for 2-3 seconds and found this:
http://pelfusion.com/tutorials/35-flash-game-development-tutorials-fla-files/
I'm sure you feel disappointed by this answer, but this is the first step in solving your own problems. The internet has more than enough general game tutorials already. If you have specific problems, we might be of better help to you.
I assume with dynamically colored rectangles, you mean simply changing the color during runtime. Well you simply give the rectangle a name, and change the color property of it in code. Like this: rectangle.Color = Something.
You might want to start out with a simpler project just to learn some of the basics, maybe a little game where the player has to move a rectangle from one side of the screen to the other using the arrow keys or mouse, upon which a score is incremented or something. This will help teach you how the coordinate system works, among other things.
To draw stuff using code, you can create a new Sprite or MovieClip object and use its graphics property to draw primitive shapes (rectangles, etc.) to it at runtime.