It looks like you're new here. If you want to get involved, click one of these buttons!
function PlayerMovement:onEnterFrame() self.heroX, self.heroY = self.scene.hero.body:getPosition(); self.distanceFromTilemapLeft = self.scene.hero:getX()-self.scene.tilemap:getX() --self.distanceFromTilemapRight = self.scene.tilemap:getWidth() - self.distanceFromTilemapLeft if(self.movingRight) then self.nextX = self.distanceFromTilemapLeft + self.speed print(self.nextX) -- Scoll and hero move if(self.nextX > 220) then self.heroMove = 220 - self.heroX; if(self.heroMove < 0) then self.heroMove = 0; end self.scrollMove = self.nextX - 220; if(self.scrollMove > self.speed) then self.scrollMove = self.speed; end else -- Just hero move --print("hero move", self.heroMove) self.heroMove = self.speed self.scrollMove = 0; end -- make hero move self.scene.hero.body:setPosition(self.heroX+self.heroMove,self.heroY) self.scene.hero:setPosition(self.heroX+self.heroMove,self.heroY) -- make scroll move self.scene.tilemap:setX(self.scene.tilemap:getX()-self.scrollMove) end if(self.movingLeft) then self.nextX = self.distanceFromTilemapLeft - self.speed print(self.nextX) -- Scoll and hero move if(self.nextX < 220) then self.heroMove = 220 - self.nextX; if(self.heroMove > self.speed) then self.heroMove = self.speed; end self.scrollMove = self.heroX - 220; if(self.scrollMove < 0) then self.scrollMove = 0; end else -- Just scroll self.heroMove = 0 self.scrollMove = self.speed; end -- make hero move self.scene.hero.body:setPosition(self.heroX-self.heroMove,self.heroY) self.scene.hero:setPosition(self.heroX-self.heroMove,self.heroY) -- make scroll move self.scene.tilemap:setX(self.scene.tilemap:getX()+self.scrollMove) --]] end self.scene.hero.body:setAngle(0) end |
Comments
If move right then
Direction = -1
Else
Direction = 1
End
And use direction to indicate direction.
My apps: http://www.yummyyellow.com