Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sprite_new_with_image to create a Sprite from raw image data #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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