Skip to content

Instantly share code, notes, and snippets.

View dabing1022's full-sized avatar
👨‍💻
Focusing

ChildhoodAndy dabing1022

👨‍💻
Focusing
View GitHub Profile
- (void)turnCard
{
if ([self isFaceUp]) {
[self flipHide];
self.faceUp = NO;
} else {
self.faceUp = YES;
[self flipReveal];
}
}
@dabing1022
dabing1022 / Touch.m
Last active December 17, 2015 02:49
实现触摸
#pragma mark - touch delegate
- (CGPoint)locationFromTouch:(UITouch *)touch
{
CGPoint touchLocation = [touch locationInView:[touch view]];
return [[CCDirector sharedDirector]convertToGL:touchLocation];
}
- (BOOL)containsTouchLocation:(UITouch *)touch
{
CGRect selfRect = CGRectMake(self.position.x, self.position.y, self.contentSize.width, self.contentSize.height);
// Feel free to use. MIT License
#import <Foundation/Foundation.h>
#import "cocos2d.h"
// Layer that will just capture any touch events on it
@interface OpaqueLayer : CCLayerColor {
}
@dabing1022
dabing1022 / CCAnimationAbout.m
Last active December 17, 2015 08:49
CCAnimationAbout
NSMutableArray *frames = [NSMutableArray arrayWithCapacity:4];
for(int i = 0; i < 4; i++){
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"lampMenuAni%d.png",i]];
[frames addObject:frame];
}
CCAnimation *myAnimation = [CCAnimation animationWithSpriteFrames:frames delay:0.15f];
id animate = [CCAnimate actionWithAnimation:myAnimation];
id repeat = [CCRepeatForever actionWithAction:animate];
[sprite runAction:repeat];
#import <Foundation/Foundation.h>
#import "cocos2d.h"
typedef enum {
MainMenuTargetScene,
ClassicTargetScene,
}TargetScenes;
@interface LoadingScene : CCScene {
TargetScenes targetScene;
#import "GameObject.h"
#import "LoadingScene.h"
#import "ClassicGameScene.h"
#import "MainMenuScene.h"
@implementation LoadingScene
+ (id)sceneWithTargetScene:(TargetScenes)target {
return [[[self alloc] initWithTargetScene:target] autorelease];
@dabing1022
dabing1022 / CardFlip
Created November 21, 2013 15:09 — forked from syuhari/CardFlip
void Card::flipAction() {
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite* card = CCSprite::spriteWithFile("card_face.png");
card->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(card, CARD_FACE_TAG, CARD_FACE_TAG);
card->setVisible(false);
CCSprite* card2 = CCSprite::spriteWithFile("card.png");
card2->setPosition(card->getPosition());
@dabing1022
dabing1022 / LuaCoroutine.lua
Created December 21, 2013 06:59
理解LUA协程
-- LUA协程
-- http://my.oschina.net/wangxuanyihaha/blog/186401
-- coroutine.create(f)
-- 函数参数[接受单个参数,这个参数为coroutine的主函数]
-- 函数返回值[返回一个thread对象]
-- 函数作用[创建一个新的协程,协程的主函数定义了该协程内的任务流程]
-- coroutine.resume(co, [, var1, ...])
@dabing1022
dabing1022 / physics-test.lua
Last active August 29, 2015 13:58
quick-cocos2dx-physics-test(2.2.1rc)
local ResourcesData = require("data.ResourcesData")
local scheduler = require("framework.scheduler")
local Bing_ganPhysics = require("data.bing_ganQuick")
local ChipmunkTestScene = class("ChipmunkTestScene", function()
return display.newScene("ChipmunkTestScene")
end)
local GRAVITY = -200
local COIN_MASS = 100
@dabing1022
dabing1022 / changeColor.cpp
Created April 22, 2014 09:28
将图片更改为纯色
CCImage* img = new CCImage();
img->initWithImageFile("A4.png");
unsigned char* data = new unsigned char[img->getDataLen()*4];
CCLOG("data len %d", img->getDataLen());
data = img->getData();
for(int i = 0; i < img->getWidth(); i++)
{