PDA

View Full Version : تعریف یک آرایه از اشیا



مرد مباح
چهارشنبه 16 دی 1394, 17:36 عصر
با سلام خدمت شما دوستان،

من خیلی وقته برنامه نویسی میکنم ولی توی جاوا اسکریپت تازه کارم و لطفا منو راهنمایی کنید
توی زبانهای دیگه دیدم قابلیت مشابه وجود داشته و توی این زبان هم باید چنین چیزی باشه.

کد زیر رو لطفا نگاه کنید :
Kiwi.State.prototype.create.call(this);

this.table = new Kiwi.GameObjects.StaticImage(this, this.textures.table, 0, 0);
this.addChild(this.table);

var Sit =[]
for (i=1;i<10;i++) {
this.Sit[i] = new Kiwi.HUD.Widget.Button( this.game, 'Sit down', 10, 50+(4*i) );
this.game.huds.defaultHUD.addWidget( this.Sit[i] );
this.Sit[i].style.color = 'white';
this.Sit[i].style.fontSize = '1.2em';
this.Sit[i].style.padding = '0.1em 0.1em';
this.Sit[i].style.cursor = 'pointer';
this.Sit[i].style.backgroundColor = 'Green'

this.Sit[i].input.onOver.add( this.mouseOver1, this );
this.Sit[i].input.onOut.add( this.mouseOut1, this );
this.Sit[i].input.onDown.add( this.mouseDown1, this );
this.Sit[i].input.onUp.add( this.mouseUp1, this );
}


کیوی که در بالا اشاره شده، یک مجموعه دیگه هست که برای ساخت برنامه کمک میکنه.
هدف ساخت 9 دکمه زیر هم هست که بر اساس مدل آرایه ای نوشته شده.
ولی کار نمیکنه و نتونستم جایی تو نت مشابهش رو پیدا کنم.

تمام این فرمانها توی مدل غیر آرایه ای برای یک دکمه و یا چندتا از اونا جواب میده. ولی توی آرایه جواب نمیده.

اگر چنین قابلیتی تو برنامه وجود نداره هم لطفا بگین تا راه دستیش رو پیش برم

SCoder
جمعه 18 دی 1394, 02:47 صبح
این کار رو بکن ببین جواب میده ...




Kiwi.State.prototype.create.call(this);

this.table = new Kiwi.GameObjects.StaticImage(this, this.textures.table, 0, 0);
this.addChild(this.table);

this.Sit =[]
for (i=1;i<10;i++) {
(function(a){
this.Sit[a] = new Kiwi.HUD.Widget.Button( this.game, 'Sit down', 10, 50+(4*a) );
this.game.huds.defaultHUD.addWidget( this.Sit[a] );
this.Sit[a].style.color = 'white';
this.Sit[a].style.fontSize = '1.2em';
this.Sit[a].style.padding = '0.1em 0.1em';
this.Sit[a].style.cursor = 'pointer';
this.Sit[a].style.backgroundColor = 'Green'

this.Sit[a].input.onOver.add( this.mouseOver1, this );
this.Sit[a].input.onOut.add( this.mouseOut1, this );
this.Sit[a].input.onDown.add( this.mouseDown1, this );
this.Sit[a].input.onUp.add( this.mouseUp1, this );
})(i);
}