小编Cra*_*iss的帖子

Sprite Frame Animation Cocos2d 3.0

我一直在尝试制作一个动画精灵,他们有很多教程,但他们都是为了Cocos2d 2.x. 我的精灵表名为flappbird.png,.plist名为flappbird.plist

我有这个代码,但每次我启动它只是崩溃,这是在我的init方法

// -----------------------------------------------------------------------

_player = [CCSprite spriteWithImageNamed:@"monster1.png"]; // comes from your .plist file
_player.position  = ccp(self.contentSize.width/28,self.contentSize.height/2);
_player.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _player.contentSize} cornerRadius:0]; // 1
_player.physicsBody.collisionGroup = @"playerGroup";
_player.physicsBody.type = CCPhysicsBodyTypeStatic;
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"monster1.png"];
[batchNode addChild:_player];
[self addChild:batchNode];

NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 5; i++)
{
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"flapbird%d.png",i]];
    [animFrames addObject:frame];
}

CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animFrames delay:0.2f];
[_player runAction:[CCActionRepeatForever actionWithAction:[CCActionAnimate actionWithAnimation:animation]]];

[_physicsWorld addChild:_player]; …
Run Code Online (Sandbox Code Playgroud)

objective-c sprite-sheet cocos2d-iphone ios

4
推荐指数
1
解决办法
5817
查看次数

在 Fragment 上显示来自 url 的图像

我环顾了整个互联网,但找不到答案,因为我不断从他们那里收到错误。我正在尝试从 url 制作图片以显示在图像视图中,有什么帮助吗?非常感谢:D

这是我的片段代码

package com.TripleC.twenty20;

import com.TripleC.twenty20.R;
import com.TripleC.twenty20.R.layout;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PagesFragment extends Fragment {

public PagesFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
       Bundle savedInstanceState) {     
       View rootView = inflater.inflate(R.layout.fragment_pages, container, false);
       return rootView;


}   
}
Run Code Online (Sandbox Code Playgroud)

我试试这个

try {
  ImageView i = (ImageView)findViewById(R.id.image);
  Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
  i.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

但它告诉我我不能使用 findviewbyid “方法 findViewById(int) 未定义为 PagesFragment …

eclipse android imageview android-fragments

2
推荐指数
1
解决办法
5751
查看次数

按下按钮时的操作Cocos2d 3.0

我怎么会触发- (void)onRightButtonClicked:(id)sender该按钮时按下,而不是当它已经按下(放开).

这是按钮的代码

rightButton = [CCButton buttonWithTitle:@"" spriteFrame:[CCSpriteFrame frameWithImageNamed:@"right.png"]];
rightButton.position = ccp(self.contentSize.width/3.65, self.contentSize.height/10);
[rightButton setTarget:self selector:@selector(onRightButtonClicked:)];
[self addChild:rightButton];
Run Code Online (Sandbox Code Playgroud)

然后按下按钮后会发生什么.

- (void)onRightButtonClicked:(id)sender
{
CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:walkAnim];
CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction];
[dino runAction:repeatingAnimation];
}
Run Code Online (Sandbox Code Playgroud)

button cocos2d-iphone

2
推荐指数
1
解决办法
2270
查看次数