Java-java中方法中有方法
private void addNewSpriteWithCoords(CGPoint ccp) {
// TODO Auto-generated method stub
CCSpriteSheet sheet = (CCSpriteSheet) getChildByTag(kTagSpriteManager);
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
//just randomly picking one of the images
int idx = (ccMacros.CCRANDOM_0_1() > .5 ? 0:1);
int idy = (ccMacros.CCRANDOM_0_1() > .5 ? 0:1);
//CGRect是在屏幕上绘制矩形
CCSprite sprite = CCSprite.sprite(sheet, CGRect.make(32 * idx,32 * idy,32,32));
//不明白为什么要在sheet中加
sheet.addChild(sprite);
//sprite设置位置 屏幕坐标
sprite.setPosition(ccp);
// Define the dynamic body.
//Set up a 1m squared box in the physics world
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;//小方块会动
bodyDef.position.set(ccp.x/PTM_RATIO, ccp.y/PTM_RATIO);//物理坐标
// Define another box shape for our dynamic body.
PolygonShape dynamicBox = new PolygonShape();
dynamicBox.setAsBox(.5f, .5f);//These are mid points for our 1m box//物理世界上的0.5米
synchronized (world) {
// Define the dynamic body fixture and set mass so it's dynamic.
Body body = world.createBody(bodyDef);
body.setUserData(sprite);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body.createFixture(fixtureDef);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是方法中方法。提示:synchronized块。