So, basically, I have a sprite (.png) in SpriteKit, where most of the pixels are zero/no detail etc.
I wish to create a UIBezierPath of only the detail inside the Sprite, so later I can use containsPoint.
After a bunch of googling I found you can create a PhysicsBody using the path of the Texture in the sprite image, like this:
let texture = SKTexture(imageNamed: "myImage.png")
img.physicsBody = SKPhysicsBody(texture: texture, size: img.size)
This creates a physics body around only the detail inside the image, excluding any alpha value pixels, if you know what I mean.
Is there a way to create a BezierPath doing the same? or maybe creating a CGPath, then using that to create a BezierPath?
The reason is, I'm hoping to test if a CGPoint is inside this sprite, without using the physicsDelegate or physicsBodys.
Thanks in advance.
Related
I'm learning unity and I have successfully instantiated a new game object into my scene (a cube)
Now I'm playing with the Canvas UI and I'm trying to download an asset bundle with images and show them on the UI, but I can't find examples on Google
Can someone post me an example on how to load an image into the Canvas from an asset bundle?
Thanks!!!
There are a few things to do to get this to work:
You'll need to Create a UnityEngine.UI.Image (sprites don't work on Canvas on their own).
Assign the Image.Sprite property by grabbing the Texture2D out of the bundle, and if needed, you can create a sprite using the Sprite.Create() method which takes a Texture2D.
In other words, an Image has a Sprite, and a Sprite is made from a Texture2D.
Texture2D tex = myAssetBundle.LoadAsset<Texture2D>("myTex");
Sprite mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
Select the image from the asset bundle.Set the texture type to Sprite(2D and UI).Then simply drag and drop your image into the canvas.
I am wondering how I would be able to use animated shapes inside a movieclip that would be acting as a mask?
In my Animate CC canvas file I have an instance (stripeMask) that should mask the below instance called mapAnim.
stripeMask contains shapes that are animating in.
So when the function maskIn is called, the playhead should move to the first frame inside the stripeMask clip (the one after frame 0) and animate the mask like so:
function maskIn(){
//maskAnimation to reveal image below
stripeMask.gotoAndPlay(1);
}
I love AnimateCC and it works great, but the need for creating more complex and animated masks is there and it's not easy to achieve unless I am missing something here.
Thanks!
Currently you can only use a Shape as a mask, not a Container or MovieClip.
If you want to do something more complex, you can use something like AlphaMaskFilter, but it has to be cached, and then updated every time the mask OR the content updates:
something.filters = [new createjs.AlphaMaskFilter(stripeMask)];
something cache(0,0,w,h);
// On Change
something.updateCache(); // Re-caches
The source of the AlphaMaskFilter must be an image, so you can either point to a Bitmap image, or a cacheCanvas of a mask clip you have also cached. Note that if the mask changes, the cache has to be updated as well.
This is admittedly not a fantastic solution, and we are working on other options.
I am trying to create a cube using three.js for a project. I need to add text to vertices and at different points inside the cube. Any idea how this can be done?
For some basic code examples of using Sprite objects in Three.js, check out:
http://stemkoski.github.com/Three.js/Sprites.html
And for an easy way to create images that contain text to use as your sprite textures, check out the sample code at:
http://stemkoski.github.com/Three.js/Texture-From-Canvas.html
I think a combination of these two ideas will achieve what you are looking to do.
If you want to have label-style texts, so that the text begins at a specific point, but is always oriented with the camera and easily readable no matter the camera position, you can use sprites. (example of canvas-created text label sprites: http://i.imgur.com/e9I68xD.jpg - here they are rendered on a separate pass to that they are never obscured by the scene but you can do it on the same pass)
If that's what you are looking for, I'd suggest first checking the Sprites examples, and learn to attach some static image as a sprite to correct position in the scene. After you get that working, you modify the code so that you generate the text to an image canvas using standard Javascript Canvas functions, and using that image as the sprite.
I would like to make a reflection to an image - like this:
Is that possible in Monotouch?
Thanks!
Mojo
It is possible, considering that you have full access to CoreGraphics.
There are too many ways of skinning that cat though.
Say you have the top image in "image", I would do something like:
Create a graphics context
Draw the image
Create a bitmap context for the inverted image, with alpha transparency
Render the image invertd
Render a gradient that has been configured to go from 0.5 opaque to 0.2 opaque
Render that on the bottom of the image
Get an image out of the second context
Draw the extracted image into the first context, inverted.
hi
how can i let the user to crop his picture before choosing one
in the photoChooserTask?
( in msdn it says that the pixelheight/width doesn't work yet)
thanks
You would have to do the pixel operations yourself after the image has selected. You can render the image to the screen, and then look for two touch points to determine the x/y and height/width ... then create a new texture with those dimensions and render to it as a RenderTarget. You can then save this new texture, or do whatever you need to do with it
Not sure if Windows Phone 7 can handle RenderTargets but if it can. You can just have the user drag a rectangle, create a RenderTarget of that size, and then draw to the RenderTarget using the rectangle as the source rectangle of the image you want to crop.