How does one add multiple objects at random postions?

3 ビュー (過去 30 日間)
John
John 2012 年 12 月 7 日
So I'm trying to add a picture of a bear to a game I'm working on, and I figured out how to add one picture randomly, but I need more than one picture. What can I do to the following line to create more than just one bear, without copying and pasting this line over and over?
mge_add_object('name','bear1','type','obstacle','pos',
[randi(5),randi(5)],'vel',[0,-1],'size',
[1.5,1.5],'mass', 20,'image','grizzly-bear.jpg');

回答 (1 件)

Matt Fig
Matt Fig 2012 年 12 月 7 日
編集済み: Matt Fig 2012 年 12 月 7 日
Add 5 of them:
for ii = 1:5
mge_add_object('name','bear1','type','obstacle','pos',
[randi(5),randi(5)],'vel',[0,-1],'size',
[1.5,1.5],'mass', 20,'image','grizzly-bear.jpg');
end

カテゴリ

Help Center および File ExchangeVideo games についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by