プレイヤーをアイテムと衝突させるさまざまな方法を試しています。
Coin.each_bounding_circle_collision(@player) do |coin, player|
puts "coin collides with player"
end
Item.each_bounding_circle_collision(@player) do |item, player|
puts "item collides with player"
end
@player.each_bounding_circle_collision(Item) do |player, item|
puts "player collides with item"
end
@player.each_bounding_circle_collision(Coin) do |player, coin|
puts "player collides with coin"
end
これらのうち、ItemがCoinの親クラスであるにもかかわらず、最初と最後の1つ(つまり、Coinに対してチェックするもの)のみが機能します。
class Item < Chingu::GameObject
trait :timer
trait :velocity
trait :collision_detection
trait :bounding_circle, :scale => 0.8
attr_reader :score
def initialize(options = {})
super(options)
self.zorder = Z::Item
end
end
class Coin < Item
def setup
@animation = Chingu::Animation.new(:file => "media/coin.png", :delay => 100, :size => [14, 18])
@image = @animation.first
cache_bounding_circle
end
def update
@image = @animation.next
end
end
私はRuby全般についての知識が少ないため、なぜこれが機能しないのかわかりません。おそらく、明らかな何かが欠けているのかもしれません。どんな助けでも大歓迎です。
(評判が低いため、これに「chingu」のタグを付けることはできません。そのため、次に近いものである「libgosu」の下に配置されます)
ありがとう。
(出典:Rubyroids)