为了账号安全,请及时绑定邮箱和手机立即绑定

报错了,错误信息看不懂

[LUA-print] [string "src/app/Body.lua"]:27: attempt to index local 'node' (a number value)

stack traceback:

        [string "src/framework/functions.lua"]:336: in function 'new'

        [string "src/app/Snake.lua"]:28: in function 'Grow'

        [string "src/app/Snake.lua"]:12: in function 'ctor'

        [string "src/framework/functions.lua"]:336: in function 'new'

        [string "src/app/scenes/MainScene.lua"]:10: in function 'onEnter'

        [string "src/framework/cocos2dx/NodeEx.lua"]:143: in function 'listener_'      

        [string "src/framework/cocos2dx/NodeEx.lua"]:428: in function 'EventDispatcher'

        [string "src/framework/cocos2dx/NodeEx.lua"]:271: in function <[string "src/framework/cocos2dx/NodeEx.lua"]:270>


正在回答

5 回答

问题解决没有,我也和你出现了差不多的错误

0 回复 有任何疑惑可以回复我~
#1

慕无忌4252426 提问者

哈,当时解决了,过好久了,忘了,
2016-08-02 回复 有任何疑惑可以回复我~
#2

FLY8

求解怎么解决的
2017-01-26 回复 有任何疑惑可以回复我~

求问如何解决的。。跟着老师代码一模一样。但是没有出现body

0 回复 有任何疑惑可以回复我~

其实我也是新手,但是我看了一下,它好像是说你的node给了一个数值,你可以去MainScene那看一下snake的创建是不是self.snake = Snake.new(self),大概是这个原因吧

1 回复 有任何疑惑可以回复我~
#1

慕无忌4252426 提问者

嗯,我去看
2016-05-07 回复 有任何疑惑可以回复我~

local Snake = class("Snake")

local Body = require "app.Body"


local cInitLen = 3


function Snake:ctor( node )

self.BodyArray = {}

self.node = node

self.MoveDir = "left"


for i=1,cInitLen do

self:Grow(i ==1)

end

end


function Snake:GetTailGrid()

if #self.BodyArray == 0 then

return 0,0

end


local tail = self.BodyArray[#self.BodyArray]


return tail.X,tail.Y

end


function Snake:Grow( isHead )

local tailX,tailY = self:GetTailGrid()

local body = Body:new(self,tailX,tailY,self.node,isHead)


table.insert(self.BodyArray,body)

end


local function OffsetGridByDir( x,y,dir )

if dir == "left" then

return x-1,y

elseif dir == "right" then

return x+1,y

elseif dir == "up" then

return x,y-1

elseif dir == "down" then

return x,y+1

end


print("unknown dir",dir)


return x,y

end


function Snake:Update()

if #self.BodyArray == 0 then

return 0,0

end


for i = #self.BodyArray,1,-1 do

local body = self.BodyArray[i]


if i == 1 then

body.X,body.Y = OffsetGridByDir(body.X,body.Y,self.MoveDir)

else

local front = self.BodyArray[i-1]

body.X,body.Y = front.X,front.Y

end


body:Update()

end

end


return Snake


0 回复 有任何疑惑可以回复我~

local Body = class("Body")


local cGridSize = 33

local scaleRate = 1/display.contentScaleFactor


function Grid2Pos( x,y )

local visibleSize = cc.Director:getInstance():getVisibleSize()

local origin = cc.Director:getInstance():getVisibleOrigin()


local finalX = origin.x+visibleSize.width/2+x*cGridSize*scaleRate

local finalY = origin.y+visibleSize.height/2+y*cGridSize*scaleRate


return finalX,finalY

end


function Body:ctor( snake,x,y,node,isHead )

self.snake = snake

self.X = x

self.Y = y


if ishead then

self.sp = cc.Sprite:create("head_l.png")

else

self.sp = cc.Sprite:create("body.png")

end


node:addChild(self.sp)


self:Update()

end


function Body:Update()

local posx,posy = Grid2Pos(self.X,self.Y)


self.sp:setPosition(posx,posy)

end


return Body


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

报错了,错误信息看不懂

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信