bluck20 / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

When I create the CCSprice in a Thread and use MoveAction, sometime if show white sprice #121

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.I use Thread to create sprites and move its with Move Action
2. Sometime the sprites is show white blank not the image
3. I tried to use CCDirector.sharedDirector().purgeCachedData() is onDestroy 
but is not help so much!

What is the expected output? What do you see instead?
I just want all my sprites is show true images

What version of the product are you using? On what operating system?
the last version

Please provide any additional information below.
My Thread
public class ThreadThrow extends Thread {
        boolean pause;
        Screen screen;

        public ThreadThrow(Screen screen) {
            pause = false;
            this.screen = screen;
        }

        @Override
        public void run() {
            while (canThrow) {
                while (pause) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                CCSprite projectile = new CCSprite(playerProjectile);
                projectile.setScaleX(rateX);
                projectile.setScaleY(rateY);
                projectile.setPosition(CGPoint.ccp(winSize.getWidth() - 20, winSize.getHeight() / 2.0f));
                int offX = (int) (projectile.getPosition().x - location.x);
                int offY = (int) (-projectile.getPosition().y + location.y);
                if (offX <= 0)
                    this.stop();
                addChild(projectile);
                projectile.setTag(2);
                _projectiles.add(projectile);
                int realX = (int) ((-projectile.getContentSize().width / 2.0f));
                float ratio = (float) offY / (float) offX;
                int realY = (int) (((int) (winSize.width + (projectile.getContentSize().width / 2.0f)) * ratio) + projectile.getPosition().y);
                CGPoint realDest = CGPoint.ccp(realX, realY);
                int offRealX = (int) (-realX + projectile.getPosition().x);
                int offRealY = (int) (-realY + projectile.getPosition().y);
                float length = (float) Math.sqrt((offRealX * offRealX) + (offRealY * offRealY));
                float velocity = 500.0f / 1.0f; // 480 pixels / 1 sec
                float realMoveDuration = length / velocity;
                projectile.runAction(CCSequence.actions(CCMoveTo.action(realMoveDuration, realDest),
                        CCCallFuncN.action(screen, "spriteMoveFinished")));

                try {
                    sleep(delayTime);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        public void pause() {
            this.pause = true;
        }

        public void attack() {
            this.pause = false;
        }
    }

Original issue reported on code.google.com by tam.httam on 19 Mar 2012 at 3:45