DUVARLAR
Merhaba arkadaşlar;
Bu derste daha önceki derslerde anlattığım hittest komutunu biraz daha geliştirip duvar yapacağız.
Öncelikle 50 x 50 boyutunda bir top çizelim ve bunu MovieClip'e çevirip instance name'ine "top" yazalım ve daha sonra bu topu hareket ettirmemizi sağlayacak kodlar yazalım.
Topun kodları (frameye yazılacak) ;
hız = 6;
top.onEnterFrame = function(){
if(Key.isDown(Key.UP)){
top._y -= hız;
}
if(Key.isDown(Key.DOWN)){
top._y -= hız;
}
if(Key.isDown(Key.LEFT)){
top._y -= hız;
}
if(Key.isDown(Key.RIGHT)){
top._y -= hız;
}
}
Şimdi de bir duvar çizelim ve MovieClip'e çevirip adını "duvar" koyalım.Şimdi de frameye şu kodları ekleyelim ;
duvar.onEnterFrame = function (){
while(duvar.hitTest(top._x+25, top._y, true))
top._x -= hız;
}
while(duvar.hitTest(top._x-25, top._y, true))
top._x += hız;
}
while(duvar.hitTest(top._x, top._y+25, true))
top._y -= hız;
}
while(duvar.hitTest(top._x, top._y-25, true))
top._y += hız;
}
}
Eğer ben her şeyi doğru anlattıysam ve siz de beni doğru anladıysanız bu dersimiz burada bitmiştir.Başka bir derste görüşmek üzere... :D