Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Parallax pause problem — Gideros Forum

Parallax pause problem

GhostLeaderGhostLeader Member
edited March 2014 in General questions
Hi im new to gideros i buy the book Gideros Mobile Game Development from iBook and i read too much and im in chapter 3 learning about physics in gideros, it was really great and easy to understand but i was planing on doing a parallax scrolling game so when i searched for a parallax tutorial
i used this one http://giderosmobile.com/forum/discussion/1158/class-and-example-for-parallax-background/p1
and i add this parallax ground to self but when i use the pause button the ground is always moving
lua
lua
level.lua
5K

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Well, this is something you will need to implement into ParaBG class
    you could for example add setPause method and on moving bg check if it is paused or not, something like this:
    --define pause variable in constructor
    function ParaBG:init(bgs, bgspeed)
     
    	--by default is not paused
    	self.paused = false
     
    	-- Far Background Images--repeat 
    	self.bg1 = Bitmap.new(Texture.new(bgs.bg1),true)
    	self.bg2 = Bitmap.new(Texture.new(bgs.bg1),true)
     
    	-- Closer Background Images--repeat
    	self.bg3 = Bitmap.new(Texture.new(bgs.bg2),true)
    	self.bg4 = Bitmap.new(Texture.new(bgs.bg2),true)
     
    	-- Set the starting points.
    	self.bgFarY=0
    	self.bgNearY=0
    	self.bgspeed = bgspeed
     
    	-- Add sprites.
    	self:addChild(self.bg1)
    	self:addChild(self.bg2)
    	self:addChild(self.bg3)
    	self:addChild(self.bg4)
     
    	--Event--
    	self:addEventListener(Event.ENTER_FRAME, self.DrawParaBG, self)
    end
    Then add pause check in enter frame event:
    function ParaBG:DrawParaBG(event, container)
     
    	if not self.paused then
    		self.bgFarY = (self.bgFarY or 0) - ((self.bgspeed or 4.0) / 4)
    		self.bgNearY = (self.bgNearY or 0) - ((self.bgspeed or 4.0))
     
    		self.newFarY = self.bg1:getWidth() -(-self.bgFarY)
    		if self.newFarY <=0 then
    			self.bgFarY = 0
    			self.bg1:setX(self.bgFarY)
    		else
    			self.bg1:setX(self.bgFarY)
    			self.bg2:setX(self.newFarY)
    		end
     
    		self.newNearY = self.bg3:getWidth() -(-self.bgNearY)
    		if self.newNearY <=0 then
    			self.bgNearY = 0
    			self.bg3:setX(self.bgNearY)
    		else
    			self.bg3:setX(self.bgNearY)
    			self.bg4:setX(self.newNearY)
    		end
    	end
    end
    Add additional method to control pause state
    function ParaBG:setPause(pause)
    	self.paused = pause
    end
    Then in your own scene, when you pause your game, also set pause to paralax class:
    self.paralax:setPause(true)
    --then when needed unpause it
    --self.paralax:setPause(false)
    Hope that helps ;)
  • thank you very much it work fine, thank you again :D
Sign In or Register to comment.