Era-Dorta / gosu-android

A Gosu implementation for Android devices, undergraduate project
MIT License
31 stars 2 forks source link

touch_ended never called #18

Open ashes999 opened 9 years ago

ashes999 commented 9 years ago

Hi,

It's me again. I'm interested in maintaining/extending this project in the very short term (like 1-3 weeks) to get one of my proof-of-concepts done. I will submit PRs for things I change.

For now, I need help. When I define touch_ended events in my GameWindow class, they're never called. I don't know why.

I looked through the code, and it seems fine. The handlers are defined equally for all three touch_* methods. I can't see where the problem is.

I'm using the v0.0.5 gem, if that matters.

Era-Dorta commented 9 years ago

Hi, thanks for commitment to the project.

I had a look at terrace repository and I couldn't quite figure out how to run the code. Could you give me detailed instructions so I can reproduce the bug?

As a side note, jlnr has been working on a integrated android port for Gosu, which to my understanding seems the way to go. https://github.com/gosu/gosu/tree/android https://github.com/gosu/gosu/issues/273

ashes999 commented 9 years ago

Thanks, that's very good news (the Android port of Gosu).

Sorry, my mobile work is experimental (and hence undocumented yet). If you must reproduce it, you can do the following:

You will need a working Ruboto environment for this. Since you haven't worked on your project for a couple of years, I don't want to inconvenience you with setting this all up again just for me. I will be happy with just some tips or something I can use to try and debug this.

You said that you tested touch_moved and it worked in the past?

Is this because I'm using the rubygems version and not building from source?

Era-Dorta commented 9 years ago

Thanks for the update, touch_moved is used in all of the examples in gosu_android. I recently used the version from ruby_gems and I got normal touch response in the arkanoid2 example. In any case, I'll look at it later in the day and I'll try to push version 0.0.6 to rubygems.

ashes999 commented 9 years ago

Sorry, I meant to say "You said that you tested touch_ended and it worked in the past?"

Thanks for investigating.

Era-Dorta commented 9 years ago

Truth be told, I can't remember if I ever tested touch_ended.

Era-Dorta commented 9 years ago

I tested touch_began and touch_ended with the code from rubygems in the arkanoid game example, and they both worked as expected. I'll give a try at reproducing with your code in the next couple of days.

ashes999 commented 9 years ago

I'm getting very inconsistent results.

I can now see touch_began now firing in my code, but nothing yet with touch_ended. I'll try and see if there's something wrong I'm doing on my end.

ashes999 commented 9 years ago

Here's some sample code that reproduces the problem. In the log files, I see lots of 1 TOUCH BEGAN and 1 TOUCH MOVED but no TOUCH END messages.

require 'ruboto/widget'
require 'ruboto/util/toast'
require 'gosu'

class GameWindow < Gosu::Window
  def initialize
    super(640, 480, false)
    self.caption = "Gosu Tutorial Game"
    @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
  end

  def update

  end

  @@i = 1

  # TODO: turn this into touch_ended
  def touch_ended(touch)
    @message = "#{@@i} TOUCH ENDED #{touch}"
    puts @message
  end

  def touch_began(touch)
    @message = "#{@@i} TOUCH BEGAN #{touch}"
    puts @message
  end

  def touch_moved(touch)
    @message = "#{@@i} TOUCH MOVED #{touch}"
    puts @message
  end

  def draw

  end

  def button_down(id)
    if id == Gosu::KbEscape then
      close
    end
  end
end

class TemplateActivity
  def on_create(bundle)
    super(bundle)
    Gosu::AndroidInitializer.instance.start(self)
    rescue Exception => e
      puts "#{ e } (#{ e.class } #{e.message} #{e.backtrace.inspect} )!"
  end

  def on_ready
    window = GameWindow.new
    window.show
    rescue Exception => e
      puts "#{ e } (#{ e.class } #{e.message} #{e.backtrace.inspect} )!"
  end
end
Era-Dorta commented 9 years ago

Quite strange, on my phone that code outputs to the log all the TOUCH BEGAN, TOUCH MOVED and TOUCH ENDED. This might actually have to do with #19, since in this line if the touch coordinates are outside the screen defined by Gosu, the touch is ignored.

ashes999 commented 9 years ago

I'm not sure. The same if statement applies to all three touch events. Why would only two work? It's very strange. It might even be an emulator bug, if it's working fine on your phone.