Hashasm

melon js 4.0

Recommended Posts

The syntax's given in the documentation  is different from what is there in melonjs 4 version.

For Example:-

syntax givin for pointer function is 


// onActivate function
 onActivateEvent: function () {
    // register on the 'pointerdown' event
    me.input.registerPointerEvent('pointerdown', this, this.pointerDown.bind(this));
 },

 // pointerDown event callback
 pointerDown: function (event) {
   // do something
   ....
   // don"t propagate the event to other objects
   return false;
 }

but this syntax is not working with my ver 4.0..

 

 

 

Share this post


Link to post
Share on other sites

onActivateEvent: function () {
        //register on mouse/touch event
        me.input.registerPointerEvent("pointerdown", this, this.onSelect.bind(this));
       
    },

Note:-"i am working on isomatric tiled map  where i am building game like sim city "

 

its throwing error:

TypeError: this.onSelect is undefined[Learn More]

 

request :- "Please can any one can suggest me one good tutorial which has all pointer functions,HUD for clone-and-drag menu ,zooming functions "

Thanks in advance

Share this post


Link to post
Share on other sites

We will probably need to see the full class definition you created. The error console is telling you that you don't have an onSelect method on the class. Your original snippet is practical; the method you are binding exists. But you did not describe any errors for that code.

Share this post


Link to post
Share on other sites

game.PlayerEntity = me.Entity.extend({
    
    
    

    /**
     * constructor
     */
    init:function (x, y, settings) {
        .....some code is here for player
        
        
        
    },

here i am registring now no errors but on pointerdown nothing is showing

     // onActivate function
 onActivateEvent: function () {
    // register on the 'pointerdown' event
    me.input.registerPointerEvent('pointerdown', this, this.pointerDown.bind(this));
 },

 // pointerDown event callback
 pointerDown: function (event) {
   if (me.levelDirector.getCurrentLevelId()) {
                var layer = me.game.world.getChildByName("bottom")[0];
                var tile = layer.getTile(event.gameWorldX, event.gameWorldY);
               
                if (tile) {
                   
                    console.log( tile.col + "," + tile.row)
                }
                else{
                    
                    console.log("not a tile");
                }
            }
   return false;
 }
,

    /**
     * update the entity
     */
    update : function (dt) {
        
       .....code for key board functions
    },

   /**
     * colision handler
     * (called when colliding with other objects)
     */
    onCollision : function (response, other) {
        // Make all other objects solid
        return true;
    }

    
    
   
});

Share this post


Link to post
Share on other sites

Thank you taking time to solve my problems we creating a game like sim city I would be needing your help guys ...thank you so much for replying me.

i found melon is good to start with my game carrier :)

Share this post


Link to post
Share on other sites

i am trying to get position of each tile

me.levelDirector.getCurrentLevelId()  it wont return 0;

beacuse:-

    // onActivate function
 onActivateEvent: function () {
    // register on the 'pointerdown' event
    me.input.registerPointerEvent('pointerdown', this, this.pointerDown.bind(this));
 },

 // pointerDown event callback
 pointerDown: function (event) {
   console.log("hai");
   return true;
 },

 

now i am just consoling hai still not working..

Share this post


Link to post
Share on other sites

@obiot shapes eample is working after updating js file.

but i am not getting the pointer position .....by using that syntax from documentation.

 

hey now i fiund some solution  but totally different syntax can anyone explain me this

this is the code

 

me.input.registerPointerEvent("pointerdown", me.game.viewport, function (event) {
            me.event.publish("pointerdown", [ event ]);
        },false);

....

  this.pointerDown = me.event.subscribe("pointerdown", function (event) {
            
            if (me.levelDirector.getCurrentLevelId()) {
                var layer = me.game.world.getChildByName("bottom")[0];
                var tile = layer.getTile(event.gameWorldX, event.gameWorldY);
               
                if (tile) {
                   
                    console.log( tile.col + "," + tile.row)
                }
                else{
                    
                    console.log("not a tile");
                }
            }
            
        });

 

its working fine now i 

Share this post


Link to post
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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.