local MainScene = class("MainScene", function() return display.newScene("MainScene") end) function MainScene:ctor() self:init() end function MainScene:init() display.addSpriteFrames("bandit-hd.plist","bandit-hd.png") --display.newSprite("#player_idle1.png",display.cx,display.cy):addTo(self) local HeroSprite=require("src.HeroSprite") local hero=HeroSprite.create() hero:setPosition(display.cx,display.cy) self:addChild(hero) local x,y=hero:getPosition() print(x.." "..y) return true end function MainScene:onEnter() end function MainScene:onExit() end return MainScene
--[[ local HeroSprite = class("HeroSprite", function() return display.newSprite("#player_idle1.png") end) ]] local HeroSprite = class("HeroSprite", function() return display.newSprite("#player_idle1.png") end) function HeroSprite:ctor() local x=self:getPositionX() local y=self:getPositionY() print(x) print(y) end function HeroSprite.create() local hero = HeroSprite.new() hero:init() return hero end -- 回调函数 function HeroSprite:init() print("****") local x,y=self:getPosition() print(x) print(y) return true end return HeroSprite