Andengine collision detection according to scaled size of sprite - andengine

I had Animated Sprites and i scaled down thoes sprites .. And increase the size of sprites. I want to detect collision of sprites according to scaled size.

In this case you can do in this way:
For Example
Sprite player, monister;
if( player.cotains(monister.getScaleX(), monister.getScaleY())){
// you can do what ever you want
}

Related

Animate an SKSpriteNode with textures that have a size different from the original

I want to animate an SKSpriteNode using textures from an SKTextureAtlas, using SKAction.animateWithTextures(textures,timePerFrame,resize,restore). However, the textures in the atlas have a size that is slightly larger than the original texture (it's basically a character moving). When the action is run, the textures are either compressed to fit the original size of the sprite, or recentered when I set resize to false, which changes the position of the character. What I want, though, is for the textures to be anchored at the lower-left corner (or lower-right, depending on the direction) so that the position of the character doesn't change apart from the extra part of the texture.
I've tried changing the anchor point of the sprite prior to running the action, but obviously that applies to the original texture as well. Also, I guess changing the size of the original texture would have an impact on the physics behaviour, which I want to avoid.
Does anyone have a suggestion about how to do this?
Thanks!
David
This would work
Edit all the textures to match the size of the largest sized texture.
Just give the smaller textures some padding using an alpha channel to give you a transparent background.
E.g. Notice how the first texture has lots of negative space
(From CartoonSmart.com)
Create the physics body with a certain size in mind. E.g. You can load the texture without the padding and get the size. Then position it as needed onto the new and improved texture with padding. So after you create the Sprite as normal with the new resized textures you can then
/// load a texture to be a template for the size
let imageTextureSizeTemplate = SKTexture(imageNamed: textureWithoutPadding)
let bodySize = imageTextureSizeTemplate.size()
/// position template texture physics body on texture that will be used
let bodyCenter = CGPointMake(0.5, 0.5)
// create physics body
let body:SKPhysicsBody = SKPhysicsBody(rectangleOfSize: bodySize, center: bodyCeneter)
self.physicsBody = body
Set resize: false when you animate the textures.

Misconception about how the scales work

I am a beginner in Unity and I can't understand how the scales of GameObjects work; in the following picture I have a quad and a sprite. The quad's scale should be smaller than the sprite's scale, but in the editor when I touch them they have the same scale of 1.
Short Answer
Every object has a baseline (1, 1, 1) scale when first created. The size for a 2D sprite and 3D quad object are calculated differently for each, which is why they are not the same size in your screenshot.
Long Answer
The sprite is a 2D object and its size is based on the import settings of the sprite. The default size for sprites is 100 pixels is 1 unit.
The quad is a 3D object and its size is based on what 1 unit is in Unity. In Unity's settings, 1 unit is 1 meter, by default. So, the quad is 1 meter cubed, by default.
If you import a sprite that is 100x100, and keep the default 100 pixels is 1 unit, it should be the same size (with an orthographic camera) as the default quad size.

Sprites reshape unexpectedly

Using Unity 4.6.0 .
I've imported some sprites to my project . I attached an image of one of these sprites (It's only a prefab with SpriteRenderer Component attached to it)
But sometimes Unity reshapes the sprite automatically
And if I change some settings of these sprites like Max Size or Format, then the sprites will be rendered correctly but after a while it will be reshaped again! I don't have any idea about this problem.
This can happen when you parent your sprite to an object that has a scale other than (1, 1, 1). If any object higher up in the hierarchy is scaled it will affect all children including your sprite.
You can either counter the scaling or use Transform.SetParent to do it for you.

How to calculate scale size of sprite object in unity

I have image of sprite having size 90 X 120 and I want to load that image in unity,
Now when I am loading that image it is look like stretch in height and width I am setting scale value of the object but It is look like not proper as I am just doing error and trial method.
can any one tell me how to calculate so the I can load proper image of sprite in scene.
means if my main camera size is 100 and type is orthographic.
and when I create sprite object below are setting which is been given to object
Texture type = Sprite
Sprite Mode = single
Pixel To units = 100
pivot = center
Max size = 1024
Format = 16 Bits
Now can any one tell me if any setting need to change or how to calculate the scale size of sprite as per above info so that sprite look good

Tiling an image that is part of a texture atlas

I'm using Cocos2D. What is the most efficient way to tile an image when it's part of a texture atlas that's been generated using Texture Packer. I have an image that is 10 x 320 and I want to tile it to fill the screen.
I've used this code before for tiling images
bgHolder = [CCSprite spriteWithFile:#"bg.png" rect:CGRectMake(0, 0, 700, 300*155)];
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[bgHolder.texture setTexParameters:&params];
[self addChild:bgHolder];
but I don't think I can use this approach when the image I want to tile isn't square and is only a small part of the over al texture.
Chaining a bunch of CCSprites seems pretty inefficient to me so I'm hoping there is a better way.
Use one sprite per tile. That's the way to do it. You should use sprite batching to keep the number of draw calls to 1. Rendering 48 sprites is not much worse than rendering one 480x320 sprite when using sprite batching.