--
You received this message because you are subscribed to the Google Groups "PulpCore" group.
To post to this group, send email to pulp...@googlegroups.com.
To unsubscribe from this group, send email to pulpcore+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pulpcore?hl=en.
Hi David, thanks for your reply. I decided to go the subclass route
but am having some issues. My code is pretty simple, looks like this
(heavily based on ImageSprite):
public class MyImageSprite extends ImageSprite {
private int clipX,clipY,clipWidth,clipHeight;
public MyImageSprite(CoreImage image, int x, int y) {
super(image, x, y);
removeClip();
}
@Override
protected void drawSprite(CoreGraphics g) {
if (getImage() != null) {
g.setEdgeClamp(antiAlias.get() ? CoreGraphics.EDGE_CLAMP_NONE :
CoreGraphics.EDGE_CLAMP_ALL);
try {
g.drawImage(getImage(),clipX,clipY,clipWidth,clipHeight);
} catch (Exception e) {
return;
}
}
}
public void removeClip() {
setClip(0,0,getImage().getWidth(),getImage().getHeight());
}
public void setClip(int x,int y,int w,int h) {
clipX=x;
clipY=y;
clipWidth=w;
clipHeight=h;
}
}
When I do a simple test to create a sprite and set a clip at that
time, it works. But dynamically trying to change the clip-rect from
frame to frame, it seems to get 'stuck' the first frame.
I certainly can't rule out a dumb bug, but are there any obvious
things I've missed?
barSprite.setClip(0, 0,WIDTH, h);
barSprite.setAlpha((float)h/HEIGHT);
barSprite.setSize(WIDTH*((float)h/HEIGHT), HEIGHT);
barSprite.setDirty(true);
h changes each frame between 0 and HEIGHT (a constant). I see the
sprite getting scaled horizontally, AND fading in out... but the
clipping resolutely does nothing. In another part of my app, the same
thing works perfectly! It must be something silly but I'm tearing my
hair out trying to figure out what!
Looking at the source, the only way I can see this happening is in
Sprite.draw(): http://code.google.com/p/pulpcore/source/browse/src/pulpcore/sprite/Sprite.java?name=0.11#1029
Is that correct, or are there other ways the sprite can be redrawn
without drawSprite() getting called? With so many sprites in the scene
but only a couple MyImageSprites, I am struggling how to debug it more
deeply.
John.
But going back to the question - if the alpha is changing each frame
(which I can see is working), does that mean the sprite definitely is
having to be redrawn one way or the other? If that's the case, in what
way can this happen other than a call to drawSprite()? Or is Pulp able
to cache a render and vary the alpha without re-drawing?