Wednesday, September 14, 2022
HomeGame DevelopmentLearn how to change the processing order Node Occasion System? - Cocos...

Learn how to change the processing order Node Occasion System? – Cocos Creator


I’ve 3 sprites, with the assistance of a script I alter the rendering order and drag the sprites one on high of the opposite in reverse order.
The sprite that was on the backside is obtained from above. However while you click on on this stack once more, it’s not potential to take the highest sprite.
Please inform me how can I resolve this drawback. I didn’t discover a resolution on the discussion board.

import { _decorator, Element, Node, enter, Enter, Occasion, Vec2, Label, KeyCode, EventMouse, EventTarget} from ‘cc’;
import{GameManager} from “./GameManager”;
const { ccclass, property } = _decorator;

@ccclass(‘TouchDragger’)
export class TouchDragger extends Element {

onLoad() {
  
    this.node.on(Node.EventType.TOUCH_START, (occasion) => { 
    console.log('Contact begin');
    
    occasion.propagationStopped = true;
    
    this.node.setSiblingIndex(2);

    }, this);

    this.node.on(Node.EventType.TOUCH_MOVE, (occasion) => { 
      
    this.node.setPosition(this.node.getPosition().x + occasion.contact.getDelta().x , this.node.getPosition().y + occasion.contact.getDelta().y, 0);
   
    }, this);

    this.node.on(Node.EventType.TOUCH_END, (occasion) => { 
    console.log('Contact finish');

    occasion.propagationStopped = false;
    }, this);

}


It needs to be like a card sport the place the deck is shuffled and the topmost card may be dragged.

Which model is used? Are you able to present a easy demo? Each node is registered for occasions?

Model 3.6. I connect the offered script to every of the three nodes. To this point that is an experiment with three sprites. I created nodes each within the editor and denamically within the script,
however the outcome is similar – this.node.setSiblingIndex(2) modifications the rendering order, however doesn’t keep in mind the occasion processing order, and while you click on on the visually high sprite once more, the outdated node processing order is preserved.

Nodes/sprites are brothers. Tried making them youngsters of the Canvas or youngsters of the kid node of the Canvas, the outcome is similar. In earlier variations of the engine – goal.setLocalZOrder(1) – solved the issue.

I’ll be thankful for any assist!

occasion.propagationStopped = true;occasion.preventSwallow = true;
Possibly you want this

I exploit this in a script, doesn’t resolve the issue!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments