It looks like you're new here. If you want to get involved, click one of these buttons!
Player = Core.class(Sprite) function Player:init() --[[self.image = Bitmap.new(Texture.new("Assets/grfx/mario_ani.png")) self:addChild(self.image)]] self.gravity = 1 --was 1 self.flighttMax = 200 self.flight = self.flightMax self.startX = 150 self:setX(self.startX) self.hold = false self.xAccel = 0 self.yAccel = 0 self.xVel = 0 self.yVel = 0 self.newY = 0 self.newX = 0 self.mass =-100 self.maxAccel = 30 self.maxVel = 30 self.onGround = false self.onWallLeft = false self.onWallRight = false self.onRoof = false filter = 0.1 fx = 0 fy = 0 fz = 0 self.Oy, self.Ox, self.Oz = accelerometer:getAcceleration() -- get oridentation at startup self:addEventListener(Event.MOUSE_DOWN, self.mouseDown, self) self:addEventListener("enterFrame", self.onEnterFrame, self) -- Load textures and create texture package self.animationTexturePack = TexturePack.new("Assets/grfx/mario_ani.txt", "Assets/grfx/mario_ani.png") --------------------------------------------------------------------- --------------------------------------------------------------------- -- Load animatoions and set to player. -- init texture animation loader and read animations... self.aniLoader = CTNTAnimatorLoader.new() -- read nimation infos self.aniLoader:loadAnimations("Assets/grfx/mario_ani.tan", self.animationTexturePack, false) -- create animation self.lastDirection = 1 self.anim = CTNTAnimator.new(self.aniLoader) self.anim:setAnimation("REST_RIGHT") self.anim:playAnimation() self.anim:addChildAnimation(self) self.anim:setVisible() -- add animation as child of player self:addChild(self.anim) --------------------------------------------------------------------- end function Player:onEnterFrame(event) if not pauseGame then -- get accelerometer values local y, x, z = accelerometer:getAcceleration() x = x - self.Ox y = y - self.Oy z = z - self.Oz -- do the low-pass filtering fx = x * filter + fx * (1 - filter) fy = y * filter + fy * (1 - filter) fz = z * filter + fz * (1 - filter) self:updateXAccel() self:updateVelocity(event.deltaTime) self:updateAnimation() self:updatePosition() end end function Player:updateAnimation() if self.xVel < 0 then --moving left if self.onGround == true then self.anim:setAnimation("RUN_LEFT") self.anim:setSpeed(math.abs(self.xVel)) self.lastDirection = 3 elseif self.onGround == false then self.anim:setAnimation("JUMP_LEFT") self.anim:setSpeed(math.sqrt(self.xVel*self.xVel + self.yAccel*self.yAccel)) end elseif self.xVel > 0 then if self.onGround == true then self.anim:setAnimation("RUN_RIGHT") self.anim:setSpeed(math.abs(self.xVel)) self.lastDirection = 4 elseif self.onGround == false then self.anim:setAnimation("JUMP_RIGHT") self.anim:setSpeed(math.sqrt(self.xVel*self.xVel + self.yAccel*self.yAccel)) end else -- set to idle animations if self.lastDirection == 3 and self.onGround == true then self.anim:setAnimation("REST_LEFT") else if self.lastDirection == 3 and self.onGround == false then self.anim:setAnimation("JUMP_LEFT") elseif self.lastDirection == 4 and self.onGround == true then self.anim:setAnimation("REST_RIGHT") elseif self.lastDirection == 4 and self.onGround == false then self.anim:setAnimation("JUMP_RIGHT") end end end end |
Comments
it's seems obvious but...
forgot to add "player object" to stage ?
www.tntengine.com
i think is
www.tntengine.com
The issue came out of nowhere, it's very strange. It was working just fine a while ago. I have no idea what I did!
can you send me a simple "working code" with the same issue?
maybe a bug on my side...
www.tntengine.com
player.lua is where the animation is handled, along with accelerometer and tap events.
The project should boot into a level with a character on screen. When working properly, you should be able to run around a very simple 2d map.
I apologize in advance, my code may not be commented all that well and it's kind of a mess.
On another note, feel free you use any code I've got here for other projects! That goes for anyone reading this
1. download and update your TNT Animator Studio (libs that you are using are outdated and OLD)
2. Some Code change in Player class:
on player:init()
and is working fine. (have a nice mario that jump and walk around!)
let me know if it solve.
Ciao!
www.tntengine.com
Thanks so much!