存档

2012年4月 的存档

CCScrollView for cocos2d-x that works?

2012年4月26日 没有评论

Edit: With enough rewriting, and commenting, I have it running, will post final below for others.

Edit2: I’ve been more updating my own version, and I’ve learned the original coder was not very good with C++, you may want to go over everything in there before using it, check out comments below post

The currently available CCScrollView for cocos2d-x suffers from one major flaw: It’s messed up.

Specifically, the cpp function headers do not match the .h file’s.
The cpp file refers to UIEvent and NSMutableArray, not X-Platform.

The scroll view itself must have an array added, which limits your ability to use a for loop to create your menu items (if creating menu items), since you can’t use a mutable one, and they don’t subclass each other like iOS so you can’t just use a mutable then say CCArray * array = mutable->getMutableArray() or similar.

Also, the defines are outdated (though fixable through adding the CCX_SAFE_DELETE via the translation rules on the cocos2d-x site), and a variety of random templates trying to create NS and UI objects that are not even within the project for I have no clue why.

The basic idea is, aside from the addition of using mutable arrays, this class is way too messed up to bother translating to C++. I don’t believe the author compiled the version he has up, as the headers don’t match. I thought I downloaded both (there’s 2 of each) the cpp and .h files, and both have UIEvent instead of CC along with the other issues.

Note: I have fixed a variety of the above, and changed SelectorProtocol to CCObject in various places, but it’s just getting overwhelming.

Perhaps I should use the Parallax node instead?

This is just ridiculous, perhaps it’s great for Cocos2d but it’s not working on c2d-X. Anyway, I’ll be recoding and searching, thanks for any suggestions!

Edit: Here’s the classes I’m now using. Not done editing, but these will get anyone started, and compiling on more than just iPhone

Header:

#ifndef __CCSCROLLLAYER__
#define __CCSCROLLLAYER__
//  CCScrollLayer.h
//
//  Copyright 2010 DK101
//  http://dk101.net/2010/11/30/implementing-page-scrolling-in-cocos2d/
//
//  Copyright 2010 Giv Parvaneh.
//  http://www.givp.org/blog/2010/12/30/scrolling-menus-in-cocos2d/
//
//  Copyright 2011 Stepan Generalov
//
//  Copyright 2011 Eli Yukelzon
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

// Original source: https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer 
// Last updated: October 1, 2011 

#include "cocos2d.h"

namespace cocos2d {


    class CCScrollLayer;


    class CCScrollLayerDelegate
    {
    public:
        /** Called when scroll layer begins scrolling.
         * Usefull to cancel CCTouchDispatcher standardDelegates.
         */
        virtual void scrollLayerScrollingStarted(CCScrollLayer* sender) {}

        /** Called at the end of moveToPage:
         * Doesn't get called in selectPage:
         */
        virtual void scrollLayerScrolledToPageNumber(CCScrollLayer* sender, unsigned int page) {}
    };

    /* 
     It is a very clean and elegant subclass of CCLayer that lets you pass-in an array 
     of layers and it will then create a smooth scroller. 
     Complete with the "snapping" effect. You can create screens with anything that can be added to a CCLayer.

     */ 
    class CCScrollLayer :   public CCLayer
    {

        int currentScreen; //added
        int totalScreens;
        float scrollWidth;
        float scrollHeight;
        float startWidth;
        float startHeight;
        int startSwipe;

    public:
        //CCScrollLayer();
        ~CCScrollLayer();

        static CCScrollLayer* nodeWithLayers(CCArray* layers, int widthOffset); 

        bool initWithLayers(CCArray* layers, int widthOffset); 

        /** Updates all pages positions & adds them as children if needed.
         * Can be used to update position of pages after screen reshape, or 
         * for update after dynamic page add/remove. 
         */
        void updatePages();

        /** Adds new page and reorders pages trying to set given number for newly added page.
         * If number > pages count - adds new page to the right end of the scroll layer.
         * If number <= 0 - adds new page to the left end of the scroll layer. 
         * @attention Designated addPage method. 
         */
        void addPage(CCLayer* aPage, unsigned int pageNumber);

        /** Adds new page to the right end of the scroll layer. */
        void addPage(CCLayer* aPage);

        /** Removes page if it's one of scroll layers pages (not children)
         * Does nothing if page not found.
         */
        void removePage(CCLayer* aPage);

        /** Removes page with given number. Doesn nothing if there's no page for such number. */
        void removePageWithNumber(unsigned int pageNumber);

        /* Moves scrollLayer to page with given number & invokes delegate
         * method scrollLayer:scrolledToPageNumber: at the end of CCMoveTo action. 
         * Does nothing if number >= totalScreens or < 0.
         */
        void moveToPage(unsigned int pageNumber);

        /* Immedeatly moves scrollLayer to page with given number without running CCMoveTo. 
         * Does nothing if number >= totalScreens or < 0.
         */
        void selectPage(unsigned int pageNumber);

        CC_SYNTHESIZE(CCScrollLayerDelegate*, m_pDelegate, Delegate);

        /** Calibration property. Minimum moving touch length that is enough
         * to cancel menu items and start scrolling a layer. 
         */
        CC_SYNTHESIZE(CGFloat, m_fMinimumTouchLengthToSlide, MinimumTouchLengthToSlide);

        /** Calibration property. Minimum moving touch length that is enough to change
         * the page, without snapping back to the previous selected page.
         */
        CC_SYNTHESIZE(CGFloat, m_fMinimumTouchLengthToChangePage, MinimumTouchLengthToChangePage);

        /** If YES - when starting scrolling CCScrollLayer will claim touches, that are 
         * already claimed by others targetedTouchDelegates by calling CCTouchDispatcher#touchesCancelled
         * Usefull to have ability to scroll with touch above menus in pages.
         * If NO - scrolling will start, but no touches will be cancelled.
         * Default is YES.
         */
        CC_SYNTHESIZE(bool, m_bStealTouches, StealTouches);

        /** Whenever show or not white/grey dots under the scroll layer.
         * If yes - dots will be rendered in parents transform (rendered after scroller visit).
         */
        CC_SYNTHESIZE(bool, m_bShowPagesIndicator, ShowPagesIndicator);

        /** Position of dots center in parent coordinates. 
         * (Default value is screenWidth/2, screenHeight/4)
         */
        CC_SYNTHESIZE_PASS_BY_REF(CCPoint, m_tPagesIndicatorPosition, PagesIndicatorPosition);

        /** Total pages available in scrollLayer. */
        unsigned int getTotalScreens() const;

        /** Current page number, that is shown. Belongs to the [0, totalScreen] interval. */
        CC_SYNTHESIZE_READONLY(unsigned int, m_uCurrentScreen, CurrentScreen);

        /** Offset, that can be used to let user see next/previous page. */
        CC_SYNTHESIZE(CGFloat, m_fPagesWidthOffset, PagesWidthOffset);

        /** Offset that can be used to let user see empty space over first or last page. */
        CC_SYNTHESIZE(CGFloat, m_fMarginOffset, MarginOffset);

        /** Array of pages CCLayer's  */
        CC_SYNTHESIZE_READONLY(CCArray*, m_pLayers, Pages);
    protected:
        // The x coord of initial point the user starts their swipe.
        CGFloat m_fStartSwipe;

        // Internal state of scrollLayer (scrolling or idle).
        int m_iState;
        bool m_bStealingTouchInProgress;
        // Holds the touch that started the scroll
        CCTouch* m_pScrollTouch;

        //void visit();
        //void moveToPageEnded();
        unsigned int pageNumberForPosition(const CCPoint& position);
        CCPoint positionForPageWithNumber(unsigned int pageNumber);
        void claimTouch(CCTouch* pTouch);
        void cancelAndStoleTouch(CCTouch* pTouch, CCEvent* pEvent);

        //void registerWithTouchDispatcher();
        bool ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent);
        void ccTouchMoved(CCTouch* pTouch, CCEvent* pEvent);
        void ccTouchEnded(CCTouch* pTouch, CCEvent* pEvent);
        //void ccTouchCancelled(CCTouch* pTouch, CCEvent* pEvent);
        };
} //end namespace

#endif

CPP

//  CCScrollLayer.cpp
//  Museum
//
//  Created by GParvaneh on 29/12/2010.
//  Copyright 2010. All rights reserved.
//  Ported to C++ by Lior Tamam on 03/04/2011
#include "CCScrollLayer.h"

using namespace cocos2d;

CCScrollLayer* CCScrollLayer::nodeWithLayers(CCArray*  layers, int widthOffset)
{   
    CCScrollLayer *pRet = new CCScrollLayer();
    if (pRet && pRet->initWithLayers(layers, widthOffset))
    {
        pRet->autorelease();
        return pRet;
    }
    CCX_SAFE_DELETE(pRet);
    return NULL;
}

bool CCScrollLayer::initWithLayers(CCArray* layers, int widthOffset)
{   
    if (CCLayer::init())
    {       
        // Make sure the layer accepts touches
        CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);

        // Set up the starting variables
        //if(!widthOffset)
        {
        //  widthOffset = 0;
        }   
        currentScreen = 1;

        // offset added to show preview of next/previous screens
        scrollWidth  = (int)CCDirector::sharedDirector()->getWinSize().width - widthOffset;
        scrollHeight = (int)CCDirector::sharedDirector()->getWinSize().height;
        startWidth = scrollWidth;
        startHeight = scrollHeight;

        // Loop through the array and add the screens
        unsigned int i;
        for (i=0; i<layers->count(); i++)
        {
            CCLayer* l = (CCLayer*)layers->objectAtIndex(i);
            //l->setAnchorPoint(ccp(0,0));
            //l->setPosition(ccp((i*scrollWidth),0));
            addChild(l);            
        }

        // Setup a count of the available screens
        totalScreens = layers->count();
        return true;    
    }
    else
    {
        return false;
    }   
}

void CCScrollLayer::setMaximumScrollHeight(float maxHeight)
{
    //Make the offset match expected pixels (include the current screen if at ccp(0,0)
    maxHeight -= CCDirector::sharedDirector()->getWinSize().height;
    maximumScrollHeight = maxHeight;
}

 CCScrollLayer::~CCScrollLayer()
{
    CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
    CCLayer::onExit();
}

bool CCScrollLayer::ccTouchBegan(CCTouch *touch, CCEvent *withEvent)
{
//  
//  CCPoint touchPoint = touch->locationInView();
//  touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
//  
//  startSwipe = (int)touchPoint.y;
    return true;
}

void CCScrollLayer::ccTouchMoved(CCTouch *touch, CCEvent *withEvent)
{   
    CCPoint touchPoint = touch->locationInView();
    CCPoint prevPoint = touch->previousLocationInView();

    touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
    prevPoint = CCDirector::sharedDirector()->convertToGL(prevPoint);

    CCPoint difference = ccp( touchPoint.x - prevPoint.x , touchPoint.y - prevPoint.y);
    CCPoint currentPos = this->getPosition();

    currentPos = ccp( currentPos.x, currentPos.y+difference.y);

    if (currentPos.y > maximumScrollHeight) 
    {
        currentPos.y = maximumScrollHeight;
        //this->setPositionY(maximumScrollHeight);
    }
    else if (currentPos.y < 0)
    {
        currentPos.y = 0;
       // this->setPositionY(0);
    }
    this->setPosition(currentPos);
}

/*
void CCScrollLayer::ccTouchEnded(CCTouch *touch, CCEvent *withEvent)
{

    //CCPoint touchPoint = touch->locationInView();
    //touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);

    int newX = (int)touchPoint.x;

    if ( (newX - startSwipe) < -scrollWidth / 3 && (currentScreen+1) <= totalScreens )
    {
    //  this->moveToNextPage();
    }
    else if ( (newX - startSwipe) > scrollWidth / 3 && (currentScreen-1) > 0 )
    {
    //  this->moveToPreviousPage();
    }
    else
    {
    //  this->moveToPage(currentScreen);        
    }   

}
*/

Reviving an old thread to add new information, for anyone who found this through a search engine: CCScrollView is now part of the GUI extension and seems to work fairly well. There should be no more need for the implementations referenced above.

Check out the forums on Cocos2d-x’s site for the latest one. They’re being reworked right now by the author based on this.
http://www.cocos2d-x.org/boards/18/topics/1090?r=10835#message-10835

分类: cocos2d, stackoverflow精选 标签:

How to uninstall cocos2d templates?

2012年4月23日 没有评论

Situation:
– Just few hours ago I intalled cocos2d 2.x

– But just before it I delete template files of cocos2d 1.0.1

– Now I can’t see template files of cocos2d 2.x
– In Xcode both of the templates are visible, and I can use them.

Question: How I can delete cocos2d 1.0.1 templates, if I already delete files of this templates? Why I can’t see files of cocos2d 2.x?

Thanks in advance!

Try looking at this link:
http://www.cocos2d-iphone.org/forum/topic/4082
You might need to manually remove the files if all else fails.
Hope it helps! :)

This will be helpful for those who try to reinstall or delete Cocos2D Templates!

  • If you delete all the files from thi path: ~/Library/Application Support/Developer/
  • If you tried to delete it with command in Terminal.app: cd "your path" ./install-templates.sh -u -f
  • If you tried to reinstall Xcode.app

Nothing helps?

I found solution of this problem!

What you need to do is:

  • Open the Finder
  • Press Shift-Command-G
  • Enter the Path: /Users/Your_Username/Library/Developer
  • Press Go
  • Open Xcode Folder
  • Open Templates Folder
  • Delete Cocos2D Folder
  • Open File Templates Folder
  • Delete Cocos2D Folder

That’s all!

P.S As well you can modify the names of templates and tabs in Xcode. Simply just by renaming folders of the templates.

P.P.S By the way right now you can upgrade to Cocos2D 2.x. Download it from here: Cocos2D

For Xcode 5.1 and later

Command+Alt+G (go to) /Users//Library/Developer/Xcode/Templates

Then delete 3d party templates folder.

分类: cocos2d, stackoverflow精选 标签:

2d Mobile Gaming

2012年4月17日 没有评论

I’m looking to create a 2d mobile game (iPhone and Android). Are there any resources that you’re aware of that breakdown the following in depth (yes, I googled it):

  • Corona SDK
  • Cocos 2d
  • Unity
  • GameSalad

As a little background, I’ve been doing iOS programming for ~2 years.

You obviously haven’t done enough research for your question, as googling corona cocos2d unity pulls up a simply excellent comparison of not 3, but 6 game engines. All credit to the author at Burton’s media group for this masterpiece.

I would recommend Cocos2d, as it is, in my opinion, equally or even better than Corona, and it is free.

Some great resources to get you starting off are thenewboston’s video series, which start off as an introduction to cocos2d, and then how to make an RPG. It is a really nice introduction to cocos2d, and helps you understand the programming language. (I am not sure what programming languages you already know)
http://www.youtube.com/playlist?list=PL452AE69EA1EAC535

Have fun

分类: stackoverflow精选, unity3d 标签:

2D Engines for Javascript

2012年4月16日 没有评论

I’m attempting to build a tile-based game in javascript, using HTML5 canvas. There are -many- engines to choose from, such as;

… and the list goes on and on.

However, there does not seem to be one de facto standard among all these different implementations. Essentially I am looking for the ‘jQuery’ of javascript game engines. One that is backed by a (larger) community, has excellent documentation and is actively maintained. Most of these just seem like one-man projects to me.

To phrase this into a real question; what is the de facto standard for 2d game engines in javascript?

Additionally I would be very interested in experiences with actual implementations (other than demo pong / pacman games).

There isn’t one right now and I would go on to say that there may never be one in the same way that there is jQuery, for the simple fact that most (commercial) games are going to want to be mercilessly performant, which means using as little extra cruft as possible, and many of these libraries add unnecessary things or performance hits where it may not be desired.

That is not to say they won’t be used at all, all of the above libraries are probably good for a great deal of small(er) games.

But I imagine on large projects many studios will find themselves starting with a library until they hit a performance wall, and then writing all the components they used in the library themselves in order to keep only the thin bits that they need.

If there is one that becomes popular it will almost certainly be be modular like MooTools (second most popular JS library), where it tries to be compact and lets you select only the components you want to use. I imagine you’ll find a lot of games in the future that have a very small engine just for handling sound or just for handling images or a 2D isomorphic board, instead of games that have a (large) library that attempts to handle every possible kind of 2D game.

Anyway, if you simply want to find the most popular javascript engine then your best bet over the coming months is to use Google (page rank) to determine most popular. Searching for “2D game engines Javascript/Canvas” will give you a pretty good idea of which is the most linked-to (popular) library at any given time.

(After all, try searching Google for “JavaScript Library”. You can guess the first result I bet!)

I agree with the others, there just isn’t a standard, and there might not be for a while. Yet, I’m just starting out myself – and really digging the ThreeJS framework :

http://learningthreejs.com/

https://github.com/mrdoob/three.js/

Sure, it’s a WebGL 3D framework – but I suspect you can strip out the 3D elements to make it 2D? At least that’s my hope as I dig into this world of WebGL – which could end up being the standard moving forward?*

What helps is relying on Chrome Canary for development! :) https://tools.google.com/dlpage/chromesxs

If you’re going this route – don’t forget to set about:flags in Chrome, to enable “Override software rendering list” flag.

Found this question while searching for an engine of my own. I just want to add this site here because it offers a good overview over a lot of HTML5 game engines:

http://html5gameengine.com/

There are also some nice filters like licences/costs, release date and user rating.

(p.s.: I’m not related to this site in any way)

Backbone Game Engine is a 2d framework that was written on top of already popular and large community driven Backbone. Objects, inheritance, events, persistence and so forth come defacto with Backbone. The engine borrows from MelonJS with sprites (Backbone Models) that implement update and draw methods. Super Mario Bros Level 1-1 was written as an example. May be worth your time checking.

“Essentially I am looking for the ‘jQuery’ of javascript game engines.”

http://gamequeryjs.com/

分类: cocos2d, stackoverflow精选 标签:

Adding Colours (Colors) Together like Paint (Blue + Yellow = Green, etc)

2012年4月13日 没有评论

I’m making an iOS game using cocos2d libraries.

Lets say you have two objects that have two separate colours – defined in RGB as

Blue:    0,0,255
Yellow:  255,255,0

I want to add blue and yellow to make green.

To over complicate things, let’s say that the Blue object is bigger than the Yellow object (for the sake of argument let’s say that the ratio is 2:1), I’m adding twice as much blue as yellow – how to I calculate this new (light green) colour correctly.

I understand LAB * Color Space is useful for this sort of ‘natural colour’ kind of thing, but I’m not sure how to use it – especially in the context of a cocos2d object which (AFAIK) is limited to using RGB in its colour schemes.

I’d really appreciate practical help on how to implement this. Thanks heaps!

21/4 Update: So in LAB* blue+yellow ≠ green (which makes sense when you see they’re at opposite ends of the same channel). It’s actually quite a tricky problem with a little bit of discussion on SO. It seems that the ultimate answer is to use the Kubelka-Munk method that a piece of open source software called Krita uses. I can’t find that anywhere (either the formula or the code itself).

This question has a link which uses HSL to work in a similar method to paint. I’m going to try to see if it works, and I’ll feed back the result here.

In the meantime if anyone knows how to implement Kubelka-Munk or where I can find code to do this, or another solution, I would be very, very stoked!

There is no color model where mixing blue and yellow makes green. Try it yourself with gouache, the only way it works is cyan and yellow. This is why you should try switching from RGB to CMYK, and back if you need. Here is how it’s done

void toCMYK(float red, float green, float blue, float* cmyk)
{
  float k = MIN(255-red,MIN(255-green,255-blue));
  float c = 255*(255-red-k)/(255-k); 
  float m = 255*(255-green-k)/(255-k); 
  float y = 255*(255-blue-k)/(255-k); 

  cmyk[0] = c;
  cmyk[1] = m;
  cmyk[2] = y;
  cmyk[3] = k;
}

void toRGB(float c, float m, float y, float k, float *rgb)
{
  rgb[0] = -((c * (255-k)) / 255 + k - 255);
  rgb[1] = -((m * (255-k)) / 255 + k - 255);
  rgb[2] = -((y * (255-k)) / 255 + k - 255);
}

And then in your code, mix the cyan and yellow

float cmyk1[4];
toCMYK(255, 255, 0, cmyk1);  // yellow

float cmyk2[4];
toCMYK(0, 255, 255, cmyk2);  // cyan

// Mixing colors is as simple as adding
float cmykMix[] = { cmyk1[0] + cmyk2[0], cmyk1[1] + cmyk2[1], cmyk1[2] + cmyk2[2], cmyk1[3] + cmyk2[3] };

float rgb[3];
toRGB(cmykMix[0], cmykMix[1], cmykMix[2], cmykMix[3], rgb);  

NSLog(@"RGB mix = (%f, %f, %f)", rgb[0], rgb[1], rgb[2]);

Running the code will yield: RGB mix = (0.000000, 255.000000, 0.000000)

Check the formulas on this site: http://www.easyrgb.com/index.php?X=MATH
I’ve been doing similar thing, and it can be achieved by converting RGB->XYZ->Lab. However the computation is quite expensive(if you doing it for a lot of pixels).

And forget about RGB math when trying to mix colors if you want to obtain results similar to human eye

I think, it is worth to try HSL color space. When adding colors we interpolate their Hue values (even taking in account objects weights). If the colors are 100% saturated, Luminance and Saturation values will be equal.

Dyes don’t work in the real world quite like subtractive-color models suggests. The dyes used for CYMK printing are pretty close, since they’re formulated for that purpose, but many dyes made from naturally-occurring substances can behave somewhat oddly. The difficulty is that while white light is perceived as a combination of red, green, and blue, it actually consists of many different wavelengths–literally “all the colors of the rainbow”–each of which will stimulate the red, green, and blue receptors in the eye by different amounts. It is possible for two colors which appear identical to in fact contain different combinations of wavelengths; likewise, two dyes may appear identical when viewed in white light, but absorb different combinations of wavelengths. Such dyes may look identical to each other when used alone, but may yield very different-seeming results when combined with something else.

Although dyes can sometimes be tricky, however, paints are even worse. Paints contain reflective particles, and some of the light which hits a painted surface will be reflected back off the surface by the first particle it hits; in that regard, they mix like additive colors. For example, if the paint contains 20% green particles, then a significant amount of green light will be reflected, regardless of what other colors it might contain. On the other hand, some of the light which hits a painted surface will bounce around and hit multiple particles. If any of those particles absorbs a photon of some color, that photon won’t be reflected. In that regard, paints behave more like subtractive colors. In practice, paints behave somewhat like additive colors, somewhat like subtractive colors, and sometimes like something weird and wacky and totally unlike either.

Actually it seems that converting RGB->XYZ->LAB does exatly the same thing as RGB->LAB

分类: cocos2d, stackoverflow精选 标签:

Can cocos2d support 4096×4096 texture on Ipad3?

2012年4月11日 没有评论

Ipad1 can only support 2048×2048, so I want to know ipad retina support bigger size texture.
I use cocos2d v1.01

Maximum texture sizes.

iPad 1
iPad 2 < iOS 5.1
2048 * 2048

iPad 2 >= iOS 5.1
iPad 3
4096 * 4096

via @LearnCocos2D

分类: stackoverflow精选, unity3d 标签:

Cocos2D – Particles follow the emitter instead of staying at the position they were released

2012年4月10日 没有评论

In cocos2D I currently have a very simple particle emitter initialized like this:

    turnEmitter = [[CCParticleFlower alloc] init];
    turnEmitter.texture = [[CCTextureCache sharedTextureCache] addImage:@"Pocket.png"];
    [self addChild:turnEmitter z:1];
    turnEmitter.scale = 0.7f;
    turnEmitter.positionType = kCCPositionTypeFree;

It is simply added directly to the gameplay layer.

This emitter follows a sprite around the screen in this way (happens in the update method):

    turnEmitter.position = turnEmblem.position;

Now the problem is that the tail of particles left behind the emitter moves with the emitter, instead of released particles simply staying in the position they were released, which gives a really weird and stupid looking effect.

What I want to do is have the particles not follow the emitter at all after they have been spawned, unfortunately I have been unable to find any way of doing so.

As you can see from the code above I have already searched around, and found people which suggests changing the positionType property of the emitter, although I have tried all the possibilities and it does not solve the problem.

Does anyone have any ideas as to what this might be?

You may want to try changing the “emitterMode” as well to “kCCPositionTypeFree”. I had a similar issue where i had the emitter as a child of a CCNode. The CCNode was being rotated, but the particles and emitter wasn’t. In the same way it looked stupid because the illusion of rotation was ruined. I need to set the following on my emitter:

emitter.emitterMode = kCCPositionTypeRelative;
emitter.positionType = kCCPositionTypeRelative;
分类: stackoverflow精选, unity3d 标签:

2-Dimension array of List in C#?

2012年4月8日 没有评论

I just want get a 2 dimension array of List in c#. In my thought, below should works but it didn’t, the 1 dimension array of List works. I use Unity3D with Mono, however I think it’s language related problem.

List<MyType>[,] twoDArrayofList;//don't work, it's type is List<MyType>
List<MyType>[] oneDArrayofList;//it's works, the type is List<MyType>

Anyone know what’s wrong? Thank you.

What do you mean by “doesn’t work”? What error are you getting?

I don’t know about Mono (or Unity3D), but I just tried the following in a .NET project and got the results I expected:

List<string>[,] strings = new List<string>[2, 2];
strings[0, 0] = new List<string> { "One" };
strings[0, 1] = new List<string> { "Two" };
strings[1, 0] = new List<string> { "Three" };
strings[1, 1] = new List<string> { "Four" };

This is an older post, but it came up in my search for a similar answer. I found that creating a Dictionary instead of a List meets my needs. You can’t iterate by index, but if you have a discrete list and you are iterating through the first string “Key”, you can easily obtain the second string “Value”.

Here is a stackoverflow post with examples:
What is the best way to iterate over a Dictionary in C#?

分类: stackoverflow精选, unity3d 标签:

Can Unity and Flash communicate between eachother if they coexists in the browser?

2012年4月3日 没有评论

In other words, can Flash trigger methods in Unity if both are present on a webpage, and both are setup with some exposed methods to talk to eachother?

Would JavaScript be the middle-man doing the communication between the two?

I’m thinking that Flash would use ExternalInterface and Unity would use something else (I’m not familiar enough with it).

Just curious if that would be possible, in theory.

Thanks!

Looks like unity has methods for talking to JavaScript, similar to as3. It would definitely be possible using JS

Application.ExternalCall( "SayHello", "The game says hello!" );

http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html

分类: stackoverflow精选, unity3d 标签: