406 Not Acceptable

Tag: j2me

Collision detection in J2ME

by Jim on Nov.20, 2008, under Java, j2me, java code

I am going to show a basic exclusion collision algorithm for J2ME. Whilst the Sprite class has collision detection methods, they are not very flexible and are useless when checking how objects collide. For example, in a bat and ball game you probably will want to know which edge the ball collides with in order to bet the ball to bounce correctly.

Exclusion collision detection is done by checking where certain parts of the two items are in correspondence to each other. Basically if the highest point of item A is lower than the lowest part of item B, it is not possible for the items to collide.

In addition, you can order your method based on which direction you are expecting collisions to usually occur from. This will then be more efficient than even the box detection method offered by the Sprite class.

public boolean collisionBetween(Sprite a, Sprite b)

{

if (a.getY() > (b.getY() + b.getHeight()))
{
//Not collided b is above a

return false;
}
else
{
if ((a.getY() + a.getHeight()) < b.getY())
{
//Not collided b is below a

return false;
}
else
{
if (a.getX() > (b.getY() + b.getWidth()))
{
//Not collided b is to the left of a

return false;
}
else
{
if ((a.getX() + a.getWidth()) < b.getX())
{
//Not collided b is to the right of a

return false;
}
}
}
}

//There is a collision

return true;

}
There might be a parenthesis error in here, as I did this in notepad at work. So I couldn’t check the syntax! From the formatting — which Wordpress kindly destroyed — it looks fine though.

Leave a Comment :, , more...

In other news…

by Jim on Oct.30, 2008, under Site Related

Since I have now recieved my grade, there is little reason for me to continue to withhold any J2ME based posts. So unless something else emerges to take up my time (apart from filling in crappy job application forms, seriously why did I bother with a CV?) I should be able to publish them.

I’ve noticed that the most popular posts on this blog/waste of space on the internet, are those on the more technical subjects or problems with software. Namely J2ME Polish and Ubuntu. So maybe I should post more about them; although, I really did not intend for this blog to be heavily technical.

Leave a Comment :, more...

Sorry about the lack of J2ME…

by Jim on Aug.29, 2008, under Java, j2me, university

I’ve decided that it would be best to me to hold back any articles on J2Me until after I have finished my project. I am not doing this because I do not have the time, but instead for plagiarism purposes. After all I would be posting code from my project onto this site and that may flag up on some plagiarism detection program and give me some serious hassle. The bigger issue is if anyone steals the content from this site (unlikely) and that gets picked up… then I’d have even more hassle to deal with.

Anyway, expect this stuff in September/October. I’ll have a few articles written ready for when I finish the project.

What’s really annoying is that some people get an extra 4 days to do their coding… that’s not what I’d be calling fair…

1 Comment :, , more...

Fixing J2ME Polish Integration With Netbeans 6

by Jim on Aug.21, 2008, under Java, j2me

J2ME Polish is a really neat package for J2ME programming. Really all I want it for is to change all my annoying Vectors into ArrayLists for speed. Now there are a few issues with the integration plugin on both Windows and Linux when using Netbeans. Heck it doesn’t even work properly on Netbeans 5.5, never mind Netbeans 6, 6.1, or 6.5…

Now what’s the only thing better than a poor integration plugin? No support, that’s what! A quick check on the J2ME Polish forums and you will find numerous posts asking how to fix these errors. So if you’ve tried going to the forums and had no luck (like everyone else,) you’ve come to the right place.

So here are a list of the problems and how to fix them.

 When starting NetBeans it prompts you with a message that states “org.netbeans.modules.java.platform/1 >1.10 required version found 1.9.2″(Or some other version) with options “Disable and continue or Exit”.

This one’s an annoying one, which occurs every now and again. I got this on 6.0 on Linux and 5.5 on Windows, but not with 6.5 on Windows. So how do you fix it?

Go to:

/usr/share/netbeans/platform7/modules

or in Windows (x being a version number)

Program Files\NetBeans 6.x\nb6.x\modules

If you can’t find this folder just search for  “de-enough-polish-netbeans.jar” as this is the file you need to edit. Open up “de-enough-polish-netbeans.jar” with a zip program (Winrar, rileroller, Winzip, etc) and edit the file at META-INF/MANIFEST.MF wih a text editor (notepad.) There will be a sentence that states:

org.netbeans.modules.java.platform/1 > 1.10

Change it to

org.netbeans.modules.java.platform/1 > 1.0

Reactivate the plugin in Netbeans and enjoy!

You are prompted to resolve reference problems relating to “Emulator Platform” or “SUN WTK 2.2 etc…” not being found.

This occurs to everyone…

Go to your an existing (non polish) project folder and open the folder nbproject. There should be a file called project.properties, open this with a text editor. Scroll down and there should be two lines stating:

platform.active=Sun_Java_TM__Wireless_Toolkit_2_5_2_for_CLDC
platform.active.description=Sun Java(TM) Wireless Toolkit 2.5.2 for CLDC

The versions may be different, as you may have a later Wireless Toolkit!

Now open the same file in your J2ME Polish project and replace the platform.active and platform.active.description lines with the ones from the non polish project.

Replace every occurance of “MPowerPlayer” with Sun_Java_TM__Wireless_Toolkit_2_5_2_for_CLDC (or what you had in your old project.)

Replace every occurance of “Emulator Platform” with Sun Java(TM) Wireless Toolkit 2.5.2 for CLDC  (or what you had in your old project.)

Close Netbeans and reopen and all should be fixed!

Leave a Comment :, , , , more...

Distinction!

by Jim on Jun.19, 2008, under Java, university

Well so far, anyhow it’s time to celebrate! Well, somewhat… I’ve got a project to do!

Over the summer (read till October,) I’ll be busy working on my project; hopefully it won’t mean a massive lack of activity like my exams caused. In fact I should be able to write up some tips on using J2Me as I go along. I am rather lucky as I managed to persuade my supervisor to let me develop a game using J2Me, which should be lots of fun to make and test :)

I have noticed that although there are a few good sites, tutorials, and guides on developing games for J2Me; there is a distinct lack of help on how to use the Visual Game Designer and Visual Map Designer features that were introduced with Netbeans 6.0. (Correct me if I am wrong, but they weren’t in Netbeans 5.5.) Because these tools haven’t been around very long there is also a lack of books covering them. The only real useful information about using them is the sample ‘game’ included in the Netbeans Mobility pack. So when I get the time I’ll provide a guide on using these tools for a simple ‘game’.

In addition, I should be able to host the odd version of the game. As it will need testing on multiple devices and I can’t just go out and buy a load of phones! Of course the emulators are useful, but there are situations where the device can act differently. I’ve noticed this being the case when using JSR-226: The 2D Vector Graphics API. Annoying really as Vectors can be a great tool for mobile games. With their being a number of resolutions to work with vectors have a great advantage over sprites, but with the low implementation of JSR-226 in devices, I’ll be overlooking them.

Back to beer!

5 Comments :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...