달력

10

« 2024/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
http://www.cocos2d-iphone.org/forum/topic/4219

I decided to use a category to work-around this issue. Create a class called "CCMoveTo+RoundedUpdate" and add this code:

CCMoveTo+RoundedUpdate.h

//
//  CCMoveTo+RoundedUpdate.h
//
//	Category to rounded move any object and avoid gaps in tilemap.
//  --> Overrides "update" code from CCIntervalAction.m
//
//  Created by Markus Barta on 09.02.10.
//
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface CCMoveTo (RoundedUpdate)
@end

CCMoveTo+RoundedUpdate.m

//
//  CCMoveTo+RoundedUpdate.m
//
//  Created by Markus Barta on 09.02.10.
//
#import "CCMoveTo+RoundedUpdate.h"

@implementation CCMoveTo (RoundedUpdate)
-(void) update: (ccTime) t
{
	//NSLog(@"Using category CCMoveTo+RoundedUpdate for movement -> rounded setPosition!");
	[target setPosition: ccp( round(startPosition.x + delta.x * t ), round(startPosition.y + delta.y * t ) )]; //Setting to a rounded pos avoids gaps in tilemap!
}
@end

Just add those two files to your project and compile. The gaps should be gone :)


:
Posted by netkorea
http://www.cocos2d-iphone.org/forum/topic/7927

That's a fun one... I had to sit down with some graph paper and math and spend a while working it out, I wanted a simple solution that would work in all cases no matter the map size. Hope this saves you some time.

I use multiple ISO map sizes and the touchToXY is in my base map class, it works no matter the map size it will always return the X,Y. Top most tile of the diamond being 0,0.

Here is my solution:

-(CGPoint)touchToXY:(CGPoint)touch map:(CCTMXTiledMap *)_map mapsize:(int)_mapsize
{
	touch = [[CCDirector sharedDirector] convertToGL:touch];
	touch = [_map convertToNodeSpace:touch];
	CGSize ts = [_map tileSize];
	int isoy = (((touch.y/ ts.height) + (touch.x - (_mapsize * ts.width/2)) / ts.width) - _mapsize) *-1;
	int isox = (((touch.y/ ts.height) - (touch.x - (_mapsize * ts.width/2)) / ts.width) -_mapsize) *-1;
	return ccp(isox,isoy);
}

To call it:

Variables you need to define are

<CCTMXTiledMap> = Your Tile Map
<MapWidthInTiles> = How big is the grid.  20 if it's 20x20, 30 if it's 30x30 etc..

Call from your touch code:

CGPoint myTouch = [touch locationInView: [touch view]];
CGPoint isoXY = [self touchToXY:myTouch map:<CCTMXTiledMap> mapsize:<MapWidthInTiles>];
Posted 2 months ago #

:
Posted by netkorea
http://www.cocos2d-iphone.org/forum/topic/7817

I've been playing around with path finding and tilemaps along with the latest release of cocos2d-iPhone - and I posted a sample app in hopes that it saves someone else some time - or if anyone has comments to optimize/improve this code (I'm sure that won't be difficult as I wasn't shooting for optimization, just trying to learn).

I started with two great tutorials:

Ray Wenderlich's cocos2d-iphone tile map tutorial:
http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

and BravoBug's A-Star sample program:
http://bravobug.com/news/?p=118

My sample app loads a tile map that contains a start point, an end point, and walls, and detects (and graphically displays) a path between the start and end points. You can select whether or not you want to allow diagonal movements. Anyway, here's the link. I hope someone finds it useful:

http://dl.dropbox.com/u/3729313/PathFinder.zip

Cheers,
Kevin


:
Posted by netkorea

http://www.iphonedevsdk.com/forum/iphone-sdk-development/52507-user-resize-image-screen.html
Unread 07-07-2010, 10:18 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 22
Default

Quote:
Originally Posted by mitchsamuels View Post
Hello, I have an image on my view that is draggable. How can I make it so the user is able to resize the image on the screen by pinching.
Easiest way to do that is to use UIGestureRecognizer. That is new to iPhone OS 3.2 (or iOS4 for iPhones).

Basically, you make a UIPinchGestureRecognizer and add it to your view, and in UIGestureRecognizer you register for a callback. When that is done, when the user has started pinching, it will not only callback, but the UIPinchGestureRecognizer will give you a scale by how much, which you can immediately translate into a scale.

Relevant Text:

UIGestureRecognizer Documentation
:
Posted by netkorea