Skip to content

Instantly share code, notes, and snippets.

View sag333ar's full-sized avatar

sagar kothari sag333ar

View GitHub Profile
@sag333ar
sag333ar / RegisterTouch
Created September 4, 2014 14:09
Register Touch events in Cocos2d-x
// in .h file
class HelloWorld : public cocos2d::LayerColor
{
public:
bool myTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void myTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void myTouchEnded(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
}
// in .m file
@sag333ar
sag333ar / CreateSprite
Created September 4, 2014 14:17
Create Sprite in Cocos2d-x
// create the sprite
auto spriteLeft = Sprite::create("FortuneWheel.png");
// get the texture size / image size
auto spriteLeftRect = spriteLeft->getTextureRect();
// set the position of sprite
spriteLeft->setPosition(Vec2(visibleSize.width-spriteLeftRect.size.width/2-20 , spriteLeftRect.size.height/2+40));
// add the sprite to scene-layer
@sag333ar
sag333ar / ManageAssetsFor_iDevices
Created September 4, 2014 14:31
Manage assets for iDevices in Cocos2D-x
bool AppDelegate::applicationDidFinishLaunching() {
s_AppDelegate = this;
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}
@sag333ar
sag333ar / AddScrollView
Created September 5, 2014 12:37
Add a scroll-view in cocos2d-x having a layer with scrollable text.
// step 1. include it from extensions.
#include "extensions/GUI/CCScrollView/CCScrollView.h"
// get the screen size
Size visibleSize = Director::getInstance()->getVisibleSize();
// get the origin
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// create a container-layer with white color-background & having 90% of screen size & 1200px vertical size
@sag333ar
sag333ar / UIImage+ScreenShot.m
Created December 1, 2014 08:23
Take screen-shot of UIWindow
- (UIImage *)getTheScreenShotFromWindow
{
// get the window size
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
CGSize size = window.size;
// check the scale - retina or regular
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
else
//
// LocationManager.h
// http://SagarRKothari.com
//
// Created by SagarRKothari on 12/5/14.
//
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
//
// LocationManager.m
// http://SagarRKothari.com
//
// Created by SagarRKothari on 12/5/14.
//
//
#import "LocationManager.h"
@sag333ar
sag333ar / Exercise1.swift
Created August 19, 2015 06:30
Exercise1 : Declaring variables, defining constants. Implicit declaration & explicit declaration of variables.
// declare a variable. variable can keep on changing the values
var myVariable = 42
// modifying variable value
myVariable = 50
// defining constant
let myConstant = 100
// following is an example of implicit declaration of integer variable
@sag333ar
sag333ar / Exercise2.swift
Created August 19, 2015 10:03
Exercise2 : String operation - Inserting values of variables in a string using \()
//: Playground - noun: a place where people can play
// The Swift Programming Language
// iBook Page 6 (13" screen display with full screen)
// Basic string operations
import UIKit
// declare two variables
let apples = 3
let oranges = 5
@sag333ar
sag333ar / Exercise3.swift
Last active August 29, 2015 14:27
Exercise3 : Declaring / modifying / displaying an array. Declaring / modifying / displaying key-valued array. Creating empty array & key-valued empty array.
//: Playground - noun: a place where people can play
// The Swift Programming Language
// Basics of Array & key-valued array
import UIKit
var str = "Hello, playground"
// creating / declaring an array
var shoppingList = ["catfish", "water", "tulips", "blue paint"]