2016-04-12 12 views
-1
var xpos = 0; 
var ypos = 0; 
xpos = obj_magnet.x; 
ypos = obj_magnet.y; 
if (xpos > 435 && xpos < 704 && ypos > 350 && ypos < 640) 
{ 
    with(obj_lamp) 
    { 
     instance_change(obj_lamp_light, true); 
    } 
    if obj_lamp_light.image_index == 5 
    { 
     obj_lamp_light.image_speed = 0; 
    } 
    with(obj_arrow) 
    { 
     instance_change(obj_arrow_move_one_direction, true); 
    } 
    if obj_arrow_move_one_direction.image_index == 4 
    { 
     obj_arrow_move_one_direction.image_speed = 0; 
    } 
    with(obj_arrow_move_opposite_direction) 
    { 
     instance_change(obj_arrow, true); 
    } 
    exit; 
} 
else 
{ 
    with(obj_lamp_light) 
    { 
     instance_change(obj_lamp, true); 
    } 
    with(obj_arrow_move_one_direction) 
    { 
     instance_change(obj_arrow_move_opposite_direction, true); 
     if obj_arrow_move_opposite_direction.image_index == 4 
     { 
      obj_arrow_move_opposite_direction.image_speed = 0; 
     } 
    } 
    exit; 
} 

Bu, obj_arrow_move_opposite_direction ve obj_arrow_move_one_direction öğesinin 5 alt resim içerdiği ve obj_lamp_light'ın 5 alt resim içerdiği yerlerde yaratmaya çalıştığım bir oyundur.Birisi bu kodda neyin yanlış olduğunu görebilir mi?

+0

Tam olarak ne çalışmıyor? Herhangi bir hata var mı? Beklenen sonucu almıyor musunuz? –

cevap

0

Her nesnenin 5 alt resim içerdiğini belirttiniz, değil mi? 7 numaralı satırda varolmayan bir alt görüntü (5) aradığınız anlaşılıyor.

Bu, basit bir yazım hatası gibi görünüyor, ancak eğer değilse, image_index öğesinin 0'da başlayacağını belirtmek önemlidir. Bu nedenle, 5 resim 0 olur -4, 1-5 yerine.

var xpos=0; 
var ypos=0; 
xpos=obj_magnet.x; 
ypos=obj_magnet.y; 
if(xpos>435&&xpos<704&&ypos>350&&ypos<640) { with(obj_lamp){ 
instance_change(obj_lamp_light,true);} if 
obj_lamp_light.image_index==5{ obj_lamp_light.image_speed=0;} // should be object_lamp_light.image_index == 4 
with(obj_arrow){ 
instance_change(obj_arrow_move_one_direction,true);} 
if obj_arrow_move_one_direction.image_index==4{ 
obj_arrow_move_one_direction.image_speed=0;} 
with(obj_arrow_move_opposite_direction){ 
instance_change(obj_arrow,true);} 
exit; 
} 
else{ 
with(obj_lamp_light){ 
instance_change(obj_lamp,true);} 
with(obj_arrow_move_one_direction){ 
instance_change(obj_arrow_move_opposite_direction,true); 
if obj_arrow_move_opposite_direction.image_index==4{ 
obj_arrow_move_opposite_direction.image_speed=0;}} 
exit; 
} 

iyisi, nesnenin image_indexes sen IMAGE_NUMBER kullanmak ve birer çıkarma olabilir son alt görüntüye eşit olduğundan emin olmak için kontrol ediyoruz eğer. Böylelikle daha fazla alt resim eklerseniz, kodunuzun hala son kareyi kontrol ettiğini garanti edebilirsiniz.

İlgili konular