前端之家收集整理的这篇文章主要介绍了
cocos2dx之伪3D,2D平面图片按比例缩放实例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
下面是代码@H_301_2@
require "app.views.Utility"
local FightScene = class("FightScene",cc.load("mvc").ViewBase)
function FightScene:onCreate()
end
function FightScene : getPosByColAndRowAndSize(col,row,size)
return cc.p(size.width * (col + 1),size.height * row)
end
function FightScene:onEnter()
local function createSpriteWithPathPosScale(path,pos,scale)
local sprite = cc.Sprite:create(path)
sprite : setAnchorPoint(cc.p(0.5,0.5))
sprite : setPosition(pos)
sprite : setScale(scale)
return sprite
end
local size = cc.size(120,120)
local node = display.newNode() --动画结点
self : addChild(node)
local colNumer = 2
local rowNumber = 4
local width = 120
local height = 120
for col = 0,colNumer - 1 do
for row = 0,rowNumber - 1 do
local pos = self : getPosByColAndRowAndSize(col,size)
local role = createSpriteWithPathPosScale("role.png",1)
node : addChild(role)
local pos,scale = self : getPosScaleWithOriPos(pos.x,pos.y)
role : setPosition(pos)
role : setScale(scale)
if row == 3 and col == 1 then
local oriPos = self : getPosByColAndRowAndSize(col + 2,size)
local newPos,scale = self : getPosScaleWithOriPos(oriPos.x,oriPos.y)
role : runAction(
cc.Spawn : create(cc.MoveTo : create(1,newPos),cc.ScaleTo : create(1,scale))
)
end
end
end
node : setPosition(cc.p(0,(640 - (rowNumber - 1) * size.height) / 2))
node = display.newNode() --动画结点
self : addChild(node)
local colNumer = 2
local rowNumber = 4
for col = 0,pos.y)
role : setPosition(pos)
role : setScale(scale)
if row == 1 and col == 1 then
local oriPos = self : getPosByColAndRowAndSize(col + 1,scale))
)
end
end
end
node : setScaleX(-1)
node : setPosition(cc.p(960,(640 - (rowNumber - 1) * size.height) / 2))
end
--透视化好友
function FightScene : getPosScaleWithOriPos(oriX,oriY)
local x = oriX
local y = oriY
local lax = 100
local lay = 257 + 1000
local startZ = 0
y = y + startZ
local ys = 1.0-(y/(y+lay+580 + 100))
y = y * ys
x = (480+lax) + (x-(480+lax))*ys
local scale = ys
return cc.p(x - 50,y),scale
end
return FightScene
原文链接:https://www.f2er.com/cocos2dx/339977.html