Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Why isn't my text displaying?

$
0
0

Hello, I have written the following code and want to create a text ticker of the array.

The code runs okay, but no text is displayed. Can anyone see why?

Thank you

// import PeasyCam library
import peasy.*;
PeasyCam cam;

//set global variables
int rotateX = 0, rotateY = 0; // allow mouse to be moved when mouse is used or not used
int previousX, previousY;
float distanceX = 0.0, distanceY = 0.0;  //initial position
color gray = color(131, 131, 131);
PShape ball1, ball2, ball3, ball4, ball5, ball6, ball7, ball8, ball9, ball10;
PImage img, moon;

// array of instructions for text ticker
String[] instructions = {
  "hold the right mouse button and move the mouse up and down the y axis to zoom in or out",
  "hold the left mouse button and move the mouse in either direction to move around the spheres",
  "double-click the left button to re-set your interaction"
};

PFont font;
float x = width; //location of text ticker
int index = 0; // start reading from array
//

void setup() {
  size(1000, 1000, P3D);
  font = createFont("arial", 72, true);  // initiate font
  // load images in preparation for background image
  img = loadImage("nightsky.jpg");
  moon = loadImage("moon.jpg");
  noFill(); // keep spheres as wireframe
  // create 4 spheres of varying sizes (from 100px to 25px)
  stroke(gray);
  sphereDetail(100);
  ball9 = createShape(SPHERE, 6400);
  ball8 = createShape(SPHERE, 3200);
  ball7 = createShape(SPHERE, 1600);
  ball6 = createShape(SPHERE, 800);
  ball5 = createShape(SPHERE, 400);
  sphereDetail(15);
  ball4 = createShape(SPHERE, 200);
  ball3 = createShape(SPHERE, 100);
  ball2 = createShape(SPHERE, 50);
  noStroke();
  ball1 = createShape(SPHERE, 25);
  ball1.setTexture(moon);

  cam = new PeasyCam(this, 350); // set camera's initial position
  cam.setMinimumDistance(75);
  cam.setMaximumDistance(20000);
}

void draw() {
  // background in draw not setup so drawn on loop and new sphere replaces old

  background(img);
  rotateX (-0.5);
  rotateY(-0.5);
  lights();
  //stroke(0);
  shape(ball1);
  //shape(ball2);
  shape(ball3);
  shape(ball4);
  shape(ball5);
  shape(ball6);
  shape(ball7);
  shape(ball8);
  shape(ball9);
  translate(width/2, height/2, 300);

  textFont(font, 16);
  textAlign(LEFT);
  text(instructions[index], x, 180);

  // Decrement x
  x = x - 3;

  // initiate next item in array to be displayed if x is equal to the negative width
  float w = textWidth(instructions[index]);
  if (x < -w) {
    x = width;
    index = (index + 1) % instructions.length;
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles