Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Jitter on high speed moving sprites - Gideros Forum

Jitter on high speed moving sprites

koeosstudiokoeosstudio Member
edited October 4 in Game & application design
I don't know if this is a problem or I am just wrong with my code. Since there is no built in camera camera class that follows a player's movement, the thing that I am doing is translating the player's movement in reverse to the background instead and inserting it in a frame event with delta time to update. My configuration is 60 fps. There is no problem when I translate a slow speed.But when I try at higher speed above 2000, the game play it still acceptable but the thing is the sprites contained in the background leave jitters and the as a result, the backgrounds is like the one which moving when observed by the eye and the player was perceived like standing still on the center of the screen. LoL

My guess about the cause of the problem is: I am using a very low enough resolution where the movement step is longer in distance than with higher resolution. My current resolution is 720, 1280. This is my code:
 
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

Sign In or Register to comment.