Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

CCMotionStreak not visible over a CCSprite #422

@Jbonavita

Description

@Jbonavita

I have a really simple game that, for now, uses CCMotionStreak to show a streak when I touch is moving.
I added a single layer to the scene and add the CCMotitionStreak to that layer. As the touch moves, the streak displays. This works perfect.
However, as soon as I add a background image, the streak no longer shows. The image is added before the layer so that shouldn't be an issue.

If I remove the background image, the streak displays fine.

I also tried setting the ZOrder = 1000 for the motion streak as well without luck.

    public override void OnEnter()
    {
        base.OnEnter();
        var backgroundLayer = new CCLayer();
        layer = new CCLayer();
        
        AddChild(backgroundLayer);
        AddChild(layer);
        
        layer.AddEventListener(new CCEventListenerTouchAllAtOnce { OnTouchesBegan = OnTouchesBegan,
            OnTouchesEnded = OnTouchesEnd,
            OnTouchesMoved = OnTouchesMoved});

        background = new CCSprite("background.png")
        {
            AnchorPoint = CCPoint.AnchorMiddle,
            Position = layer.BoundingBox.Center
        };

        backgroundLayer.AddChild(background);
    }

    private void CreateMotionStreak()
    {
        motionStreakNode = new CCMotionStreak(.8f, .1f, 30, CCColor3B.White, "streak.png")
        {
            AnchorPoint = CCPoint.AnchorMiddle
        };

        layer.AddChild(motionStreakNode);
    }

    private void OnTouchesMoved(List<CCTouch> touches, CCEvent arg2)
    {
        if (touches.Count > 0 && motionStreakNode != null)
            motionStreakNode.Position = touches[0].Location;
    }

    private void OnTouchesEnd(List<CCTouch> touches, CCEvent arg2)
    {
        if (touches.Count > 0)
        {
            motionStreakNode.RemoveFromParent();
        }
    }

    void OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent)
    {
        if (touches.Count > 0)
        {
            CreateMotionStreak();
            motionStreakNode.Position = touches[0].Location;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions