Jump to content

Search the Community

Showing results for tags 'overlap sprite'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hi This is my code var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'gamediv', { preload: preload, create: create, update: update });var sprite1;var sprite2;//yArray contains the 4 possible positions for a sprite//all must be used once and no more.var yArray = [50, 200, 350, 500];var y2Array = [50, 200, 350, 500];//var rand = reroll();ys1Array = Phaser.Math.shuffleArray(yArray);ys2Array = Phaser.Math.shuffleArray(y2Array);var leftSideSprites = [];var rightSideSprites = [];var leftSpriteArray = [];var rightSpriteArray = [];function preload() { game.load.image('teaspoon', 'teaspoon.png'); game.load.image('teacup', 'teacup.png'); game.load.image('shoes', 'shoes.png'); game.load.image('socks', 'sock.png'); game.load.image('television', 'television.png'); game.load.image('remote', 'remote.png'); game.load.image('hat', 'hat.png'); game.load.image('head', 'head.png');};function create() { leftSideSprites.push('teacup', 'shoes', 'television', 'head'); rightSideSprites.push('teaspoon', 'socks', 'remote', 'hat'); game.stage.backgroundColor = '#ffffff'; // Creating 8 sprites, randomly placing them and then assigning IDs to them. for (i = 0; i <= 3; i ++) { var spriteName = "sprite" + i; spriteName = game.add.sprite(50, ys1Array[i], leftSideSprites[i]); spriteName.id = i; game.physics.enable(spriteName, Phaser.Physics.ARCADE);// Enabling input of each sprite spriteName.inputEnabled = true; spriteName.input.enableDrag(); spriteName.events.onDragStart.add(startDrag, this); spriteName.events.onDragStop.add(stopDrag, this); leftSpriteArray.push(spriteName); } for (var i = 0; i <=3; i++) { var spriteName = "sprite" + i; spriteName = game.add.sprite(670, ys2Array[i], rightSideSprites[i]); spriteName.id = i; game.physics.enable(spriteName, Phaser.Physics.ARCADE); rightSpriteArray.push(spriteName); } console.log(leftSpriteArray[2]); console.log(rightSpriteArray[2].id);};function update() {};function overlapHandler (clickedSprite) { console.log("SUCCESS");}function startDrag(clickedSprite) { console.log('the id of the sprite I clicked = ' + clickedSprite.id); sprite1 = leftSpriteArray[clickedSprite.id]; sprite2 = rightSpriteArray[clickedSprite.id];}function stopDrag(clickedSprite) { game.physics.arcade.overlap(sprite1, sprite2, overlapHandler(clickedSprite) , null, this); }Basically the overlap handler is called any time I drag the sprite even though it doesn't collide with anything. Is there anyway for it to be called only when two specific sprites overlap.
×
×
  • Create New...