显示模型

This commit is contained in:
chenxi 2023-04-11 20:52:14 +08:00
parent dd6e751174
commit 46d338e13d
6 changed files with 47 additions and 5 deletions

View File

@ -16,6 +16,8 @@ BattleConst.SIDE_DEF = 2
BattleConst.SKILL_TYPE_ACTIVE = 1
BattleConst.SKILL_SELECT_COUNT = 3
BattleConst.DEFAULT_FACTOR = 10000
BattleConst.INIT_POS_X = 200
BattleConst.UNIT_BODY_WIDTH = 100
-- 为方便存储,这里使用字符串
BattleConst.BATTLE_TYPE = {
@ -35,6 +37,10 @@ BattleConst.UNIT_STATE = {
DEAD = 4, -- 死亡
}
BattleConst.SPINE_ANIMATION_NAME = {
IDLE = "idle",
}
---- 格子类型
BattleConst.GRID_TYPE = {
EMPTY = 0,

View File

@ -14,8 +14,4 @@ function BattleHeroComp:initBase()
self.currState = UNIT_STATE.INIT
end
function BattleHeroComp:initPosition()
self.baseObject:setLocalPosition(0, 0, 0)
end
return BattleHeroComp

View File

@ -3,12 +3,22 @@ local BattleConst = require "app/module/battle/battle_const"
local BattleUnitComp = class("BattleUnitComp", LuaComponent)
local UNIT_STATE = BattleConst.UNIT_STATE
local SIDE_ATK = BattleConst.SIDE_ATK
local SPINE_ANIMATION_NAME = BattleConst.SPINE_ANIMATION_NAME
function BattleUnitComp:ctor()
end
function BattleUnitComp:initPosition()
self.baseObject:setLocalPosition(0, 0, 0)
if self.unitEntity:getSide() == SIDE_ATK then
self.baseObject:setLocalPosition(-BattleConst.INIT_POS_X, 0, 0)
else
self.baseObject:setLocalPosition(BattleConst.INIT_POS_X, 0, 0)
end
end
function BattleUnitComp:playBorn()
self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false)
end
function BattleUnitComp:_initBase()
@ -23,6 +33,20 @@ function BattleUnitComp:initWithEntity(modelId, entity, battleController, target
self.target = target
self:_initBase()
self:initPosition()
self:playBorn()
end
function BattleUnitComp:hideOutsideScreen()
if self.unitEntity:getSide() == SIDE_ATK then
self.baseObject:setLocalPosition(-GConst.UI_SCREEN_WIDTH/2 - BattleConst.UNIT_BODY_WIDTH, 0, 0)
else
self.baseObject:setLocalPosition(GConst.UI_SCREEN_WIDTH/2 + BattleConst.UNIT_BODY_WIDTH, 0, 0)
end
end
function BattleUnitComp:playAnimation(name, loop, forceRefresh)
self.currAnimationName = name
self.baseObject:playAnimation(name, loop, forceRefresh)
end
function BattleUnitComp:tick(dt)

View File

@ -133,6 +133,9 @@ function BattleController:initAllUnits(callback)
local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT)
heroComp:initWithEntity(modelId, v, self)
self.atkUnits[v:getMatchType()] = heroComp
if not v:getIsMainUnit() then
heroComp:hideOutsideScreen()
end
onloadFinished()
end)
end

View File

@ -28,6 +28,7 @@ function BattleTeamEntity:init(side, data)
self.members[unitData.matchType] = unit
self.membersCount = self.membersCount + 1
if self.mainHero == nil then
unit:setIsMainUnit(true)
self.mainHero = unit
end
end

View File

@ -43,4 +43,16 @@ function BattleUnitEntity:getMatchType()
return self.unitData.matchType
end
function BattleUnitEntity:getSide()
return self.side
end
function BattleUnitEntity:setIsMainUnit(isMainUnit)
self.isMainUnit = isMainUnit
end
function BattleUnitEntity:getIsMainUnit()
return self.isMainUnit
end
return BattleUnitEntity