As software developers we are geard toward solving problems. I personally love putting the puzzle together and seeing things working as they should. As simple as it sounds the fact that we can write one line of code and render an image to the browser is just cool if you think about it. The reason it’s cool is, it works. I know what the code is going to do when I write it and there is always something satisfying about that.
If you have been in the development field for a while then you, like all of use, you surly have run into the issue at the end of the day that you can’t make work, get the defect fixed or whatever the case may be. Either it is lack of experience with the problem at hand or the stress of meeting a deadline just gets to you, or usually it’s a combination of both.
No matter how may times I run into this type of situation I always seem to forget what gets me through it 95% of the time. Settle down, take a deep breath and walk away for a while. Yes the problem is there and it will not magically fix itself but sometimes your brain needs time to work. It’s as simple as that.
More often than not I will get off work, sit on my front porch and enjoy a beer or glass of wine. If you love software development as much as I do, my brain is constantly working and thinking about it. When I have an issue that I can’t figure out I tend to walk through the code in my brain line by line without even really noticing that I am doing it. I have even had dreams where I see the solution.
In my opinion when we relax this is when the power of the human brain kind of takes over. We sometimes have to get out of our own way and let our natural problem solving self figure out, and complete the problem on it’s own. I encourage everyone, not just developers. If you have a problem to solve and the stress or deadline is getting to you, “walk away”. I promise that more often than not your brian just needs some time to process.
I have been building a simple Astroid clone as some of you know. Well I found a bug that really stopped me in my tracks. My understanding is that it’s a bug with the Box2d logic that Corona uses for it’s physics engine.
During a collision event you basically crash the application if you try to set any properties on any of the bodies that are being updated by the physics engine. I was able to get a crash by trying to call addBody and also by trying to do something simple like setting X and Y properties on a body that the physics engine was trying to update during the collision.
The fix really is pretty simple and I consider more of a “hack” than anything. You basically have to create an enterframe event and call your logic with in the enterframe function. This basically allows the physics update to complete and then you can act on the objects within the physics engine on the next frame. As you will see I create a local function with in the collision event that runs and then also removes the enterframe that we create as soon as we are done running our logic.
If anyone has a better solution please feel free to post in the comments.
The things that where crashing the app that are now fixed where the following. When a missel collides with a rock I wanted to create smaller rocks and then move the missel that was just used off screen so that it does not collied with any more objects till it is shot from the spaceship again.
Just wanted to post my progress on the mobile development I have been doing with CoronaSDK. I started out building this game in Flixel in the Flash Player. Development was pretty easy and I got most everything ported over but there are of course some differences when it comes to working with the physics in Corona. (thanks Matthew Pringle for the help )
The problem I was running into was how to get the Rocks to fly around randomly and also detect when they move off screen in order to place them on the other side of the screen just like in the classic game. The forums on the ansca site proved to be very helpful after some tweaking on my end.
I am not sure if I am detecting the objects going off screen in a very good manner as there is more than likely a more optimized way of doing it. I am basically using an enterFrame event to check all the x and y locations and then preforming some checks to place the object where it needs to be if it goes off screen. Below is the code for applying the phisics and also my enter frame function that I am using.