Loading...
Logo
Processing Forum
I'd like to run through my pool on every frame and effect individual items at different times. I see there's an "HIterator" class, but I can't find any documentation on it.

Replies(10)

I had not heard of Hype before so I had a look and there is virtually no documentation :-(

As far as I can see the the following code should work - it assumes your HDrawablePool object is called pool

Copy code
  1. HIterator<HDrawable> iter = pool.iterator;
  2. HDrawable drawable;
  3. while(iter.hasNext()){
  4.     drawable = iter.next();
  5.     // do what you like with drawable but if
  6.     // you want to remove it from the pool use
  7.     // iter.remove();
  8. }

Awesome! Thanks. Was that in one of the examples on the website?
No I didn't look at the website but the iterator pattern is fairly standard in Java collections so I just looked at the code for HDrawablePool to see if they had done the same, I suspected they had because you mentioned the HIterator class. Once I found the iterator() method creating the code was straight forward because I am used to working with Java Collections.

The trick is to look for the iterator() method, if the class has one then the pattern of code I posted should work.
BTW in my original replace line 1 with this -

Copy code
  1. HIterator<HDrawable> iter = pool.iterator();

The creators  provide these classes as both .pde and .java files and this will work with both but my first post only works with .pde version. If you ever want to use the .java then at least that is one change you won't have to make.
It doesn't actually, it has 3 methods- hasNext(), next(), and remove()

Tried running this code but it tells me "the local variable iter has not been initialized"

Copy code
  1. HIterator<HShape> iter;

  2. while(iter.hasNext()){
  3.   HShape shape = iter.next();
  4.   shape.stroke(#FF0000);
  5. }
I believe that you're probably familiarized w/ object instantiations, am I right?
Any non-primitive variable needs to get a reference from an object before start using any methods from it.

It means as long as variable iter got no reference from a HIterator object,
none of its methods or fields can be used. Like hasNext() or next() for example.

Seems like you gotta grab that reference from some method of a HShape or HDrawable object though.
Look up for it in that library documentation.
Oh nice, I learned something! Haha... well I got it to instantiate properly- actually I noticed afterward that quarks had actually fixed the code but I didn't see it.

So I can iterate through the pool but when I run the remove() function nothing happens. I mean the iterator removes the instance from itself, but somehow it still gets drawn to the screen. I give up! All I'm using the framework for is a simple grid layout, I think I'll just make my own until someone actually makes some documentation for HYPE.

Thanks for the help guys :)
FYI You never instantiate an iterator object yourself. An iterator object is always created to work with a particular collection - it will not work another collection, even if it is the same type so assuming  HDrawablePool object is called pool then
 
HIterator<HDrawable> iter = pool.iterator();

The iterator() method will instantiate and return the iterator object. This iterator object will only work with the pool object.

Looking at the code the iter.remove() should remove an HDrawable object from pool I don't know why it didn't work for you.

I know! And I ran a simple check (incrementing a variable i and printing it out). The objects are no longer in the pool and yet, they remain on screen. I think there might be one final step to update the actual Pool, but without any documentation I can't figure it out. Anyway like I said it's just a grid layout, I've already finished making my own
You might try the size method to confirm the deletion i.e.

print("Was " + pool.size());
iter.remove();
println("  now is " + pool.size());