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() --Variables used by player self.aE = Event.new("aimEvent") self.pE = Event.new("playerEvent") self.dX, self.dY = 0, 0 self.x1, self.y1 = 0, 0 self.x2, self.y2 = 0, 0 self.v = 2000 self.angle = 0 self.touched = false self.slow = 0 self.vx, self.vy = 0, 0 -- Setting up sprites self.player = Bitmap.new(playerTexture) self.player:setAnchorPoint(0.5, 0.5) self.player:setScale(0.7) self.player:setPosition(lwCenter, lhCenter) self.guide = Bitmap.new(guideTexture) self.guide:setAnchorPoint(0.5, 1) self.guide:setScaleY(0.2) self.guide:setAlpha(0) self.guide:setPosition(self.player:getPosition()) self:addChild(self.guide) self:addChild(self.player) -- Event Listeners self:addEventListener(Event.TOUCHES_BEGIN, self.touchBegin, self) self:addEventListener(Event.TOUCHES_MOVE, self.touchMove, self) self:addEventListener(Event.TOUCHES_END, self.touchEnd, self) self:addEventListener(Event.ENTER_FRAME, self.enterFrame, self) end function player:touchBegin(event) if event.touch.id == 1 then self.x1 = event.touch.x self.y1 = event.touch.y self.touched = true self.slow = 0.02 end end function player:touchMove(event) if event.touch.id == 1 then self.guide:setAlpha(1) self.touched = true -- Calculate and update player rotation self.x2 = event.touch.x self.y2 = event.touch.y self.dX = (self.x2 - self.x1) self.dY = (self.y2 - self.y1) self.angle = 180 - math.deg(math.atan2(self.dX, self.dY)) self.player:setRotation(self.angle) -- calculate vector local a = math.rad(self.angle) self.vx = math.sin(a) * self.v self.vy = (math.cos(a) * -1) * self.v if self.angle == 0 or self.angle == 180 then self.vx = 0 elseif self.angle == 90 or self.angle == 270 then self.vy =0 end end end function player:touchEnd(event) if event.touch.id == 1 then self.guide:setAlpha(0) self.slow = 1 self.touched = false end end function player:enterFrame(event) if self.touched then self.guide:setPosition(self.player:getX(), self.player:getY()) self.guide:setRotation(self.angle) end -- Firing player event to translate movement on bg, self.slow simulate slow motion effect when touch begins self.pE.vx = self.vx * self.slow * -1 * event.deltaTime self.pE.vy = self.vy * self.slow * -1 * event.deltaTime self:dispatchEvent(self.pE) end |
Comments
(I'm not experienced enough to answer your main question)
Code formatting:
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
https://wiki.giderosmobile.com/index.php/Game_Camera
You can see how to use it in the comments of the class. It is working ok for me, you can see it in action here: https://mokalux.itch.io/metroika
In case you can't setup the camera
Hope that helps.
Likes: koeosstudio
I tried this code but no luck: