5 Replies Latest reply on Oct 9, 2010 6:03 AM by multiduck

    mouse interactivity

    mplelaba

      I'm working on a FPS project.

      A can't understand something about the mouse interactivity.I have a sample/test project....there is my test area.

      The mouse is interactive there and working properly.I copied the script to the FPS game and nothing happens when I press the left button.

      How this is possible???

      Please if anyone can help.....

       

      here is the code-->

       

       

      global world
      global pBox
      global pBox2
      global pGun
      global pCam
      property porigin

       

       

       

      on exitFrame me
        go to the frame
      end

       

      on BeginSprite
       
        pBox = world.model("Box01")
        pBox2 = world.model("Box02")
        pGun = world.model("Sphere01")
        pGun.visibility = #none
        pCam = world.camera[1]
       
       
        pGun.addChild(pCam, #preserveWorld)
       
          porigin = point(sprite(1).left,sprite(1).top)
       
      end

       

      on enterFrame
       
        movement
       
      on mouseDown
        ptklik = the mouseLoc - porigin --des p klikarw
        modelhit = sprite(1).camera.modelUnderLoc(ptklik) 
       
        if modelhit <> void then
          hit(modelhit)
        else
          hit(false)
        end if
      end

       

      on hit whichmodel
        if not whichmodel then  
        else
          case whichmodel.name of
            "Box01":
              pBox.rotate(0,0,20)
            "Box02":
              pBox2.rotate(-5,0,0)
          end case
        end if 
      end


      end

        • 1. Re: mouse interactivity
          multiduck Level 1

          The mouse events are probably stopped somewhere else in your project, search through your scripts for other instances of mouse events and use the pass command. Another source could be if the sprite isn't editable, if so it will ignore mouse clicks. There is also other reasons that might cause this that I can't recall right now, but I usually have mouse catching code in one of my main scripts that checks which sprite was clicked (clickOn) and routs the event to the correct sprite, useful if you for example have several sprites with mouse events that can block each other.

           

          Edit, in your code you have the end statement for the "on enterframe" last in your script instead of before the "on mouseDown", Director usually don't care about that, but it can't hurt to fix it.

          • 2. Re: mouse interactivity
            mplelaba Level 1

            Hi,thank u very much for your reply!

             

            I don't know how to use the pass command.I have one sprite in the game.the sprite(1).
            I can't give any explanation.In the test area the mouse click (active) only in the 2 sides of the stage(imagine the stage separated to 3 vertical pieces),in the middle nothing happens.

            is there any example with code ?

            • 3. Re: mouse interactivity
              multiduck Level 1

              If you don't have any other script in your project that uses the mousedown handler, you wont need to use the pass command.

               

              Try adding sprite(1).editable = true to your on beginsprite handler and see if it works.

               

              Edit: Btw It's better not to hard code sprite numbers in your scripts, if you move your sprite in the score, your movie will no longer work as it should. Try adding a property for the sprite number, for example:

               

              property pSpriteNum

               

              on beginsprite me

               

                 pSpriteNum = me.spritenum

               

                 sprite(pSpriteNum).editable = true

               

              end

               

              or even better store a referens to the sprite

               

              property pSprite

               

              on beginsprite me

               

                 pSprite = sprite(me.spriteNum)

               

                 pSprite.editable = true

               

              end

              • 4. Re: mouse interactivity
                mplelaba Level 1

                Thank u very much!

                I solved the problem!I had created an avatar(sphere) and I was moving with this model with the camera as a child from behind.

                The avatar was invisible,but it was in front of the view that's why I couldn't click on anynthing.

                I put the avatar a little bit up(z axis) end now is working!

                • 5. Re: mouse interactivity
                  multiduck Level 1

                  Ah, ok, so the sprite was reacting to clicks then.

                   

                  For you, instead of using modelunderloc you could use the simillar command modelSunderLoc which returns all models under the mouse, and then loop through the returnd list of models and search for your models. This way it doesn't matter if any other models are in the way

                   

                  replace your modelhit line with: (modefied from the example code in directors help section under modelsunderloc)

                  tModelList = [pBox, pBox2] -- only look for the box models
                  tOptionsList = [#levelOfDetail: #simple, #modelList: tModelList] -- #simple: we only need model references
                  modelhit  = sprite(1).camera.modelsUnderLoc( ptklik, tOptionsList)

                  and change your "on hit whichmodel" with this one

                  on hit whichmodel
                    if not whichmodel then  
                    else

                   

                      repeat with i = 1 to whichmodel.count


                        case whichmodel[i] of
                          pBox:
                            pBox.rotate(0,0,20)
                          pBox2:
                            pBox2.rotate(-5,0,0)
                        end case

                   

                      end repeat


                    end if 
                  end

                   

                  Note: Since I'm not at the time of writing this able to test this in director, the list returned from modelsunderloc might be structured differently than a simple list of model references, so you might need to modify the case statment a bit.