Jump to content

Making an object clickable outside of the class.


Recommended Posts

Basically I have a card

export default class Card {
	constructor(scene,x, y, sprite, text, player) {
		this.render = () => {
			let card = scene.add.image(x,y,sprite).setScale(0.2,0.2).setInteractive();
			let cardText = scene.add.text(x- 75, y - 100,text).setFontSize(17).setColor('#000000').setInteractive();
			card.on('pointerover', function () {
				card.y = card.y - 50;
				cardText.y = cardText.y - 50;
			card.on('pointerout', function()  {
				card.y = card.y + 50;
				cardText.y = cardText.y + 50;
			card.on('pointerdown', function() {
			return card;
		this.getPlayer = () => {
			return player;

and I then need to have functionality in my scene so that if it is clicked, I can call two methods in two classes, Player, and playZone, which aren't accessible by card.js. This will then move the card location and a few other things. I can't do the pointerdown in card.js as I need to be able to add the card object to the specific playZone.

Hopefully this makes sense! I'm new to Javascript and I am far more familiar with Java.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...