Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1

    Actionscript per movimento 2d

    Ho creato questo actionscript per il movimento 2d di un omino

    onClipEvent (load) {
    velocita = 19;
    }
    onClipEvent (enterFrame) {
    if (Key.isDown (Key.RIGHT)) {
    this._x += velocita;
    } else if (Key.isDown (Key.LEFT)) {
    this._x -= velocita;
    }
    }


    e funziona...solo che mi chiedo...come posso fare a far si che il mio omino si giri quando premo un tasto con la direzione opposta a quella dell'omino?

    C'é un modo?Grazie

  2. #2

  3. #3
    questo script, on ricoedo dove lo avevo trovato, ma dovrebbe esserti utile.
    per vederlo funzionare clicca qui
    "CAR"

    da associare al mc che devi far muovere:

    codice:
    onClipEvent (enterFrame) {
    // When key UP is pressed, speed is increased
    if (Key.isDown(Key.UP)) {
    speed += 1;
    } else {
    // When key DOWN is pressed, speed is decreased
    if (Key.isDown(Key.DOWN)) {
    speed -= 1;
    } else {
    // If UP or DOWN aren't pressed then the speed decreases
    speed *= .9;
    }}
    // The car will start to slow down after the speed of 25
    if (Math.abs(speed)>25) {
    speed *= .6;
    }
    // Turns the car left
    if (Key.isDown(Key.LEFT)) {
    _rotation -= speed;
    }
    // Turns the car right
    if (Key.isDown(Key.RIGHT)) {
    _rotation += speed;
    }
    // Moves the car
    speed *= .9;
    x = Math.sin(_rotation*(Math.PI/180))*speed;
    y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
    if (!_root.move.hitTest(_x+x, _y+y, true)) {
    _x += x;
    _y += y;
    } else {
    speed *= -.3;
    }
    }
    -Nextart.it Graphic Solutions

  4. #4

  5. #5

  6. #6

  7. #7
    onClipEvent (load) {
    velocita = 19;
    }
    onClipEvent (enterFrame) {
    if (Key.isDown (Key.RIGHT)) {
    this._x += velocita;
    this._xscale = -100;
    } else if (Key.isDown (Key.LEFT)) {
    this._x -= velocita;
    this._xscale = 100;
    }
    }


    il valore di xscale sarà così come ho scritto oppure inverso, a seconda della posizione di "partenza" del tuo omino
    "...non è detto che sia tardi se non guardi che ora è..."

  8. #8
    Perfetto!Grazie mille!Avevo provato anche io con this.xscale...solo che facevo l'errore di mettere

    this.xscale += 100....quindi se premevo più di una volta lo stesso tasto mi si voltava lo stesso


    Grazie di cuore

    Ciao


  9. #9
    Scusa se rompo ancora...ma sono a digiuno di flash da circa 6 mesi

    Ho messo a posto l'actionscript che mi hai dato (grazie mille ancora ) in questo modo:


    codice:
    onClipEvent (load) {
    	velocita = 10;
    }
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.RIGHT)) {
    		this._x += velocita;
    		this._xscale = 100;
    		this.play();
    	} else if (Key.isDown(Key.LEFT)) {
    		this._x -= velocita;
    		this._xscale = -100;
    		this.play();
    	} else if (Key.isDown(Key.UP)) {
    		this._y -= velocita;
    		this.play();
    	} else if (Key.isDown(Key.DOWN)) {
    		this._y += velocita;
    		this.play();
    	} else {
    		this.stop;
    	}
    }



    e adesso in sostanza si muove su e giù per lo stage in modo perfetto...solo che quando smetto di premere destra o sinistra prima di stoppare l'animazione la finisce....io vorrei che finisse di botto...c'é un modo?

    Grazie

  10. #10
    prova ad aggiungere

    onClipEvent(keyUp){
    this.stop;
    }
    "...non è detto che sia tardi se non guardi che ora è..."

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.