We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Beginner: How can i get rid of a sprite thing
Page Index Toggle Pages: 1
Beginner: How can i get rid of a sprite thing? (Read 468 times)
Beginner: How can i get rid of a sprite thing?
Feb 2nd, 2008, 11:53am
 
hello there,

please excuse a stupid question..ive got some 3d primitives and sprites working yay and now i dont need them anymore and want to kill them. so i was thinking of setting them to nostroke/nofill or moving them out of screen...but i guess there are better options; maybe anyone could point me in the right direction please. thanks a lot in advance and
best wishes
Re: Beginner: How can i get rid of a sprite thing?
Reply #1 - Feb 2nd, 2008, 7:14pm
 
ludwig,

No worries, there's no such thing as a stupid question...
I'm not entirely sure on what you're trying to do, it's helpful for others if you post some of the code you're working with.

The simplest way is to draw the background() at the beginning of each draw-cycle, and then your primitives/sprites. If you don't draw anything the background remains blank.

Quote:


import processing.opengl.*;

float xrotate, yrotate;
float r = .05; // set rotation increments

void setup() {
 size(200,200,OPENGL);
 background(0);
 noFill();
 stroke(255,0,0); // red outline
}

void draw() {
 // "clean" the stage
 background(0);
 
 // only if the mouse is pressed the box is drawn
 if (mousePressed) {
   translate(width/2,height/2,0);
   rotateY(xrotate);
   rotateX(yrotate);
   box(80);
   
   // advance rotation
   xrotate += r;
   yrotate += r;  
 }
}




Does this help

cheers,
Greg
Re: Beginner: How can i get rid of a sprite thing?
Reply #2 - Feb 5th, 2008, 7:48pm
 
hi dek,

thank you very much for your time, and your answer has done the thing..i obviously havent understood the void draw; unfortunatley i dont have any code with me right now to post but what i was trying to do: think of a simple space shooter or breakout game where sprites and otherthings get hit and disappear. i thought they`re like objects and too many of them would cost resources, now i think i was wrong and ill try an if conditional to draw them only when i need them. Not much of a coder, yet:/ hope you understand..
best wishes
Re: Beginner: How can i get rid of a sprite thing?
Reply #3 - Feb 5th, 2008, 9:53pm
 
hey ludwig,

Depending on the complexity of your program, trying to manage the object/sprite visibility using conditionals might turn out to be a bit limiting. By all means, give it a shot, it's all about learning-by-doing.
Imagine the laser beams and targets being created, moved, collision checked, and destroyed. There's a whole lot of managing going on.

This might be a job for Object-Oriented Programming. Here you use classes to create objects which can be elegantly controlled and managed. You can create objects on the fly and destroy them whenever you want, just like in the way you had in mind.

Unfortunately, as powerful as OOP is, it can be intimidating to programming beginners, since it's a whole new concept to wrap your head around. There's no doubt, that you'll eventually encounter OOP in your programming life, but first you should have a solid understanding of the basics and move on when you see fit.

Hope I haven't confused you too much...

cheers.
Page Index Toggle Pages: 1