|
BlueJ
Absolute Beginner's Guide - using PulpCore with BlueJ
Although tools such as Netbeans and Eclipse are quite powerful, this short guide will hopefully help increase the audience of PulpCore users to those who use BlueJ (from http://bluej.org: "an integrated Java environment specifically designed for introductory teaching") and wish to avoid ANT scripts. Setting up PulpCore in BlueJ
(Yet Another) Hello World program for PulpCoreCredit where credit is due: This example is amalgamated form the tutorials from http://www.alexjeffery.org (old code updated to work with PulpCore 0.11), and http://cloningtheclassics.com/ .
import pulpcore.Stage;
import pulpcore.scene.Scene2D;
import pulpcore.image.Colors;
import pulpcore.image.CoreFont;
import pulpcore.image.CoreGraphics;
import pulpcore.image.CoreImage;
import pulpcore.sprite.Label;
import pulpcore.sprite.Sprite;
import pulpcore.sprite.FilledSprite;
import pulpcore.sprite.ImageSprite;
public class PulpyDemo extends Scene2D
{
FilledSprite background;
Label helloLabel;
ImageSprite logoImage;
public void load()
{
// Calculate coordinates of applet center
int centerX = Stage.getWidth() / 2;
int centerY = Stage.getHeight() / 2;
// Create a background
background = new FilledSprite(Colors.YELLOW);
add(background);
// Build a new label
helloLabel = new Label(CoreFont.getSystemFont(), "Hello World!", centerX, 40);
// Center the label horizontally and vertically
helloLabel.setAnchor(0.5, 0.5);
// Add the label to the scene
add(helloLabel);
// Load an image
logoImage = new ImageSprite(CoreImage.load("logo.png"), centerX, centerY);
// Center the image
logoImage.setAnchor(ImageSprite.CENTER);
// Add the image to the screen
add(logoImage);
}
public void update(int elapsedTime)
{
// this method has been intentionally left blank
}
}
Running the appletBecause PulpCore uses a JavaScript file to help load, we will not use BlueJ's built-in AppletViewer. Instead, we will set up the necessary files manually.
<html>
<head>
<title>PulpCore Demo</title>
<body>
<div id="game">
<script type="text/javascript">
<!--
pulpcore_width = 450;
pulpcore_height = 250;
pulpcore_archive = "myArchive.jar";
pulpcore_assets = "myAssets.zip";
pulpcore_scene = "PulpyDemo";
pulpcore_splash = "splash.gif";
//-->
</script>
<br />
<script type="text/javascript" src="pulpcore.js"></script>
<br />
<noscript>
<p>To play, enable JavaScript from the Options or Preferences menu.</
p>
</noscript>
</div>
<div id="source">
<center>
Created with <a href="http://www.interactivepulp.com/
pulpcore/">PulpCore</a>
</center>
</div>
</body>
</html>
Link to working copy of applet: http://www.adelphi.edu/~stemkoski/pulpcore/index.html Link to online version of this tutorial (includes applet): http://www.adelphi.edu/~stemkoski/pulpcore/index-tutorial.html |