Skip to content

Conversation

@danhealy
Copy link

This creates a convenience singleton method on Sprite to create an Image from raw image data, a Texture from that Image, and finally a Sprite using createWithTexture.

Ideally the Image and Texture classes would be fully exposed to Ruby, but this is beyond my capabilities at the moment.

Example usage (based on motion-flow with motion-game example here https://github.com/andrewhavens/motion-game-with-flow-example ):

# Inside an MG::Scene
Net.get("http://www.rubymotion.com/img/rubymotion-logo.png") do |response|
  dat = response.body.to_data.to_s
  img = MG::Sprite.new_with_image(dat, dat.length)
  add img
end

The above example won't work on Android for two reasons:

  1. .to_data is unavailable
  2. A hard coded string in Ruby is interpreted differently somehow by the time it reaches this C++ code, I believe because Java strings are UTF-16 by default, but I am not certain.

@Watson1978
Copy link
Member

I think Sprite.new should be extended to accept raw data.

  • Create Sprite object from file
MG::Sprite.new('skyline.png')
MG::Sprite.new('skyline.png', :file)
  • Create Sprite object from raw data
MG::Sprite.new(data, :raw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants