Archive for March, 2008

Testing custom loading screens with Pulpcore and Sloppy

Saturday, March 29th, 2008

Pulpcore provides a pretty good user experience with its built in loading scene. How ever there may be time where you wish to do some thing a little more interesting.

Like most thing in Pulpcore this is pretty easy to do.
In my example I have chosen to have a skull themed loading screen.

Here is the very basic steps needed to create a custom loading scene.
The first thing you need to do is extend the loading scene Pulpcore provides.

public class LoadingScene extends pulpcore.scene.LoadingScene

Next create a constructor that tells the base loading screen what asset file to load and the scene to display after loading.

public LoadingScene()
{
    super("skull.zip" , new SkullScene());
}

Next is to override the load function.
It is here that we tell the main layer to discard all of the default sprites.
I have read that you should create a timeline that animates out your scene and calls the new scene by setting the onCompletion with your custom timeline. I forgot to do this in my demo and it still worked ok. So if you find your loading scene loads but never moves on I would check out that bit.

public void load()
{
    super.load();
    getMainLayer().removeAll();
    //super.onCompletion(timeline);
 
    //Own sprites go here
}

Next override the update function to update your scene as needed.
You will need to call the super.update as well. This will get the existing asset download management code to do its thing so you can focus on drawing some thing interesting.

public void update(int elapsedTime)
{
    //Update your loading screen here
    super.update(elapsedTime);
}

So in a nutshell that is a basic custom loading scene.
After I had this all setup and running came the question of how do I test it?
Running locally my applet would load in under a second so you would only get the briefest glimpse of it.

That is when I found this cool Java app called Sloppy
Sloppy will emulate a slow connection for you. So for testing I build my applet and drop it onto my local web server.
Next I run Sloppy set the connection speed to some thing slow, point it my new Pulpcore applet and off it goes.

I have a demo of custom loading screens here
Here is a plain text link so you can try it with Sloppy if you happen to have a fast connection and would other wise miss the loading screen.
http://blog.alexjeffery.org/files/pulpcore/skulls/
You should see a black screen with some white skulls flying about and a big loading bar with a skull on it.
After that loads up the same deal but in white with pretty colors, a logo and some music that where loading during the loading scene.

Demo
Source code is here
Music credits to my friend Pimpfish

Pulpcore and JBox2d: A simple demo

Saturday, March 29th, 2008

Found a physics library called JBox2d the other day.
It is a Java port of the Box2d physics library.

The demos on the JBox2d site looked pretty interesting so I decided to see if I could get it to run with Pulpcore.
I managed to get a simple demo together fairly quickly.
It is a demo where you are able to drop a domino into a scene. You can also create new floors by right clicking 4 points in a clockwise order. IF you cross the points or drawn them out of order they will render but will not take part in the physics simulation.

Demo
Source

CakePHP session lost when using Applets or Flash

Thursday, March 27th, 2008

Recently I have been developing a website on my dev machine using the CakePHP framework. During this I ran into a problem where I could log a user in, view a Pulpcore applet and then be logged out right after viewing it.

After doing a bit of searching on the net I found the cause and the solution.

The cause:
My Pulpcore applet trying to do a request a CakePHP action from the web server to get and set the highscores.
CakePHP would check the HTTP_USER_AGENT and compare it to the one used to create the session.
When it found that they differed it would kill the session thinking it was preventing a session hijack attempt.

A solution:
In the config/core.php set the following lines
Configure::write(’Session.checkAgent’, false);
Configure::write(’Security.level’, ‘medium’);

This will stop CakePHP from regenerating a session every request and stop CakePHP from checking the user agent.
After that my Pulpcore applets where able to request actions as the logged in user fine and keep the session alive.