1067:值的隐含强制

时间:2014-03-28 04:00:53

标签: actionscript

所以我现在正试图对我的两个精灵进行碰撞测试,并且我收到以下错误:

C:\\Code\\Game\Game.as, Line 54, Column 34 1067: Implicit coercion of a value of type mvc:PlayerModel to an unrelated type assets.Scripts:SpriteAnimation.

指向以下代码行:

handleSpriteToSpriteCollision(_player, _boss);

功能如下:

private function handleSpriteToSpriteCollision(sprite1:SpriteAnimation, sprite2:SpriteAnimation):void
{
    var toSprite2 : VectorModel = new
    VectorModel(0,0,0,0, sprite2.x - sprite1.x, sprite2.y - sprite1.y); 
    var bitmapData1:BitmapData = new BitmapData(sprite1.width, sprite1.height);                 
    while(testBitmapCollision(sprite1.spriteFrameBitmapData, sprite1.topLeftX, sprite1.topLeftY, sprite2.spriteFrameBitmapData, sprite2.topLeftX, sprite2.topLeftY))
    {
        sprite2.x -= toSprite2.dx;
        sprite2.y -= toSprite2.dy;
    }
}

两个精灵都显示得很好,但是一旦我调用了函数,它就会崩溃。在这一点上,我只需要一些新鲜的眼睛来看看代码,看看出了什么问题。

编辑:这是PlayerModel.as

package mvc
{
import flash.events.Event;
import flash.events.EventDispatcher;
import assets.Scripts.SpriteAnimation;

public class PlayerModel extends EventDispatcher
{
    private var _previousX:Number = 0;
    private var _previousY:Number = 0;
    private var _xPos:Number = 0;
    private var _yPos:Number = 0;
    public var vx:Number = 0;
    public var vy:Number = 0;
    private var _height:uint = 30;
    private var _width:uint;
    private var _color:uint;

    public function PlayerModel():void 
    {
    }
    public function update():void
    {
        xPos += vx;
        yPos += vy;
    }

    public function get height():uint
    {
        return _height;
    }

    public function get color():uint
    {
        return _color;
    }

    public function get xPos():Number
    {
        return _xPos;
    }
    public function set xPos(value:Number):void
    {
        _xPos = value;
        dispatchEvent(new Event(Event.CHANGE));
    }

    public function get yPos():Number
    {
        return _yPos;
    }
    public function set yPos(value:Number):void
    {
        _yPos = value;
        dispatchEvent(new Event(Event.CHANGE));
    }

    public function set setX(value:Number):void
    {
      _previousX = value - vx;
        xPos = value;
    }

    public function set setY(value:Number):void
    {
        _previousY = value - vy;
        yPos = value;
    }
}
}

1 个答案:

答案 0 :(得分:0)

我要检查的第一件事是你的老板的类和玩家对象继承你的SpriteAnimation类:

class PlayerModel extends SpriteAnimation 
{ ...

好像你的handleSpriteToSpriteCollision函数正在寻找两个SpriteAnimations并且至少传递的PlayerModel不是一个

Sprite继承了EventDispatcher,只要您的SpriteAnimation也继承了Sprite,就不应该丢失任何功能