Rotated Clipping Node in Cocos2d - cocos2d-iphone

I'm using the clipping node here: http://www.learn-cocos2d.com/2011/01/cocos2d-gem-clippingnode
ClippingNode.h
#import "cocos2d.h"
#interface ClippingNode : CCNode {
CGRect clippingRegionInNodeCoordinates;
CGRect clippingRegion;
}
#property (nonatomic) CGRect clippingRegion;
#end
ClippingNode.m
#import "ClippingNode.h"
#interface ClippingNode (PrivateMethods)
-(void) deviceOrientationChanged:(NSNotification*)notification;
#end
#implementation ClippingNode
-(CGRect) clippingRegion {
return clippingRegionInNodeCoordinates;
}
-(void) setClippingRegion:(CGRect)region {
// keep the original region coordinates in case the user wants them back unchanged
clippingRegionInNodeCoordinates = region;
self.position = clippingRegionInNodeCoordinates.origin;
self.contentSize = clippingRegionInNodeCoordinates.size;
// convert to retina coordinates if needed
region = CC_RECT_POINTS_TO_PIXELS(region);
// respect scaling
clippingRegion = CGRectMake(region.origin.x * scaleX_, region.origin.y * scaleY_,
region.size.width * scaleX_, region.size.height * scaleY_);
}
-(void) setScale:(float)newScale {
[super setScale:newScale];
// re-adjust the clipping region according to the current scale factor
[self setClippingRegion:clippingRegionInNodeCoordinates];
}
-(void) deviceOrientationChanged:(NSNotification*)notification {
// re-adjust the clipping region according to the current orientation
[self setClippingRegion:clippingRegionInNodeCoordinates];
}
-(void) visit {
glEnable(GL_SCISSOR_TEST);
CGPoint worldPosition = [self convertToWorldSpace:CGPointZero];
const CGFloat s = [[CCDirector sharedDirector] contentScaleFactor];
glScissor((clippingRegion.origin.x) + (worldPosition.x*s), (clippingRegion.origin.y) + (worldPosition.y*s),
(clippingRegion.size.width), (clippingRegion.size.height));
[super visit];
glDisable(GL_SCISSOR_TEST);
}
#end
However, I need to clip a rotated CCNode. Any idea on how I could accomplish such a task?

Replace the visit method in the class ClippingNode by this
-(void) visit
{
float rotationAngle = 15;
glPushMatrix();
CCRenderTexture* renderTexture = [[CCRenderTexture renderTextureWithWidth:512 height:512] retain];
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, clippingRegion.size.width, clippingRegion.size.height);
[renderTexture begin];
glPushMatrix();
glRotatef(rotationAngle, 0, 0, 1);
glTranslatef(-clippingRegion.origin.x, -clippingRegion.origin.y, 0);
[super visit];
glPopMatrix();
[renderTexture end];
glDisable(GL_SCISSOR_TEST);
renderTexture.sprite.position = CGPointMake(clippingRegion.origin.x , clippingRegion.origin.y);
renderTexture.sprite.anchorPoint = CGPointMake(0, 1);
renderTexture.sprite.rotation = rotationAngle;
[renderTexture.sprite visit];
[renderTexture release];
glPopMatrix();
}
Basically it creates a texture where to render the ClippingNode contents
Then translate the scene so that the origin in the clipping region is now at (0,0)
Rotate the entire scene by rotationAngle
Enable the scissor
Render the scene
Translate, rotate, and render the sprite containing the texture

It only needs CCRenderTexture to finish the job. Any suggestion will be greatly appreciated.
ClippingNode.h
#import "cocos2d.h"
#interface ClippingNode : CCNode
#property (nonatomic, assign) CGSize clippingSize;
#end
ClippingNode.m
#import "ClippingNode.h"
#interface ClippingNode()
#property (nonatomic, strong) CCRenderTexture * renderTexture;
#property (nonatomic, strong) CCSprite * clippedSprite;
#end
#implementation ClippingNode
#synthesize renderTexture;
#synthesize clippedSprite;
#synthesize clippingSize;
- (void) setClippingSize:(CGSize)newClippingSize {
//assignment
clippingSize = newClippingSize;
//set contentSize
self.contentSize = clippingSize;
//configure renderTexture
self.renderTexture = [CCRenderTexture renderTextureWithWidth:clippingSize.width height:clippingSize.height];
renderTexture.contentSize = CGSizeMake(clippingSize.width, clippingSize.height);
//configure the renderTexture sprite
self.clippedSprite = [CCSprite spriteWithTexture:renderTexture.sprite.texture];
clippedSprite.position = self.position;
clippedSprite.rotation = rotation_;
clippedSprite.scaleY = -1;
}
- (void)visit {
[renderTexture beginWithClear:0 g:0 b:0 a:1];
[super visit];
[renderTexture end];
[clippedSprite visit];
}
#end
Usage:
CCSprite * spriteImage = ...;
spriteImage.position = ccp(0,0);
spriteImage.anchorPoint = ccp(0.5,0.5);
//configure clipping Node
self.clippingNode = [ClippingNode node];
clippingNode.position = ccp(size.width * 0.5f, size.height * 0.5f);
clippingNode.anchorPoint = ccp(0.5f, 0.5f);
clippingNode.rotation = -10.0f;
//configure clipping region
[clippingNode setClippingSize:CGSizeMult(spriteImage.boundingBox.size, 1.5f)];
//add content to the clipping node
[clippingNode addChild:spriteImage]

Related

CCSpriteBatchNode is deprecated Cocos2d 3.1

I have a problem following a tutorial for cocos2d 3.0 in cocos2d 3.1 ... when compilation finish show a warning "CCSpriteBatchNode is deprecated", how can I use the plist now? or isn't used now in cocos2d 3.1? can you write an example, would very helpful :)
#implementation GameScene
{
CCSpriteBatchNode *_batchNode; // WARNING 1 HERE
Hunter *_hunter;
Bird *_bird;
}
-(void)addBackground
{
//1
CGSize viewSize = [CCDirector sharedDirector].viewSize;
//2
CCSprite *background = [CCSprite spriteWithImageNamed:#"game_scene_bg.png"];
//3
background.position = ccp(viewSize.width * 0.5f, viewSize.height * 0.5f);
//4
[self addChild:background];
}
-(void)createBatchNode {
//1
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"Cocohunt.plist"];
//2
_batchNode = [CCSpriteBatchNode batchNodeWithFile:#"Cocohunt.png"]; // WARNING 2 HERE
//3
[self addChild:_batchNode z:1];
}
In version 3.1, the cocos2d renderer was re-made to automatically batch drawn sprites. So CCSpriteBatchNode is no longer needed, just use a CCNode.
#implementation GameScene
{
CCNode *_batchNode; // WARNING 1 HERE
Hunter *_hunter;
Bird *_bird;
}

How to make stretch body(trigger) and apply physics on it in box2d in iphone?

I want to make trigger so that user can stretch the trigger and give the direction and then trigger hit to the ball and the ball will go accordingly.
The Ball speed and direction will depend on the trigger.
I am new in box2d.
Please check the link what I want.
http://dc694.4shared.com/img/Nw7YYLNL/s7/pool.png?async&0.2852371991612017
-(id) init
{
if( (self=[super init])) {
CGSize winSize = [CCDirector sharedDirector].winSize;
// Create a world
b2Vec2 gravity = b2Vec2(0.0f, 0.0f);
_world = new b2World(gravity);
// Create sprite and add it to the layer
CCSprite *Trigger = [CCSprite spriteWithFile:#"Trigger.png"];
Trigger.position = ccp(10, 50);
Trigger.tag = 1;
[self addChild:Trigger];
// Create Trigger body
b2BodyDef TriggerBodyDef;
TriggerBodyDef.type = b2_dynamicBody;
TriggerBodyDef.position.Set(127/PTM_RATIO, 210/PTM_RATIO);
TriggerBodyDef.userData = ball;
TriggerBody = _world->CreateBody(&TriggerBodyDef); // b2Body * ballBody
// Create circle shape
b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;
// Create shape definition and add to body
b2FixtureDef TriggerShapeDef;
TriggerShapeDef.shape = &circle;
TriggerShapeDef.density = 15.0f;
TriggerShapeDef.friction = 2.f;
TriggerShapeDef.restitution = 0.0f;
_TriggerFixture = TriggerBody->CreateFixture(&TriggerShapeDef);
b2Vec2 force = b2Vec2(10, -12);
TriggerBody->ApplyLinearImpulse(force, TriggerBodyDef.position);
///////////////////////// Ball ///////////////////////////////
// Create sprite and add it to the layer
CCSprite *ball = [CCSprite spriteWithFile:#"ball.png"];
ball.position = ccp(100, 200);
ball.tag = 1;
[self addChild:ball];
// Create ball body
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(127/PTM_RATIO, 210/PTM_RATIO);
ballBodyDef.userData = ball;
ballBody = _world->CreateBody(&ballBodyDef); // b2Body * ballBody
// Create circle shape
b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;
// Create shape definition and add to body
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 15.0f;
ballShapeDef.friction = 2.f;
ballShapeDef.restitution = 0.0f;
_ballFixture = ballBody->CreateFixture(&ballShapeDef);
b2Vec2 force = b2Vec2(73, -52);
ballBody->ApplyLinearImpulse(force, ballBodyDef.position);
//ballBody->SetLinearVelocity(b2Vec2(10,0)); // try
// ballBody->SetAngularVelocity(0); // try
///////////////////////// Ball ///////////////////////////////
// Create paddle and add it to the layer
CCSprite *paddle = [CCSprite spriteWithFile:#"paddle.png"];
paddle.position = ccp(winSize.width/2, 50);
[self addChild:paddle];
// Create paddle body
b2BodyDef paddleBodyDef;
paddleBodyDef.type = b2_staticBody; //b2_staticBody, b2_dynamicBody
paddleBodyDef.position.Set(winSize.width/2/PTM_RATIO, 50/PTM_RATIO);
paddleBodyDef.userData = paddle;
paddleBodyDef.angle = 75;
_paddleBody = _world->CreateBody(&paddleBodyDef);
// Create paddle shape
b2PolygonShape paddleShape;
paddleShape.SetAsBox(paddle.contentSize.width/PTM_RATIO/2, paddle.contentSize.height/ PTM_RATIO/2);
// Create shape definition and add to body
b2FixtureDef paddleShapeDef;
paddleShapeDef.shape = &paddleShape;
paddleShapeDef.density = 25.0f;
paddleShapeDef.friction = 1.1f;
paddleShapeDef.restitution = 0.1f;
_paddleFixture = _paddleBody->CreateFixture(&paddleShapeDef);
// Restrict paddle along the x axis
b2PrismaticJointDef jointDef;
b2Vec2 worldAxis(0.0f, 0.0f);
jointDef.collideConnected = true;
jointDef.Initialize(_paddleBody, _groundBody, _paddleBody->GetWorldCenter(), worldAxis);
_world->CreateJoint(&jointDef);
[self schedule:#selector(tick:)];
self.touchEnabled = YES;
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (_mouseJoint != NULL) return;
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
if (_paddleFixture->TestPoint(locationWorld)) {
b2MouseJointDef md;
md.bodyA = _groundBody;
md.bodyB = _paddleBody;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 1000.0f * _paddleBody->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
_paddleBody->SetAwake(true);
}
// [self kick];
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (_mouseJoint == NULL) return;
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
_mouseJoint->SetTarget(locationWorld);
}
I am not able to make trigger and not able to apply physics on trigger image. How to apply physics on trigger body? And how the ballbody will move according to trigger?
I have implemented this as follow:
HelloWorldLayer.h
#import "cocos2d.h"
#import "Box2D.h"
#define PTM_RATIO 32.0
#interface HelloWorldLayer : CCLayer {
b2World *_world;
b2Body *_body;
CCSprite *_ball;
CGPoint firstlocation;
CGPoint lastlocation;
b2Vec2 pre_velocity;
}
+ (id) scene;
- (void)kick;
#end
HelloWorldLayer.m
#import "HelloWorldLayer.h"
#implementation HelloWorldLayer
+ (id)scene {
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
[scene addChild:layer];
return scene;
}
- (id)init {
if ((self=[super init])) {
CGSize winSize = [CCDirector sharedDirector].winSize;
_ball = [CCSprite spriteWithFile:#"ball.png" rect:CGRectMake(0, 0, 52, 52)];
_ball.position = ccp(100, 100);
[self addChild:_ball];
//create world
b2Vec2 gravity = b2Vec2(0.0f, -8.0f);
_world = new b2World(gravity);
// Create ball body and shape
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(26/PTM_RATIO, 26/PTM_RATIO);
ballBodyDef.userData = _ball;
_body = _world->CreateBody(&ballBodyDef);
b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 0.2f;
ballShapeDef.restitution = 0.8f;
_body->CreateFixture(&ballShapeDef);
//ground edge
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
b2Body *groundBody = _world->CreateBody(&groundBodyDef);
b2EdgeShape groundEdge;
b2FixtureDef boxShapeDef;
boxShapeDef.shape = &groundEdge;
//wall definitions
groundEdge.Set(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0));
groundBody->CreateFixture(&boxShapeDef);
groundEdge.Set(b2Vec2(0,0), b2Vec2(0,winSize.height/PTM_RATIO));
groundBody->CreateFixture(&boxShapeDef);
groundEdge.Set(b2Vec2(0, winSize.height/PTM_RATIO),
b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO));
groundBody->CreateFixture(&boxShapeDef);
groundEdge.Set(b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO),
b2Vec2(winSize.width/PTM_RATIO, 0));
groundBody->CreateFixture(&boxShapeDef);
[self schedule:#selector(tick:)];
// [self schedule:#selector(kick) interval:3.0];
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = YES;
}
return self;
}
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
b2Vec2 gravity(acceleration.y * 30, -acceleration.x * 30);
_world->SetGravity(gravity);
}
- (void)tick:(ccTime) dt {
_world->Step(dt, 10, 1);
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *ballData = (CCSprite *)b->GetUserData();
ballData.position = ccp(b->GetPosition().x * PTM_RATIO,
b->GetPosition().y * PTM_RATIO);
ballData.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
}
- (void)kick {
b2Vec2 force = b2Vec2(-30, 30);
_body->ApplyLinearImpulse(force,_body->GetPosition());
}
- (void)ccTouchesBegan:(NSSet *)touch withEvent:(UIEvent *)event {
/* b2Vec2 force = b2Vec2(-30, -30);
_body->ApplyLinearImpulse(force, _body->GetPosition());*/
UITouch *touchpoint = [touch anyObject];
firstlocation = [touchpoint locationInView:[touchpoint view]];
firstlocation = [[CCDirector sharedDirector] convertToGL:firstlocation];
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touchpoint = [touches anyObject];
lastlocation = [touchpoint locationInView:[touchpoint view]];
lastlocation = [[CCDirector sharedDirector] convertToGL:lastlocation];
//NSLog(#"start location %2f %2f",firstlocation.x,firstlocation.y);
//NSLog(#"last location %2f %2f",lastlocation.x,lastlocation.y);
GLfloat y = firstlocation.y - lastlocation.y;
GLfloat x = firstlocation.x - lastlocation.x;
GLfloat lengthOfFlick = sqrt(x*x + y*y);
NSLog(#"%2f",lengthOfFlick);
/* GLfloat basAngle = atan2(-x, -y);
GLfloat radians = (basAngle + (180/3.14));
//GLfloat angle = 180 + radians;*/
//GLfloat theta = atan2(y,x)* 180 / 3.14;
//NSLog(#"theta: %2f",theta);
float ratio = lengthOfFlick/90;
NSLog(#"%f",ratio);
if(ratio > 1){
ratio = 1;
}
NSLog(#"%f",ratio);
if(firstlocation.x > lastlocation.x){
if(firstlocation.y > lastlocation.y){
b2Vec2 force = b2Vec2((int)(45 * ratio),(int)(45 * ratio));
_body->ApplyLinearImpulse(force, _body->GetPosition());
}else{
b2Vec2 force = b2Vec2((int)( -1 * 45 * ratio), (int)(45 * ratio));
_body->ApplyLinearImpulse(force, _body->GetPosition());
}
}else{
if(firstlocation.y > lastlocation.y){
b2Vec2 force = b2Vec2((int)( -1 * 45 * ratio),(int)(45 * ratio));
_body->ApplyLinearImpulse(force, _body->GetPosition());
}else{
b2Vec2 force = b2Vec2((int)(-1* 45 * ratio),(int)(-1 * 45 * ratio));
_body->ApplyLinearImpulse(force, _body->GetPosition());
}
}
}
-(void)dealloc{
delete _world;
_body = NULL;
_world = NULL;
[super dealloc];
}
#end
Or you can download this code from:4shared.com/zip/PRv8c1Pz/BOX2D.html

Making a hole on a CCRenderTexture

I am trying to make a hole on a CCRenderTexture with Cocos2D 2.0.
More specifically I have:
a CCSprite "stars" that shows some stars repeating a png image;
on top of that I have a CCRenderTexture "dark" that completely covers the "stars" sprite.
I want to be able to cut a hole on "dark" in order to show the stars below.
I am using CCRenderTexture (as suggested in some tutorials) but the hole I manage to make is never fully transparent, so the stars visible through the hole are partially obscured.
I really hope some one can show me the light, I spent over a week on this...
This is the code:
#interface MyBackgroundLayer : CCLayerGradient {
}
#end
#implementation MyBackgroundLayer
CCRenderTexture * dark;
CCSprite * stars;
-(id) init
{
if (self=[super init]) {
CGSize size = [[CCDirector sharedDirector] winSize];
// background
stars = [CCSprite spriteWithFile:#"stars.png" rect:CGRectMake(0, 0, size.width, size.height)];
stars.anchorPoint = ccp(0,0);
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[stars.texture setTexParameters:&params];
[self addChild:stars];
// dark layer to cover the background
dark = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
[dark clear:0 g:0 b:0 a:1.0f];
[self addChild: dark];
dark.position = ccp(size.width/2,size.height/2);
[[dark sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];
}
return self;
}
-(void)draw
{
[super draw];
[dark beginWithClear:0 g:0 b:0 a:1];
glColorMask(0, 0, 0, 1);
// Here I am using 0.5 as alpha value, this could seems the reason why the hole is not fully transparent.
// However if I change the alpha value to 1.0f or 0.0f the hole becomes completely opaque
ccColor4F color = ccc4f(1.f, 1.f, 1.f, 0.5f);
ccDrawSolidRect(ccp(0,0), ccp(600, 600), color);
glColorMask(1,1,1,1);
[dark end];
}
#end
I think what you're looking for is something like this ( may need some editing).
As for your code ..i thing the problem is in the blend function. Check this out to see how they work.

Cocos2D - remove layer opacity on region

I got a Scene with a layer with the top z-index wich one adds a dark effect to the whole scene setting its opacity. What i am trying to do now is to remove the shadow/dark effect in a concrete region (inside a cone/triangle) as the image shows (inside the red polygon). In other words, i want to have the same "luminosity" (zero opacity) inside the triangle as on the left side of the screen.
code:
-(id) init
{
if( (self=[super initWithColor:ccc4(0,0,0,128)] )) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCLayerColor* layer1 = [CCLayerColor layerWithColor: ccc4(0, 0, 0, 180) width: winSize.width height: winSize.height];
layer1.position = ccp(50,0);
[self addChild: layer1 z:2];
CCSprite *background = [CCSprite spriteWithFile:#"background.png"];
background.position = ccp(background.contentSize.width/2, background.contentSize.height/2);
[self addChild:background];
CCSprite *player = [CCSprite spriteWithFile:#"Player.png"rect:CGRectMake(0, 0, 27, 40)];
player.position = ccp(player.contentSize.width/2, winSize.height/2);
[self addChild:player];
}
return self;
}
any idea on how to do this ?? maybe i should try to do it on another whay and not use a CCLayer to add the dark effect ??
Thanks in advance
The simplest way would be to use a CCSprite with a black image the size of the background. Then cut out the whole you need in an image program and draw that sprite over the background with lowered opacity.

vertices smaller than sprite when rendered on iPhone screen

I am using vertex helper to get the edges of my sprites. I am using Cocos2d + Box2d on the iPhone. The problem I am getting is that the debug draw on the device I am testing on comes up but the vertices rendered or shown is smaller than my sprites even after tracing the edges of the sprites carefully and using the same sprite.
OK here is a screen shot of the problem!
The green triangle is supposed to fit with the edges of the sprite. Also this is the code I used:
This is the GLESDebugDraw code
- (void)setupDebugDraw {
debugDraw = new GLESDebugDraw(PTM_RATIO* [[CCDirector sharedDirector]
contentScaleFactor]);
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(b2DebugDraw::e_shapeBit);
}
#import "Box2DSprite.h"
#interface Stalag :Box2DSprite {
b2World *world;
}
- (id)initWithWorld:(b2World *)world atLocation:(CGPoint)location;
#end
#import "Stalag.h"
#implementation Stalag
- (void)createBodyAtLocation:(CGPoint)location {
b2BodyDef bodyDef;
bodyDef.type = b2_staticBody;
bodyDef.position = b2Vec2(location.x/PTM_RATIO,
location.y/PTM_RATIO);
self.body = world->CreateBody(&bodyDef);
body->SetUserData(self);
b2PolygonShape shape;
int num = 8;
b2Vec2 verts[] = {
b2Vec2(36.8f / 100.0, -79.2f / 100.0),
b2Vec2(10.3f / 100.0, 33.2f / 100.0),
b2Vec2(1.8f / 100.0, 80.6f / 100.0),
b2Vec2(-4.6f / 100.0, 84.5f / 100.0),
b2Vec2(-8.5f / 100.0, 80.3f / 100.0),
b2Vec2(-22.6f / 100.0, 19.4f / 100.0),
b2Vec2(-31.8f / 100.0, -45.6f / 100.0),
b2Vec2(-37.5f / 100.0, -75.7f / 100.0)
};
shape.Set(verts, num);
b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;
fixtureDef.density = 1000.0;
body->CreateFixture(&fixtureDef);
}
- (id)initWithWorld:(b2World *)theWorld atLocation:(CGPoint)location {
if ((self = [super init])) {
world = theWorld;
[self setDisplayFrame:[[CCSpriteFrameCache
sharedSpriteFrameCache] spriteFrameByName:#"hill.png"]];
gameObjectType = kStalagupType;
[self createBodyAtLocation:location];
}
return self;
}
#end
Please can anyone tell me what do I do and what I am doing wrong?
Thanks
When specifying vertices coordinates you are dividing it by a "magic number" 100. Actually it is your PixelToMetersRatio (PTM_RATIO in cocos examples). Also you are using box2d debug draw. And when creating debug draw class your must pass PTM_RATIO in it's constructor. I think you are passing another number there (not 100). Does it solve the problem ?