Hi, I don’t know why this happend and i would appreciate if someone can help me. Thats my code:
import static javax.swing.JOptionPane.*;
void settings() {
size((displayWidth/4)*2, (displayHeight/3)*2);
}
void setup() {
background (0);
//imagenMapa = loadImage("Imagenes/Mapa");
imagenPersonaje = loadImage ("Imagenes/Sprite");
}
void draw () {
background (0);
Protagonista.mostrar();
}
void keyPressed() {
final int k = keyCode;
if (k == 'w' | k == 'W' | k == UP ) {
Moverse = true;
Arriba = true;
Abajo = false;
Derecha = false;
Izquierda = false;
}
if (k == 's' | k == 'S' | k == DOWN ) {
Moverse = true;
Arriba = false;
Abajo = true;
Derecha = false;
Izquierda = false;
}
if (k == 'a' | k == 'A' | k == LEFT ) {
Moverse = true;
Arriba = false;
Abajo = false;
Derecha = false;
Izquierda = true;
}
if (k == 'd' | k == 'D' | k == RIGHT ) {
Moverse = true;
Arriba = false;
Abajo = false;
Derecha = true;
Izquierda = false;
}
}
void keyReleased() {
if (Arriba == true) {
Protagonista.RecorteX = Protagonista.RecorteIY + Ventana.Anchura;
Protagonista.RecorteY = Protagonista.RecorteIY + (3*Ventana.Altura);
}
if (Abajo == true) {
Protagonista.RecorteX = Protagonista.RecorteIX + Ventana.Anchura;
Protagonista.RecorteY = Protagonista.RecorteIY;
}
if (Izquierda == true) {
Protagonista.RecorteX = Protagonista.RecorteIX + Ventana.Anchura;
Protagonista.RecorteY = Protagonista.RecorteIY + Ventana.Altura;
}
if (Derecha == true) {
Protagonista.RecorteX = Protagonista.RecorteIX + Ventana.Anchura;
Protagonista.RecorteY = Protagonista.RecorteIY + (2*Ventana.Altura);
}
Moverse = false;
Arriba = false;
Abajo = false;
Derecha = false;
Izquierda = false;
}
class Pantalla{
int [] PosicionX = new int [16];
int [] PosicionY = new int [12];
int Anchura;
int Altura;
Pantalla (){
for (int j=0; j<16; j++){
this.PosicionY [j] = (height/12)*j;
for (int i=0; i<12; i++){
this.PosicionX [i] = (width/16)*i;}}
this.Anchura = width/16;
this.Altura = height/12;
}
}
class CharaMove{
int PosicionX;
int PosicionY;
int RecorteIX;
int RecorteIY;
int RecorteX;
int RecorteY;
CharaMove (int x, int y, int rix, int riy){
this.PosicionX = x;
this.PosicionY = y;
this.RecorteIX = rix;
this.RecorteIY = riy;
this.RecorteX = RecorteIX + Ventana.Anchura;
this.RecorteY = RecorteIY;
}
void mostrar(){
mover();
copy(imagenPersonaje, this.RecorteX, this.RecorteY, 32, 32, this.PosicionX, this.PosicionY, Ventana.Anchura, Ventana.Altura);
}
void mover(){
if (Moverse == true){
if(Arriba == true){
this.PosicionY = this.PosicionY - Ventana.Altura;
this.RecorteY = RecorteIY + (3*Ventana.Altura);
if (Pie == false){
this.RecorteX = this.RecorteIX;
Pie = true;
}
if (Pie == true){
this.RecorteX = this.RecorteIX + (2*Ventana.Anchura);
}
}
if(Abajo == true){
this.PosicionY = this.PosicionY + Ventana.Altura;
this.RecorteY = RecorteIY;
if (Pie == false){
this.RecorteX = this.RecorteIX;
Pie = true;
}
if (Pie == true){
this.RecorteX = this.RecorteIX + (2*Ventana.Anchura);
}
}
if(Izquierda == true){
this.PosicionX = this.PosicionX - Ventana.Anchura;
this.RecorteY = RecorteIY + Ventana.Altura;
if (Pie == false){
this.RecorteX = this.RecorteIX;
Pie = true;
}
if (Pie == true){
this.RecorteX = this.RecorteIX + (2*Ventana.Anchura);
}
}
if(Derecha == true){
this.PosicionX = this.PosicionX + Ventana.Anchura;
this.RecorteY = RecorteIY + (2*Ventana.Altura);
if (Pie == false){
this.RecorteX = this.RecorteIX;
Pie = true;
}
if (Pie == true){
this.RecorteX = this.RecorteIX + (2*Ventana.Anchura);
}
}
}
}
}
//Protagonista
CharaMove Protagonista;{
this.Protagonista.PosicionX = 0;
this.Protagonista.PosicionY = 0;
this.Protagonista.RecorteIX = 96;
this.Protagonista.RecorteIY = 0;
}
PImage imagenPersonaje;
//PImage imagenMapa;
float [] pantallaX= new float [16];
float [] pantallaY= new float [12];
boolean Moverse = false, Arriba = false, Abajo = false, Izquierda = false, Derecha = false, Pie= false;
Pantalla Ventana;
And I get this:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at processing.core.PApplet.runSketch(PApplet.java:10741)
at processing.core.PApplet.main(PApplet.java:10511)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at processing.core.PApplet.runSketch(PApplet.java:10735)
... 1 more
Caused by: java.lang.NullPointerException
at BaseJuegoRol_Setup.<init>(BaseJuegoRol_Setup.java:212)
... 6 more```