Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
//PIXI CLASSIC INITIALISE
var app = new PIXI.Application(800, 600, {backgroundColor : 0x1099bb});
document.body.appendChild(app.view);
var container = new PIXI.Container();
container._cases = []; // store list case
app.stage.addChild(container);
// Create cases, when mouse will hover case, try make inteligent easing focus
for (var i = 0; i < 25; i++) {
    var cases = new PIXI.Sprite(PIXI.Texture.WHITE);
    cases.width = 60, cases.height = 60;
    cases.anchor.set(0.5);
    cases.x = (i % 5) * 120;
    cases.y = Math.floor(i / 5) * 120;
    container._cases.push(cases);
    container.addChild(cases);
    cases.reelBounds = cases.getBounds().clone();
};
// Center on the screen
container.x = (app.screen.width - container.width) / 2;
container.y = (app.screen.height - container.height) / 2;
 // pointlockerAPI
document.body.onclick = function(){ document.body.requestPointerLock() };

// ┌-----------------------------------------------------------------------------┐
// GLOBAL $mouse CLASS: _mouse
// the mouse icon with pointer api
//└------------------------------------------------------------------------------┘

function _mouse() {
    PIXI.Container.call(this);
};
_mouse.prototype = Object.create(PIXI.Container.prototype);
_mouse.prototype.constructor = _mouse;

//$mouse.initialize();
_mouse.prototype.initialize = function() {
  this.x = 0;
  this.y = 0;
  this.moved = false;
  this.follower = new PIXI.Point(0,0);
  this.locked = false;
  this.ease = 0.3;
  
  
    this.icon = null; // pointerLock sprite
    this.sensiX = this.sensiY = 0.8; // mouse sensibility
    this.dirH = this.dirV = 0; // direction hori, vert (4,6,2,8) base 10
    this.mouseIsDown = false; // mouse is down indicator
    // check if started path selector
    this.tweenLastCase = null;
    this.startedPathCase = null;
    // easing mouse 
    this.tween = new TweenLite(this.position, 0, {
        x:0, y:0,
        ease:Power4.easeOut,
    });
    this.createSpriteMouse();
};

//$mouse.createSpriteMouse();
_mouse.prototype.createSpriteMouse = function() {
    const icon = new PIXI.Sprite(PIXI.Texture.WHITE);
    icon.tint = 0xa627d8;
    icon.width = 10, icon.height = 10;
    icon.anchor.set(0.5);
    this.icon = icon;
    this.addChild(icon);
 };

// add mouse to stage scene
var $mouse = new _mouse();
$mouse.initialize();
container.addChild($mouse);

// ┌-----------------------------------------------------------------------------┐
// DOCUMENT LISTENER METHOD:
// mousemove : 
//└------------------------------------------------------------------------------┘
// mouse method from listener update
_mouse.prototype.mousemove = function(event){
    // determine the direction
    this.dirH = event.movementX>0 && 6 || event.movementX<0 && 4 || 0;
    this.dirV = event.movementY>0 && 2 || event.movementY<0 && 8 || 0;
    this.x+=(event.movementX*this.sensiX);
    this.y+=(event.movementY*this.sensiY);

    // check cases
   const inCase = this.checkInCase(this.x, this.y);
  if(inCase){
       this.locked = true;
        this.ease = 0.3;
   };
  // here the trick, help mouse move on the cases.
  if(inCase && this.tweenLastCase !== inCase){
    this.tweenLastCase = inCase;
    this.moveToCase(inCase,0.5); // help the mouse to focus on the case
  }
};

document.addEventListener('mousemove', $mouse.mousemove.bind($mouse));


// ┌-----------------------------------------------------------------------------┐
// METHOD INTERACTION 
//└------------------------------------------------------------------------------┘

//$mouse.checkInCase();
_mouse.prototype.checkInCase = function(x,y) {
    let value = false;
    for (let i = 0, l = container._cases.length; i < l; i++) {
        const c = container._cases[i];
        if(c.reelBounds.contains(x,y)){
            c.tint = 0xf4d742;
            value = c;
            c.alpha = 1;
        }else{
            c.alpha = 0.5;
            c.tint = 0xffffff;
        };
    };
    return value;
};

//$mouse.moveToCase();
_mouse.prototype.moveToCase = function(inCase, speed, ease) {
  //const p =  inCase.getGlobalPosition();
  const p =  inCase.position;
  console.log(this.locked)
  const target = new PIXI.Point(this.x,this.y);
  if (this.locked) {
    target.x = 100 + this.x; // 100 will be center of your target
    target.y = 100 + this.y;
  }
  this.follower.x += (target.x - this.follower.x) * this.ease;
  this.follower.y += (target.y - this.follower.y) * this.ease;
  console.log(this.follower.x);
  this.tween.vars.x = this.follower.x;
  this.tween.vars.y = this.follower.y;
  speed && (this.tween._duration = speed);
  this.tween.invalidate();
  this.tween.play(0);
};

              
            
!
999px

Console