1
Posted by Eduardo Brito
on
16:33
Galera, vcs que acompanham meu blog, me descupem por ficar tanto tempo se postar tutoriais, eu estou meio sem tempo , mas aguarde que virão mais, obrigado pela compreenção.
var circ1:MovieClip=new MovieClip();
circ1.x=275;
circ1.y=200;
addChild(circ1);
var circle1r:uint=new uint(20);
circ1.graphics.beginFill(0xFF0000);
circ1.graphics.drawEllipse(-circle1r,-circle1r,circle1r*2,circle1r*2);
circ1.alpha=.5;
até a próxima! fonte: http://boxmonster.890m.com/wordpress/?m=200811
package {
//importando as linhas para o stage
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.geom.Point;
//definindo as variáveis
public class paint extends MovieClip {
var paintStage:BitmapData=new BitmapData(550,400,false,0xFFFFFF);
var paintDisplay:Bitmap=new Bitmap(paintStage);
var drawing:Boolean=new Boolean(false);
var vx:Number=new Number(2);
var vy:Number=new Number(2);
var len:uint=new uint;
var i:uint=new uint();
var p0:Point=new Point();
var p1:Point=new Point();
//ao clicar do mouse...
public function paint() {
addChild(paintDisplay);
stage.addEventListener(MouseEvent.MOUSE_DOWN,md);
stage.addEventListener(MouseEvent.MOUSE_UP,mu);
stage.addEventListener(MouseEvent.MOUSE_MOVE,mm);
}
function md(event:MouseEvent) {
drawing=true;
p0.x=event.stageX;
p0.y=event.stageY;
p1.x=p0.x;
p1.y=p0.y;
}
function mu(event:MouseEvent) {
drawing=false;
}
//tamanho da linha, e cor
function mm(event:MouseEvent) {
if (drawing) {
p1.x=event.stageX;
p1.y=event.stageY;
paintStage.setPixel(event.stageX,event.stageY,0x000000);
vx=p1.x-p0.x;
vy=p1.y-p0.y;
len=Math.sqrt(vx*vx+vy*vy);
vx/=len;
vy/=len;
for (i=0; ipaintStage.setPixel(p0.x+(vx*i),p0.y+(vy*i),0x000000);
}
p0.x=p1.x;
p0.y=p1.y;
}
}
}
}
var leftDown:Boolean = false;
var upDown:Boolean = false;
var rightDown:Boolean = false;
var downDown:Boolean = false;
//isso é a velocidade dp personagem
var mainSpeed:int = 5;
//adicionando movimentos ao caracte.
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
function moveChar(event:Event):void{
//checandose está se movendo
if(leftDown){
mcMain.x -= mainSpeed;
}
if(upDown){
mcMain.y -= mainSpeed;
}
if(rightDown){
mcMain.x += mainSpeed;
}
if(downDown){
mcMain.y += mainSpeed;
}
if(mcMain.x <= 0){
mcMain.x += mainSpeed;
}
if(mcMain.y <= 0){
mcMain.y += mainSpeed;
}
if(mcMain.x >= stage.stageWidth - mcMain.width){
mcMain.x -= mainSpeed;
}
if(mcMain.y >= stage.stageHeight - mcMain.height){
mcMain.y -= mainSpeed;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void{
if(event.keyCode == 37 || event.keyCode == 65){
leftDown = true;
}
if(event.keyCode == 38 || event.keyCode == 87){
upDown = true;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightDown = true;
}
if(event.keyCode == 40 || event.keyCode == 83){
downDown = true;
}
}
//botões sendo apertados
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void{
if(event.keyCode == 37 || event.keyCode == 65){
leftDown = false;
}
if(event.keyCode == 38 || event.keyCode == 87){
upDown = false;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightDown = false;
}
if(event.keyCode == 40 || event.keyCode == 83){
downDown = false;
}
}
//These variables will note which keys are down
//We don't need the up or down key just yet
//but we will later
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
//the main character's speed
var mainSpeed:Number = 7;
//whether or not the main guy is jumping
var mainJumping:Boolean = false;
//how quickly should the jump start off
var jumpSpeedLimit:int = 15;
//the current speed of the jump;
var jumpSpeed:Number = 0;
//adding a listener to mcMain which will make it move
//based on the key strokes that are down
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
function moveChar(event:Event):void{
//if certain keys are down then move the character
if(leftKeyDown){
mcMain.x -= mainSpeed;
}
if(rightKeyDown){
mcMain.x += mainSpeed;
}
if(upKeyDown || mainJumping){
mainJump();
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void{
//making the booleans true based on the keycode
//WASD Keys or arrow keys
if(event.keyCode == 37 || event.keyCode == 65){
leftKeyDown = true;
}
if(event.keyCode == 38 || event.keyCode == 87){
upKeyDown = true;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightKeyDown = true;
}
if(event.keyCode == 40 || event.keyCode == 83){
downKeyDown = true;
}
}
//this listener will listen for keys being released
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void{
//making the booleans false based on the keycode
if(event.keyCode == 37 || event.keyCode == 65){
leftKeyDown = false;
}
if(event.keyCode == 38 || event.keyCode == 87){
upKeyDown = false;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightKeyDown = false;
}
if(event.keyCode == 40 || event.keyCode == 83){
downKeyDown = false;
}
}
//jumping function
function mainJump():void{
//if main isn't already jumping
if(!mainJumping){
//then start jumping
mainJumping = true;
jumpSpeed = jumpSpeedLimit*-1;
mcMain.y += jumpSpeed;
} else {
//then continue jumping if already in the air
//crazy math that I won't explain
if(jumpSpeed < 0){
jumpSpeed *= 1 - jumpSpeedLimit/75;
if(jumpSpeed > -jumpSpeedLimit/5){
jumpSpeed *= -1;
}
}
if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
jumpSpeed *= 1 + jumpSpeedLimit/50;
}
mcMain.y += jumpSpeed;
//if main hits the floor, then stop jumping
//of course, we'll change this once we create the level
if(mcMain.y >= stage.stageHeight - mcMain.height){
mainJumping = false;
mcMain.y = stage.stageHeight - mcMain.height;
}
}
}
//jumping function
function mainJump():void{
//if main isn't already jumping
if(!mainJumping){
//then start jumping
mainJumping = true;
jumpSpeed = jumpSpeedLimit*-1;
mcMain.y += jumpSpeed;
} else {
//then continue jumping if already in the air
//crazy math that I won't explain
if(jumpSpeed < 0){
jumpSpeed *= 1 - jumpSpeedLimit/75;
if(jumpSpeed > -jumpSpeedLimit/5){
jumpSpeed *= -1;
}
}
if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
jumpSpeed *= 1 + jumpSpeedLimit/50;
}
mcMain.y += jumpSpeed;
//if main hits the floor, then stop jumping
//of course, we'll change this once we create the level
if(mcMain.y >= stage.stageHeight - mcMain.height){
mainJumping = false;
mcMain.y = stage.stageHeight - mcMain.height;
}
}
}
Mouse.hide();
delay=10;
_root.attachMovie("mousep","mousep",_root.getNextHighestDepth());
_root.attachMovie("mochithing","mochithing",_root.getNextHighestDepth());
mousep.onEnterFrame = function() {
this._x = _root._xmouse;
this._y = _root._ymouse;
};
mochithing.onEnterFrame = function() {
dist_x = mousep._x-this._x;
dist_y = mousep._y-this._y;
distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
angle = Math.atan2(dist_y, dist_x);
speed = distance/delay;
xspeed = speed*Math.cos(angle);
yspeed = speed*Math.sin(angle);
this._x += xspeed;
this._y += yspeed;
this._rotation = angle*180/Math.PI
};
//http://www.emanueleferonato.com
_root.attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:50, _y:50});
_root.attachMovie("wall", "wall", _root.getNextHighestDepth(), {_x:240, _y:200});
_root.attachMovie("arrow", "arrow", _root.getNextHighestDepth());
moving = false;
gravity = 0.01;
xspeed = 0;
yspeed = 0;
precision = 24;
radius = 15;
Mouse.hide();
arrow.onEnterFrame = function() {
this._x = _xmouse;
this._y = _ymouse;
dist_x = ball._x-this._x;
dist_y = ball._y-this._y;
total_dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (total_dist>300) {
total_dist = 300;
}
total_dist = (300-total_dist)/500;
angle = Math.atan2(dist_y, dist_x);
this._rotation = angle*57.2957795;
};
ball.onEnterFrame = function() {
if (moving) {
dir = arrow._rotation;
xspeed += total_dist*Math.cos(dir*0.0174532925);
yspeed += total_dist*Math.sin(dir*0.0174532925);
}
yspeed += gravity;
this._x += xspeed;
this._y += yspeed;
xspeed *= 0.99;
yspeed *= 0.99;
for (x=1; xspot_x = this._x+radius*Math.sin(x*360/precision*0.0174532925);
spot_y = this._y-radius*Math.cos(x*360/precision*0.0174532925);
if (wall.hitTest(spot_x, spot_y, true)) {
xspeed = 0;
yspeed = 0;
this._x = 50;
this._y = 50;
}
}
};
_root.onMouseDown = function() {
moving = true;
};
_root.onMouseUp = function() {
moving = false;
};
08. aguardem a parte 2 que é a criação do muro mas por enquanto já da pra se divertir com ele!
Até a próxima!
fonte: http://www.emanueleferonato.com
//dedinindo uma nova vareável que será o circulo
var newCircle:Shape = new Shape();
//Agora damos cor à o circulo
//eu escolhi a cor vermelha mas vc pode mudar
newCircle.graphics.beginFill(0xFF0000);
//agora darei nome ao circulo
//o primeiro valor (100) é o valor de x
// o segundo valor (100) é o valor de y
//e o valor(50), é o radio do circulo
//o x e o y são as medidas des de o centro do circulo
//Aqui o circulo fica do lado esquerdo da tela
newCircle.graphics.drawCircle(100,100,50);
//estamos quase terminando...
//usa a cor vermelha....
newCircle.graphics.endFill();
//e adiciona o circulo ao stage! Pronto!
addChild(newCircle);
Copyright © 2009 .:EBL Design:. All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive. Distribuído por Templates