我在游戏中移动了精灵,并在其上添加了标签(CCLabelTTF).标签有A,B,C等字符.我想给标签的内容赋予阴影效果,以便它们可以正常显示.
在.h文件中我有
CCLabelTTF*标签;
并且.mi已经确定了它的位置和颜色."target"是有标签的精灵.
target=[CCSprite spriteWithFile:[NSString stringWithFormat:@"balloon%d.png",enType] rect:CGRectMake(0, 0, 100, 119)];
label = [[CCLabelTTF alloc] initWithString:alphabetValue dimensions:CGSizeMake([target contentSize].width, [target contentSize].height)
alignment:UITextAlignmentCenter fontName:@"verdana" fontSize:30.0f];
//LABEL POSITION HERE
label.position = ccp(55,30);
label.color = ccc3(60,60,60);
[target addChild:label z: 10];
Run Code Online (Sandbox Code Playgroud)
现在我想给阴影效果......我怎么能这样做?
我有一个关于Cocos2D的问题.我在游戏中有两个场景都有很多精灵.当我替换一个场景并加载另一个场景时发生了什么?是否所有的精灵都被自动删除或者它正在记忆中,并且当我在场景中释放时会被释放?
我无法理解这个事情在这种情况下如何处理内存,所以任何人都可以解释我那个事情,更重要的是,当我们在场景中加载精灵时,这对我们来说很重要.
请告诉我是否我弄错了。
锚点就像一个精灵的可移动中心。
您可以通过设置锚点来指定精灵的中心。
现在您可以通过指定中心位置来放置精灵。
例如)
锚点 = (1,1) :精灵的中心是它的右上角(我可以认为它是“固定在右上角”)
position = (screenWidth, screenHeight) :将中心(锚点)放在(屏幕宽度,屏幕高度)
导致在屏幕右上角对齐的精灵。
我的cocos2d-iphone项目有平铺地图(.tmx文件和.png纹理).
最近,我删除了项目中的所有.png纹理(在Xcode中,你点击删除键,然后选择发送到垃圾箱).
然后,我运行了项目,它试图加载CCTMXTiledMap.我原本应该崩溃(不管怎样,项目中不应该有任何纹理),但事实并非如此.事实上,它运行得很好,地图确实加载.不知道为什么 - Xcode是否以某种方式保留了对这些文件的某种引用?
我检查了.tmx文件,这是定义源图像的行:
<image source="myMap-hd.png" width="973" height="1024"/>
Run Code Online (Sandbox Code Playgroud)
我的项目文件夹中肯定没有myMap-hd.png也没有myMap.png文件.甚至没有Xcode的搜索工具栏显示它!
哦,我也清理了这个项目.
我已经看到了相同错误的类似问题.在将代码重构为Arc之后,我得到 Receiver类型'CGPointObject'作为实例消息是一个前向声明错误.建议将@class方法移动到.h文件和#import .h文件的声明,并明智地使用{.
我做了所有的建议,但我仍然得到错误.
CCParallaxNode-Extras.h
#import "cocos2d.h"
@class CGPointObject;
@interface CCParallaxNode (Extras)
-(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node;
@end
Run Code Online (Sandbox Code Playgroud)
CCParallaxNode-Extras.m
#import "CCParallaxNode-Extras.h"
#import "CCParallaxNode.h"
@implementation CCParallaxNode(Extras)
-(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node
{
for( unsigned int i=0;i < parallaxArray_->num;i++) {
CGPointObject *point = parallaxArray_->arr[i];
if( [[point child] isEqual:node] ) {
[point setOffset:ccpAdd([point offset], offset)];
break;
}
}
}
@end
Run Code Online (Sandbox Code Playgroud)
课程定义:CCParallaxNode.m
#import "CCParallaxNode.h"
#import "Support/CGPointExtension.h"
#import "Support/ccCArray.h"
@interface CGPointObject : NSObject
{
CGPoint ratio_;
CGPoint offset_;
CCNode *child_; // weak ref
}
@property (nonatomic,readwrite) CGPoint ratio; …Run Code Online (Sandbox Code Playgroud) 我有一个似乎是一个相当普遍的问题,但我的搜索和解决方案的实现还没有解决.
我已经构建了一个仅用于景观的Cocos2d游戏,但需要访问Gamecenter.Gamecenter正在工作,启用了纵向模式,但它也允许游戏翻转到纵向模式.
我尝试了以下修复:
仅横向应用程序中的GameCenter身份验证会引发UIApplicationInvalidInterfaceOrientation
将GameCenter添加到仅横向cocos2d应用程序后,iOS 6出错
我认为问题在于我使用CCLayers而不是UIViewControllers构建了游戏
示例:MenuLayer.h
@interface MenuLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate, UINavigationControllerDelegate>{
..my header info..
}
Run Code Online (Sandbox Code Playgroud)
MenuLayer.m
...
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate {
return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}
-(void)authenticateLocalPlayer
{
GKLocalPlayer * localPlayer= [GKLocalPlayer localPlayer];
if(localPlayer.authenticated == NO)
{
NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[[GKLocalPlayer localPlayer] setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (viewcontroller != nil) …Run Code Online (Sandbox Code Playgroud) 在scheduleUpdate之后,更新:(ccTime)dt将被调用每秒60次,如果一次更新方法的运行时间超过1/60秒怎么办?下一个电话会被取消吗?
我有这个计时器
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimerFunc) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)
并在一些功能,我想完全删除这......怎么样?
是否可以在selected和notSelected之间以编程方式切换CCMenuItemImage?
谢谢,
克里斯
我有一个关于box2d和cocos2d的问题.我的世界没有引力,我在瓦片基础游戏中工作.我正在使用潜行操纵杆来移动精灵并且它的移动完美但是当我释放指向操纵杆时,我的精灵身体因为一些力量而无法停止.我想在操纵杆释放时停止精灵的移动.
-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player
{
CGPoint scaledVelocity=ccpMult(joysticks.velocity, 2);
NSLog(@"Joystick Velocity X: %f",joysticks.velocity.x);
NSLog(@"Joystick Velocity Y: %f",joysticks.velocity.y);
b2Vec2 force=b2Vec2(scaledVelocity.x/PTM_RATIO,scaledVelocity.y/PTM_RATIO);
ballBody->ApplyLinearImpulse(force, ballBody->GetWorldCenter());
}
Run Code Online (Sandbox Code Playgroud)
这里scaledVelocity值是近似0到1.当我释放操纵杆时,操纵杆的时间值是0.0
请帮助我,因为过去5天我被卡住了.请帮我.
提前致谢
cocos2d-iphone ×10
objective-c ×5
ios ×3
iphone ×3
anchor ×1
box2d-iphone ×1
game-engine ×1
gravity ×1
ios6 ×1
position ×1
xcode ×1
xcode4.2 ×1