在Java中,我创建了以下类,它扩展了ImageView以创建一个角色......我想知道是否可以添加我的角色所持有的项目的另一个图像(参见方法“addWeapon()”),当它移动时我的角色移动(参见方法“warriorMover(..)”)。基本上,我想知道是否有可能使“武器形象”成为主角的“特征/部分”?
public class WarriorEntity extends ImageView
{
private kingsColor kingColor;
private weapons weaponId;
private int kingSide;
private int warriorId;
private int nLeft;
private int nTop;
public WarriorEntity(Context context)
{
super(context);
}
public void defineWarrior(kingsColor a1, weapons a2, int a3, int a4, int a5, int a6)
{
kingColor = a1;
weaponId = a2;
kingSide = a3;
warriorId = a4;
nLeft = a5;
nTop = a6;
switch (kingColor)
{
case blue:
this.setImageResource(R.drawable.bluewarrior);
break;
case green:
this.setImageResource(R.drawable.greenwarrior);
break;
case purple:
this.setImageResource(R.drawable.purplewarrior);
break;
case red:
this.setImageResource(R.drawable.redwarrior);
break;
case white:
this.setImageResource(R.drawable.whitewarrior);
break;
case yellow:
this.setImageResource(R.drawable.yellowwarrior);
break;
}
this.setId(warriorId);
this.setOnClickListener(WarriorClick);
setImagexy(this, nLeft, nTop, 20, 30);
}
public void addWeapon()
{
switch (weaponId)
{
case bowandarrow :
break;
case mace :
break;
case spear :
break;
case sword :
// - Here I would want some code to add the weapon image which as if it were part
of the same image as the character... moves/reacts with the character.
break;
}
}
public void warriorMover(int leftX, int topY)
{
setImagexy(this, leftX + 8, topY - 3, 20, 30);
}
“setImagexy”是一个自定义方法,它完全可以......将图像移动到屏幕上的给定位置。