Skip to content
AM MAYA edited this page Jan 3, 2022 · 6 revisions

Following the first Tutorial, found in Etyllica/src/examples

First, you have to choose if your application is an Applet or Frame, here I will choose applet so My class will extends Etyllica. Etyllica class extends Applet, so our Tutorial1 class is an Applet too.

public class Tutorial1 extends Etyllica {

The serial is generated only to avoid warnings.

private static final long serialVersionUID = 1L;

The parameters passed on super method, are Width and Height, setting the size of your Application. Hint: The constructor can't have parameters.

public Tutorial1() {
	super(800, 600);
}

Start Game is called on Etyllica's initialization, the method setMainApplication is obrigatory, as parameter receive an Application Instance.

@Override
public Application startApplication() {
		
	//Etyllica tries to find the resources as your Application should be
	//To avoid this you should put your /assets/images in /YourProject/bin/examples/etyllica/tutorial1/
		
	//"Upping" three directories we have /YourProject/bin/assets/images
	String s = getClass().getResource("").toString();
	setPath(s+"../../../");
		
	return new HelloWorld(w,h);
}

The full code:

package examples.etyllica.tutorial1;

import br.com.etyllica.Etyllica;
import examples.etyllica.tutorial1.application.HelloWorld;

public class Tutorial1 extends Etyllica {

 	private static final long serialVersionUID = 1L;

 	public Tutorial1() {
 		super(800, 600);
 	}
	
	@Override
 	public Application startApplication() {
		
		//Etyllica tries to find the resources as your Application should be /assets/images
		//To avoid this you should put your resources in /Project/bin/examples/etyllica/tutorial1/
		
		//Upping three directories we have /Project/bin/assets/images
		String s = getClass().getResource("").toString();
		setPath(s+"../../../");
		
		return new HelloWorld(w,h);
 	}
	
}

Now we have to create a new class HelloWorld that extends Application

package examples.etyllica.tutorial01;

import br.com.etyllica.core.application.Application;
import br.com.etyllica.core.event.GUIEvent;
import br.com.etyllica.core.event.KeyEvent;
import br.com.etyllica.core.event.PointerEvent;
import br.com.etyllica.core.video.Graphic;
import br.com.etyllica.layer.ImageLayer;

public class HelloWorld extends Application{

	public HelloWorld(int w, int h) {
		super(w, h);
	}

        //Here I create a Layer to "hold" my image
	private ImageLayer hello;

	@Override
	public void load() {
		//Here I set the coordinates (x,y) and the image url
		hello = new ImageLayer(200,100,"hello.png");

 		loading = 100;
		
 	}

	@Override
	public void draw(Graphic g) {
                //Now, I'm just drawing the image
		hello.draw(g);		
	}	

}

//Upping three directories we have /Project/bin/res/images
String s = getClass().getResource("").toString();
setPath(s+"../../../");

setMainApplication(new HelloWorld(w,h));
Clone this wiki locally