A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How can I do something like this?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4

    How can I do something like this?

    Hey, this surely is a newbie question... but here it goes anyway:

    I'm trying to make a simple rpg game and I would like to add something like a pop-up text box for the dialog that shows when the character interact with the npcs/items
    (like on this game: http://www.mspaintadventures.com/?s=6&p=004692)
    but I can't figure out how to do it.
    I'm already using a text function that I learned on a tutorial but it isn't exactly what I wanted. I can't even open and close the text with the same key...

    PHP Code:
    onClipEvent (enterFrame) {
        
    distance 45;
        
    ux _root.char._x;
        
    uy _root.char._y;
        
    hx this._x;
        
    hy this._y;
        if(
    Math.sqrt((ux-hx)*(ux-hx)+(uy-hy)*(uy-hy))<distance && Key.isDown(Key.SPACE)) {
            
    _root.TextInstance.text "text goes here";
        } 
        if (
    Key.isDown(Key.SHIFT)) {
            
    _root.TextInstance.text "";
        }
        

    So I would really appreciate some help with this
    If someone could link me to a tutorial or whatever that could help it would be awesome

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hope this help.

    Create 2 movieclips, one for main character and the other for another character. Name the main character main and the other man.

    Create a dynamic textbox on stage and name it instance name statusTxt.

    Put this script on your first frame

    PHP Code:
    var xSpeed=4;
    var 
    ySpeed=4
    main
    .onEnterFrame=function(){
        
    radius=8;
          
    if(
    this.hitTest(man)){
        if(
    Key.isDown(Key.SPACE)){
           
    statusTxt.text="Save? Yes(Y)  No(N)";
        }
           if(
    statusTxt.text==""){
           }
           else {
           
            if(
    Key.isDown (89)){
             
    statusTxt.text="Saved Successfully.";
           }
          if(
    Key.isDown(78)){
              
    statusTxt.text="Remember saving your game later!";
           }
        
        }
    }
    else {
         
    statusTxt.text="";
    }

        if (
    Key.isDown(Key.DOWN) &&Key.isDown(Key.UP) ){
            
    this.ySpeed 0
            

        
    }
        else if (
    Key.isDown(Key.UP)){
            
    this.ySpeed = -5
            
            this
    .gotoAndStop("walking");
        }
        else if (
    Key.isDown(Key.DOWN)){
            
    this.ySpeed= +5
            
            this
    .gotoAndStop("walking");
        }
        
        else {
            
    this.ySpeed=0
        
    }
        
        if (
    Key.isDown(Key.LEFT) && Key.isDown(Key.RIGHT)){
        
    this.xSpeed 0
        
        
        
    }
        
        
        
        else if (
    Key.isDown(Key.RIGHT)){

                    
    this.xSpeed = +5
            this
    .gotoAndStop("walking");
        }
        
        else if (
    Key.isDown(Key.LEFT)){
            
            
    this.xSpeed = -5
            this
    .gotoAndStop("walking");
        }
        
            
        else {
            
            
    this.xSpeed =0
        
    }
        if (
    this.xSpeed ==&& this.ySpeed ==0){

        
    this.gotoAndStop("stand");
        
        }
        
        
        
    this._x += this.xSpeed;
        
    this._y += this.ySpeed;
        
        
        while (
    man.hitTest (this._xthis._y+radiustrue)){
    this._y--;
    this.gotoAndStop("stand");
    }
    while (
    man.hitTest (this._xthis._y-radiustrue)){
    this._y++;
    this.gotoAndStop("stand");
    }
    while (
    man.hitTest (this._x-radiusthis._ytrue)){
    this._x++;
    this.gotoAndStop("stand");
    }
    while (
    man.hitTest (this._x+radiusthis._ytrue)){
    this._x--;
    this.gotoAndStop("stand");
    }
        
        
        
    }; 
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Move the character with keyboard arrows, then when close to the man movieclip, hit SPACE aand then Y and N. I can add more things if you want, so it fits what you need.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center