Category: Programming
Items about code of all sorts, including php, Java, Javascript, Haxe, Perl, and many more.
Within the nme.geom package of HaXe NME you’ll find Matrices, Points, Vectors, Rectangles and… ColorTransform? Yes, it seems a slightly odd place to put it, but that’s where it is, and it can be useful in your project. No doubt, there are endless things you could do, but I wanted to talk briefly on how I’ve used it across my previous Pinball project and now, in Tower Defence.
Simply, sometimes you want the same object to appear multiple times in your project, but with subtle variations. Behavioral changes can be accomplished in code by subclassing, size variations by scaling, but what if you wanted it red in one instance and green in another? Including the same image twice with different colours seems redundant, even if the images in question are quite small, so what are your options? Well, a ColorTransform is an option if the image is a simple, single colour. In Pinball, I used this method to colorize the lights and lighting effects – the image files themselves were greyscaled, and were coloured in code before being displayed – and now in Tower Defence, I’m using it on some UI elements (the slider knob’s that change colour dependent on value).
Let’s step through how this works. First, of course, you have to create a graphic you want to use. Here’s the image of the slider knob in Tower Defence, as it came out of Photoshop…
Hello! Sorry that last post was so brief, but I hope you liked the video! Here’s another one for you, with some loose ends tidied…
Continue reading “Longer Tower Defence update”
Hey all, just a quick one this time. My tower defence game has some graphics (disclaimer: none final) and a few new little features and so I figured it’s probably time to show more of what works.
Continue reading “Tower Defence update”
Hello again, today I bring you another lesson learnt.
When you choose Haxe for a project there are a wealth of 2D physics engines available, mostly ports of other popular engines, like Box2D. There are actually a few distinct ports to Haxe of various versions of B2D, but the most up-to-date and the one I’ve been using is Joshua Granick’s port of 2.1a. You can get it from Haxelib by opening a command prompt / terminal and running “haxelib install box2d”
In brief, it’s fantastic. Once you get a handle on how it works and where all the bits you want to use are it’s pretty simple, a far cry from the engine I initially experimented with – Physaxe – which was basically 20 pages of pure maths disguised as classes and functions! But there are some small issues I’ve run across while using it, and here comes the latest (and its solution, I wouldn’t leave you hanging!)
Continue reading “The intricacies of removing bodies in Box2D”
Just a quick one: In re-creating my blog I had to go through one of my least favourite ordeals, choosing a theme. Given time I’d create my own (but, also given time, I’d probably just write my own bare bones CMS) but that’s not an option, so I usually look for simple, clean themes that I can perhaps customize a little bit and be done with. This theme is called Greyville, by the way, it’s rather pretty I think.
I actually set this blog up locally using Xampp first so I could import a few posts, do those theme mods and make sure everything worked before it went live. I was using the Greyville theme for a while, and had gotten used to it, when I realized it didn’t support a proper menu bar. So I decided I’d add one, how hard could it be?
Fairly simple it turns out, if you have the WordPress API imprinted on your mind. I spent most of my time looking up functions and then trying to chase their dependencies around the internet to find out why they weren’t working right. But I got there eventually, and I thought posting this information could help someone else who just wants to add a menu bar, or wonders why none of his custom php works…
Thanks, as seems increasingly usual, to Joshua Granick for writing about another awesome Haxe feature that works so well with NME, but no one seems to know about: Inline C++!
This seems so obvious! It compiles to C so why can’t we throw our own stuff in there? Obviously you sacrifice the niceties of a higher level language like HaXe: Vague compiler errors and manual memory management abound, but it’s worth it sometimes.
For example: My first thought, since I’ve been implementing around it for some time, was to try and implement game saves on my TouchPad. I actually tried to use NME’s extension system to implement this a few weeks ago and got nowhere, so I wasn’t sure what to expect. I wanted to call into the webOS API to get a safe path using PDL_GetDataFilePath(), then write a string out to a file, and in a second function be able to read that string back.
Greetings!
I’ve been implementing a second thread of execution in my current game project for the last few days. I had tried to do this in my previous set of code, but either had constant crashes or half the game not working because that second thread wasn’t ticking over. At that time there was almost no instruction online as to how threads worked in NME, but that has changed recently thanks to the (always excellent) Joshua Granick, whose blog post, “Using Threads with NME“, lists out some basic scenarios for communication between threads. There’s also some useful nuggets of information in this forum thread.
In my new tower defence project I need to know when certain things are touching, or when object A is within range of object B, and other nonsenses like that. It seems perverse now, but the first time I had to implement collision code a few years ago I didn’t know why the computer couldn’t TELL there was a collision: The blue circle is halfway-inside the red square, surely that’s obvious? But implement I did, and it was horrible and rough, but for that project it didn’t matter at all.
In the early days of this project I implemented a collision system again with just two shape types: Rectangle and circle. It worked well enough, but the performance was awful — I had time to knock together a few arrays and an update loop, but more advanced stuff like knowing which objects could be safely ignored to speed the whole process up takes time to write and test. Having experience with it previously, I ran back to Box2D, dropping the source in to my project so I could begin prodding.
(Note: This article is to be fleshed out once I can install Maya again to access my saved models and screenshot them!)
For a little while just before work began on that XNA RTS game that was quickly cancelled, I was trying to learn 3D modelling in Maya. Me and my accomplice were both programmers, we recognized we were going to have problems with art right away, so I volunteered to try and learn some modelling. I’m not saying I became a virtuoso, but over the few months I was working through the included “Getting Started” tutorial I think I learnt a lot of the basics, and I did produce a number of simple in-game objects that were sadly never used. The largest object I attempted was the main character for a future game which was to be a platformer/puzzle game where you controlled a mouse through a house full of wacky obstacles to escape to freedom. Obviously the game never happened, but I do have a short video of the rigged mouse model with a simple animation.
In my final year of University I was lucky enough to take part in the robotics module – as I understand it, people starting the same course as me at the time I was leaving got to do robotics as standard in their first year! Not so with us, it was kept to the last and had limited places and all.
The course was half practical – building and programming a robot – and half theory – how to process data from sensors and control various aspects of the robot. The robots themselves were based on a small micro controller board with many simple I/O ports, built in to a shell made of Lego. I was one of a team of three, and initially we were all unsure of the programming side of it, but confident in our Lego abilities! This changed around pretty abruptly when it came to actually building the thing – turns out Lego can be a pain!
The objective of the robot was to collect coloured cans in a small square arena, and deposit them in the identically-coloured corner of the arena. Obviously, without hitting walls or getting stuck was preferable too.
Continue reading “University “Intelligent Robotics” module”