Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Controller again :( — Gideros Forum

Controller again :(

oikyoiky Member
edited November 2012 in General questions
I'm trying to get my object move by pressing the left / right. On the tablet, it moves as conceived (by holding down the movement is), but on the smartphone and computer onMouseMove phase does not occur and the object moves only by successive pressing this button. In what could be the problem?

Comments

  • can you post some code as well as the scale mode you are using?

    :)
  • oikyoiky Member
    edited November 2012
    It's my Button.lua script:
    Button = Core.class(Sprite)
     
    function Button:init(upState, downState)
    	self.upState = upState
    	self.downState = downState
     
    	self.focus = false
     
    	self:updateVisualState(false)
     
    	self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    	self:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)
    	self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    end
     
    function Button:onMouseDown(event)
    	if self:hitTestPoint(event.x, event.y) then
    		self.focus = true
    		self:updateVisualState(true)
    		self:dispatchEvent(Event.new("click"))
    		event:stopPropagation()
    	end
    end
     
    function Button:onMouseMove(event)
    	if self.focus then
    		if not self:hitTestPoint(event.x, event.y) then
    			self.focus = false;
    			self:updateVisualState(false)
    		end
    				self:dispatchEvent(Event.new("click"))
     
    		event:stopPropagation()
    	end
    end
     
    function Button:onMouseUp(event)
    	if self.focus then
    		self.focus = false;
    		self:updateVisualState(false)
    		--self:dispatchEvent(Event.new("click"))
    		event:stopPropagation()
    	end
    end
     
    -- if state is true show downState else show upState
    function Button:updateVisualState(state)
    	if state then
    		if self:contains(self.upState) then
    			self:removeChild(self.upState)
    		end
     
    		if not self:contains(self.downState) then
    			self:addChild(self.downState)
    		end
    	else
    		if self:contains(self.downState) then
    			self:removeChild(self.downState)
    		end
     
    		if not self:contains(self.upState) then
    			self:addChild(self.upState)
    		end
    	end
    end
    And it's part of main script:
    function onClick(event)
    	if event:getTarget() == right then
    	shipright()
    	shipmoving()
    	elseif event:getTarget() == left then
    	shipleft()
    	shipmoving()
    	end
    end
    right:addEventListener("click", onClick)
    left:addEventListener("click", onClick)

    Letterbox scaling mode
  • Not sure if this helps, but this is the left / right control I'm using for my game:

    http://www.giderosmobile.com/forum/discussion/2093/platformer-run-jump-example-game#Item_8
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    I believe @Tom2012 example should help you

    But to get to the bottom of the problem: MouseMove event is not fired when holding down the button. It's only fired when you move mouse/finger.

    So if you want to create continuous movement, you would need to listen to down and up event. On down event you could, for example start a timer and move ship on every timer tick and on up event cancel the timer to stop ship movement.
Sign In or Register to comment.