It looks like you're new here. If you want to get involved, click one of these buttons!
Page10 = gideros.class(Sprite) -- duck function Page10:init( pageNo, parent) self.no = pageNo self.background = Bitmap.new(TextureRegion.new(Texture.new("gfx/duckback.jpg", true))) self.rooster = Bitmap.new(TextureRegion.new(Texture.new("gfx/roosterwood.png", true ))) self.rooster:setX(0) self.rooster:setY(450) self.ball = Bitmap.new(TextureRegion.new(Texture.new("gfx/duck.png", true))) self.ball:setX(250) self.ball:setY(0) self.ball.scaleX = 1 self.ball.inc = -0.001 self.buttonup = Bitmap.new(TextureRegion.new(Texture.new("gfx/1-up.png", true))) self.buttonup:setX(20) self.buttonup:setY(695) self.buttonup2 = Bitmap.new(TextureRegion.new(Texture.new("gfx/2-up.png", true))) self.buttonup2:setX(110) self.buttonup2:setY(695) self:addChild(self.background) self:addChild(self.rooster) self:addChild(self.buttonup) self:addChild(self.buttonup2) self:addChild(self.ball) self.sound = Sound.new("mp3/Japanese/cat.mp3") self.rooster.isMoving = false self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self) self:addEventListener(Event.REMOVED_FROM_STAGE, self.onRemovedFromStage, self) end function Page10:onAddedToStage() -- we need mouse functions to interact with the rooster self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self) self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self) self:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self) self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) end function Page10:onRemovedFromStage() self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) end function Page10:onMouseDown(event) -- touch event begins here. you need to get the initial x and y, we will use them later if (self.rooster:hitTestPoint(event.x, event.y) == true) then self.rooster.isMoving = true self.rooster.x0 = event.x self.rooster.y0 = event.y print("rooster") elseif (self.buttonup2:hitTestPoint(event.x, event.y) == true) then self.sound:play() elseif (self.buttonup:hitTestPoint(event.x, event.y) == true) then self.sound:play() end end function Page10:onMouseUp(event) -- touch event ends here. we must get out of the mode. if (self.rooster.isMoving == true) then self.rooster.isMoving = false end end function Page10:onMouseMove(event) if (self.rooster.isMoving == true) then -- calculate the difference local dx = event.x - self.rooster.x0 local dy = event.y - self.rooster.y0 --store the new x,y of touch coordinates self.rooster.x0 = event.x self.rooster.y0 = event.y --set the new coordinates self.rooster:setX(dx + self.rooster:getX()) self.rooster:setY(dy + self.rooster:getY()) end end function Page10:onEnterFrame(event) self.ball.scaleX = self.ball.scaleX + self.ball.inc if (self.ball.scaleX < 0.90) and self.ball.inc < 0 then self.ball.inc = -self.ball.inc end if (self.ball.scaleX > 1) and self.ball.inc > 0 then self.ball.inc = -self.ball.inc end self.ball:setScaleX(self.ball.scaleX) end |
Comments
Inside of the function Page3:onMouseDown(event)
I have tried to add the sound channels.
My idea is too add 7 mp3 sounds and on the mousedown I would like it to play the sound and if another button is clicked that sound will stop and the next will play on mousedown.
does that make since?
This way we know if self.soundChannel has a value then there is a soundChannel to check and then we can check the if it's playing using isPlaying(). Hope this helps!
The sound function must be called first function Page3:playSound(sound)
"sound"
As it is not an event correct?
Then I must create the variable. sound playing and then stopped ..
Still wrapping my head around. thanks for the explanation. on to study more.
thanks so much!