Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
When i hit the button nothing happen — Gideros Forum

When i hit the button nothing happen

a00zaa00za Member
edited February 2013 in General questions
i coded a game that when i hit the button the image will move however nothing happen

here is the code

rqaq_p2= Core.class(Sprite)

function rqaq_p2:init(start)
application:setOrientation(Application.PORTRAIT)
-----------timer---------
local counter=0;
timer = Timer.new(1000, 10)
t = 10
local Right_click=0
------ADD images-------------------------------------------------
--bg
local bg = Bitmap.new(Texture.new("Pics/rqaq/table.png"))
local scX = application:getContentWidth() / 1536
local scY = application:getContentHeight() / 2048
bg:setScale(scX,scY)
self:addChild(bg)

local applicationHeight = application:getContentHeight()
local applicationWidth = application:getContentWidth()
localScoreOfPhase = 0
--progClock
local progClock = ProgressClock.new()
progClock:setScale(scX,scY)
self:addChild(progClock)
---bowl
local bowl = Bitmap.new(Texture.new("Pics/rqaq/rqaq2_bowl.png"))
bowl:setAnchorPoint(0.5,0.5)
--bowl:setPosition(240,240)
bowl:setPosition(applicationWidth*0.50,applicationHeight*0.35)
bowl:setScale(scX,scY)
self:addChild(bowl)
--Dough_Rqaq
local Dough_Rqaq = Bitmap.new(Texture.new("Pics/rqaq/dough.png"))
Dough_Rqaq:setPosition(applicationWidth*0.50,applicationHeight*0.35)
Dough_Rqaq:setAnchorPoint(0.5,0.5)
Dough_Rqaq:setScale(scX,scY)
self:addChild(Dough_Rqaq)
--Open HAnd
local O_hand_Rqaq = Bitmap.new(Texture.new("Pics/Common/hand_opened.png"))
O_hand_Rqaq :setPosition(applicationWidth*0.50,applicationHeight*0.35)
O_hand_Rqaq :setScale(scX,scY)
O_hand_Rqaq :setVisible(false)
O_hand_Rqaq.xdirection = 1
O_hand_Rqaq.ydirection = 1
O_hand_Rqaq.xspeed = 250
O_hand_Rqaq.yspeed = 250
self:addChild(O_hand_Rqaq )
--Closed HAnd
local C_hand_Rqaq = Bitmap.new(Texture.new("Pics/Common/hand_closed.png"))
C_hand_Rqaq :setPosition(applicationWidth*0.50,applicationHeight*0.35)
C_hand_Rqaq :setScale(scX,scY)
C_hand_Rqaq :setVisible(false)
C_hand_Rqaq.xdirection = 1
C_hand_Rqaq.ydirection = 1
C_hand_Rqaq.xspeed = 250
C_hand_Rqaq.yspeed = 250
self:addChild(C_hand_Rqaq )
--Open hand click up
Open_up = Bitmap.new(Texture.new("Pics/rqaq/Open_CLick_up.PNG"))
--open hand click down
Open_down = Bitmap.new(Texture.new("Pics/rqaq/Open_CLick_down.PNG"))
--Closed hand click up
Close_up = Bitmap.new(Texture.new("Pics/rqaq/Close_CLick_up.PNG"))
--Closed hand click down
Close_down = Bitmap.new(Texture.new("Pics/rqaq/Close_CLick_down.PNG"))
--Notification R_click_O
R_click_O =Bitmap.new(Texture.new("Pics/rqaq/R_click_O.png"))
R_click_O:setPosition(applicationWidth*0.218,applicationHeight*0.70)
R_click_O:setScale(scX,scY)
R_click_O:setVisible(false)
self:addChild(R_click_O)
-- create the button
local Open_button = Button.new(Open_up, Open_down)
local Close_button = Button.new(Close_up, Close_down)
--set postion of the Open Button
Open_button:setPosition(applicationWidth*0.85,applicationHeight*0.63)
Open_button:setScale(scX,scY)
self:addChild(Open_button)
--set postion of the Close Button
Close_button:setPosition(applicationWidth*0.02,applicationHeight*0.63)
Close_button :setScale(scX,scY)
self:addChild(Close_button)
--Notification R_click_C
R_click_C=Bitmap.new(Texture.new("Pics/rqaq/R_click_C.png"))
R_click_C:setPosition(applicationWidth*0.218,applicationHeight*0.70)
R_click_C:setScale(scX,scY)
R_click_C:setVisible(false)
self:addChild(R_click_C)

----------------------------------Event---------------------------
---Events for the Timer
self:addEventListener(Event.TIMER, self.onTimer,self.timer)
self:addEventListener(Event.TIMER_COMPLETE, self.onTimerComplete,self.timer)
timer:start()
---Evente for clicking the Closed hand clicker
--self:addEventListener(Event.MOUSE_UP, CLicking,self.Open_button)
self:addEventListener(Event.MOUSE_UP, self.CLicking_Hand_O,self.Open_button)
self:addEventListener(Event.MOUSE_UP, self.Disap_Hand_C,self.Open_button)
---Evente for clicking the Open hand clicker
--self:addEventListener(Event.MOUSE_UP, CLicking,self)
self:addEventListener(Event.MOUSE_UP, self.CLicking_Hand_C,self.Close_button)
self:addEventListener(Event.MOUSE_UP, self.Disap_Hand_O,self.Close_button)





--sprites = {}
--endOfPhase = false
--self:addEventListener("spriteRemoved",self.onSpriteRemove, self)


end
--Functions---------------------------------------------------------------
function rqaq_p2:CLicking(target, event)
if target:hitTestPoint(event.x, event.y) then
--add new image for the dough and disable visibility fot the previous image
self.dough:setVisible(false)
end
end
---Open hand clicking----
function rqaq_p2:CLicking_Hand_O(event)
if(self.Open_button:hitTestPoint(event.x, event.y)) then
x,y = self.O_hand_Rqaq:getPosition()
x = x + (self.O_hand_Rqaq.xspeed * self.O_hand_Rqaq.xdirection)
y = y + (self.O_hand_Rqaq.yspeed * self.O_hand_Rqaq.ydirection)
if x < 300 then
self.O_hand_Rqaq.xdirection = 1
end

if x > 1500 - self.Dough_Rqaq:getWidth() then
self.O_hand_Rqaq.xdirection = -1
end

if y < 330 then
self.O_hand_Rqaq.ydirection = 1
end

if y > 1250 - self.Dough_Rqaq:getHeight() then
self.O_hand_Rqaq.ydirection = -1
end

self.O_hand_Rqaq:setPosition(x, y)
self.O_hand_Rqaq:setVisible(true)
end
end

---Close hand clicking-----
function rqaq_p2:CLicking_Hand_C(event)
if self:hitTestPoint(event.x, event.y) then
if( (self:getY()>(application:getContentHeight()*0.60)) and (self:getY()<(application:getContentHeight()*0.66))
and (self:getX()>(application:getContentWidth()*0.005)) and (self:getX()<(application:getContentWidth()*0.04))) then
local x,y = self.C_hand_Rqaq:getPosition()
x = x + (self.C_hand_Rqaq.xspeed * self.C_hand_Rqaq.xdirection)
y = y + (self.C_hand_Rqaq.yspeed * self.C_hand_Rqaq.ydirection)

if x < 300 then
self.C_hand_Rqaq.xdirection = 1
end

if x > 1500 - Dough_Rqaq:getWidth() then
self.C_hand_Rqaq.xdirection = -1
end

if y < 330 then
self.C_hand_Rqaq.ydirection = 1
end
if y > 1250 - self.Dough_Rqaq:getHeight() then

self.C_hand_Rqaq.ydirection = -1
end
self.C_hand_Rqaq:setPosition(x, y)
self.C_hand_Rqaq:setVisible(true)
end
end
end

--Make the hand disappeaer when clicking the other click the CLosed HAndfunction Disap_Hand_C(target, event)
function rqaq_p2:Disap_Hand_C(target, event)
self.C_hand_Rqaq:setVisible(false)

end
--Make the hand disappeaer when clicking the other click the Opend HAnd
function rqaq_p2:Disap_Hand_O(target, event)
self.O_hand_Rqaq:setVisible(false)

end

--On Timer function
function rqaq_p2:onTimer(e)
self.R_click_O:setVisible(false)
self.R_click_C:setVisible(false)
t= t-0.5
random_click = math.random(1,2)
if( random_click == 1) then
self.R_click_O:setVisible(false)
self.R_click_C:setVisible(true)
self.Right_click=0
else
self.R_click_C:setVisible(false)
self.R_click_O:setVisible(true)
self.Right_click=1

end
counter=counter+1
end
--On TimerComplete function
function rqaq_p2:onTimerComplete(e)
self.R_click_O:setVisible(false)
self.R_click_C:setVisible(false)
print("timer complete", e:getTarget(), e:getType())
end
------------------------------------------EnD Function--------------------
Tagged:

Comments

  • BJGBJG Member
    Accepted Answer
    Hi a00za - It takes a lot of work to debug a large undocumented program like this. Can you isolate a small section that doesn't work, and just post that?
  • techdojotechdojo Guru
    Accepted Answer
    @a00za - put some print() statements in your code, specifically at the point where you assign the touch event (mouse up, down etc), then put some more in the handler function - that way when you run the code you can "see" what's happening more effectively and have a better idea where your problem lies.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • here is the Event
    self:addEventListener(Event.MOUSE_UP, self.CLicking_Hand_O,self.Open_button)
    and the function of the Event
    ---Open hand clicking----
    function rqaq_p2:CLicking_Hand_O(event)
    if(self.Open_button:hitTestPoint(event.x, event.y)) then
    x,y = self.O_hand_Rqaq:getPosition()
    x = x + (self.O_hand_Rqaq.xspeed * self.O_hand_Rqaq.xdirection)
    y = y + (self.O_hand_Rqaq.yspeed * self.O_hand_Rqaq.ydirection)
    if x < 300 then
    self.O_hand_Rqaq.xdirection = 1
    end

    if x > 1500 - self.Dough_Rqaq:getWidth() then
    self.O_hand_Rqaq.xdirection = -1
    end

    if y < 330 then
    self.O_hand_Rqaq.ydirection = 1
    end

    if y > 1250 - self.Dough_Rqaq:getHeight() then
    self.O_hand_Rqaq.ydirection = -1
    end

    self.O_hand_Rqaq:setPosition(x, y)
    self.O_hand_Rqaq:setVisible(true)
    end
    end
  • @techdojo i tried the print and i found that the it does not call the function
  • BJGBJG Member
    edited February 2013
    Did you put the check to see if the function was being called before the coordinate test with "hitTestPoint"...? So it should be called if there's a MOUSE_UP anywhere on the screen...?
  • before the if statment i wrote the print
  • Is it possible to provide a brief section of code that you feel should work, complete in itself, but doesn't...? It's impossible to know why your event isn't triggering at the moment. For instance, there's nothing you've posted up yet which actually creates an instance of the class...
  • for the CLicking_Hand_O function it should move an object when the button is clicked it was working before however when re organize the the code like putting it in the init() and adding it to self not to stage i get the problem
  • BJGBJG Member
    edited February 2013
    You seem to have the syntax correct. To reduce the program to a trivial example...
    rqaq_p2= Core.class(Sprite)
     
    function rqaq_p2:init(start)
    self:addEventListener(Event.MOUSE_UP, self.CLicking_Hand_O,self.Open_button)
    end
     
    function rqaq_p2:CLicking_Hand_O(event)
    print("detected MOUSE_UP")
    end
     
    x = rqaq_p2.new()
    stage:addChild(x)
    This will correctly report "detected MOUSE_UP" when you click on the screen.

    Maybe you could try simplifying your program by commenting stuff out until you have something that works, then gradually add the complexity back in until you hit the part which is causing it to fail.
    ...like putting it in the init() and adding it to self not to stage...
    (You would need to add an object created from this class to the stage in order for this event handler to work, though, as in the last two lines above.)
  • thank you i will try
Sign In or Register to comment.