void LayerEditScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if(!event->buttons() & Qt::LeftButton) {
        return;
    }

    if((event->scenePos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
        return;
    }

    qDebug() << "LayerEditScene::mouseMoveEvent - Starting a drag";

    // Get the pixmap item related to the start of the drag.
    QGraphicsItem *item = itemAt(_dragStartPosition, QTransform());
    if(item == 0) {
        // Couldn't find an item at the location for some reason.
        qDebug() << "LayerEditScene::mouseMoveEvent - Could not find a sprite at the drag location.";
        return;
    }

    // Static cast is safe because this scene only adds QGraphicsPixmapItem
    QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem *>(item);

    // Remove item from scene
    Sprite sprite = _pixmapToSprite[pixmapItem]; // Save sprite before it's removed.
    qDebug() << "LayerEditScene::mouseMoveEvent - Dragging " << sprite.getFileInfo().fileName();

    int index = _previews.indexOf(pixmapItem);
    if(index != -1) {
        removeSprite(index);
        recalculatePositions();
    }

    // Create a new drag event and put the source image into the mime data.
    QDrag *drag = new QDrag((QObject *)event->widget());
    QMimeData *data = new QMimeData();
    data->setImageData(sprite.getTexture());
    data->setText(sprite.getFileInfo().absoluteFilePath());
    drag->setMimeData(data);

    // Put the pixmap that was selected onto the cursor
    QPixmap pixmap = pixmapItem->pixmap();
    drag->setPixmap(pixmap);
    drag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2));

    // Execute the drag with a move action.
    qDebug() << "LayerEditScene::mouseMoveEvent - Executing drag as MoveAction";
    Qt::DropAction action = drag->exec(Qt::MoveAction, Qt::MoveAction);

    if(action != Qt::MoveAction) {
        // Put sprite back
        qDebug() << "LayerEditScene::mouseMoveEvent - Move action failed, putting sprite back where it was.";
        insertSprite(index, sprite);
        recalculatePositions();
    } else {
        // Delete the old item
        qDebug() << "LayerEditScene::mouseMoveEvent - Move succeeded, deleting old sprite.";
        delete pixmapItem;
    }
}
Esempio n. 2
0
void Sprite::setZIndex(float new_z_index){
  beginFrame();
  removeSprite(this);
  z_index = new_z_index;
  addSprite(this);
  endFrame();
}
Esempio n. 3
0
void wySpriteBatchNode::removeChild(wyNode* child, bool cleanup) {
    wySpriteEx* sprite = dynamic_cast<wySpriteEx*>(child);
    if(!sprite || sprite->getParent() != this) {
        return;
    }
    removeSprite(sprite);
	wyNode::removeChild(child, cleanup);
}
Esempio n. 4
0
int wySpriteBatchNode::reorderChild(wyNode* child, int z) {
    wySpriteEx* spriteEx = dynamic_cast<wySpriteEx*>(child);
    if(!spriteEx || spriteEx->getParent() != this) {
        return -1;
    }
    int ret = wyNode::reorderChild(child, z);
    removeSprite(spriteEx);
    addSprite(spriteEx);
    return ret;
}
Esempio n. 5
0
void ComposerEngine::stopOldScript(uint16 id) {
	// FIXME: this could potentially (in the case of buggy script) be called on an in-use script

	for (Common::List<OldScript *>::iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++) {
		if ((*i)->_id == id) {
			removeSprite(0, id);
			delete *i;
			i = _oldScripts.reverse_erase(i);
		}
	}
}
Esempio n. 6
0
void ComposerEngine::setCursor(uint16 id, const Common::Point &offset) {
	_mouseOffset = offset;
	if (_mouseSpriteId == id)
		return;

	if (_mouseSpriteId && _mouseVisible) {
		removeSprite(_mouseSpriteId, 0);
	}
	_mouseSpriteId = id;
	if (_mouseSpriteId && _mouseVisible) {
		addSprite(_mouseSpriteId, 0, 0, _lastMousePos - _mouseOffset);
	}
}
Esempio n. 7
0
File: being.cpp Progetto: Ablu/mana
void Being::setSprite(unsigned int slot, int id, const std::string &color,
                      bool isWeapon)
{
    if (slot >= size())
        ensureSize(slot + 1);

    if (slot >= mSpriteIDs.size())
        mSpriteIDs.resize(slot + 1);

    if (slot >= mSpriteColors.size())
        mSpriteColors.resize(slot + 1);

    // id = 0 means unequip
    if (id == 0)
    {
        removeSprite(slot);

        if (isWeapon)
            mEquippedWeapon = 0;
    }
    else
    {
        std::string filename = itemDb->get(id).getSprite(mGender);
        AnimatedSprite *equipmentSprite = 0;

        if (!filename.empty())
        {
            if (!color.empty())
                filename += "|" + color;

            equipmentSprite = AnimatedSprite::load(
                                    paths.getStringValue("sprites") + filename);
        }

        if (equipmentSprite)
            equipmentSprite->setDirection(getSpriteDirection());

        CompoundSprite::setSprite(slot, equipmentSprite);

        if (isWeapon)
            mEquippedWeapon = &itemDb->get(id);

        setAction(mAction);
    }

    mSpriteIDs[slot] = id;
    mSpriteColors[slot] = color;
}
void LayerEditScene::keyPressEvent(QKeyEvent *event)
{
    // Remove all selected items when the delete key is pressed.
    if(event->key() == Qt::Key_Delete) {
        QList<QGraphicsPixmapItem *> remove;
        for(int i = 0; i < items().size(); i++) {
            if(items().at(i)->isSelected()) {
                remove.append(static_cast<QGraphicsPixmapItem *>(items().at(i)));
            }
        }
        for(int i = 0; i < remove.size(); i++) {
            removeSprite(_previews.indexOf(remove.at(i)));
            recalculatePositions();
        }
    }
}
Esempio n. 9
0
// 使用精灵帧图片来创建物体
void PhysicsNode::createBodyWitSpriteAndFixture(b2World *world, b2BodyDef *bodyDef, b2FixtureDef *fixtureDef, std::string spriteName)
{
    removeBody(); // remove the body if it already exists
    removeSprite(); // remove the sprite if it aleady exists
    
    _sprite = CCSprite::create(spriteName.c_str());
    _sprite->retain();
    this->addChild(_sprite);
    
    _body = world->CreateBody(bodyDef);
    _body->SetUserData(this);
    
    if (fixtureDef != NULL) {
        _body->CreateFixture(fixtureDef);
    }
}
Esempio n. 10
0
void ComposerEngine::setCursorVisible(bool visible) {
	if (visible && !_mouseVisible) {
		_mouseVisible = true;
		if (_mouseSpriteId)
			addSprite(_mouseSpriteId, 0, 0, _lastMousePos - _mouseOffset);
		else
			CursorMan.showMouse(true);
		onMouseMove(_lastMousePos);
	} else if (!visible && _mouseVisible) {
		_mouseVisible = false;
		if (_mouseSpriteId)
			removeSprite(_mouseSpriteId, 0);
		else
			CursorMan.showMouse(false);
	}
}
Esempio n. 11
0
void ComposerEngine::stopPipes() {
	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		const Common::Array<uint16> *scripts = (*j)->getScripts();
		if (scripts) {
			for (uint i = 0; i < scripts->size(); i++) {
				removeSprite((*scripts)[i], 0);
				stopOldScript((*scripts)[i]);
			}
		}
		delete *j;
	}

	_pipes.clear();

	// substreams may need to remain valid until the end of a page
	for (uint i = 0; i < _pipeStreams.size(); i++)
		delete _pipeStreams[i];
	_pipeStreams.clear();
}
Esempio n. 12
0
	void StandartDrawingLayer::removeEntity( Entity* entity )
	{
		auto graphicsComponent = entity->getComponent<Graphics>();
		auto sprite = graphicsComponent->getSprite();

		if( graphicsComponent->isStatic() )
		{
			auto chunkPosition = *entity->getComponent<Transformation>()->getLastChunkPosition();

			// find vbo for chunk
			auto it = find_if( m_staticVBOs.begin(), m_staticVBOs.end(), [&]( const ChunkVBO& el )
			{
				if( el.getChunkPosition() == chunkPosition.toPositionXY() && el.getTexture() == sprite->getTexture() )
					return true;
				else
					return false;
			} );

			//found
			if( it != m_staticVBOs.end() )
			{
				it->removeSprite( sprite );
				if( it->getSpriteCount() == 0 )
					m_staticVBOs.erase( it );
			}
			//not found
			else
			{
				throw exception();
			}
		}
		else
		{
			auto condition = [&]( const sf::Sprite* el )
			{
				return el == sprite;
			};

			m_dynamicSprites.erase( remove_if( m_dynamicSprites.begin(), m_dynamicSprites.end(), condition ), m_dynamicSprites.end() );
		}
	}
Esempio n. 13
0
void ComposerEngine::stopAnimation(Animation *anim, bool localOnly, bool pipesOnly) {
	// disable the animation
	anim->_state = 0;

	// stop any animations it may have spawned
	for (uint j = 0; j < anim->_entries.size(); j++) {
		AnimationEntry &entry = anim->_entries[j];
		if (!entry.prevValue)
			continue;
		if (localOnly) {
			if (pipesOnly)
				continue;
			if (entry.op == kAnimOpDrawSprite) {
				removeSprite(entry.prevValue, anim->_id);
			} else if (entry.op == kAnimOpPlayWave) {
				if (_currSoundPriority >= entry.priority) {
					_mixer->stopAll();
					_audioStream = NULL;
				}
			}
		} else {
			if (entry.op != kAnimOpPlayAnim)
				continue;
			for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
				if ((*i)->_id == entry.prevValue)
					stopAnimation(*i);
			}
		}
	}

	// kill any pipe owned by the animation
	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		if (pipe->_anim != anim)
			continue;
		j = _pipes.reverse_erase(j);
		delete pipe;
		break;
	}
}
Esempio n. 14
0
void ComposerEngine::processAnimFrame() {
	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;

		anim->seekToCurrPos();

		if (anim->_state <= 1) {
			bool normalEnd = (anim->_state == 1);
			if (normalEnd) {
				runEvent(kEventAnimDone, anim->_id, anim->_eventParam, 0);
			}
			stopAnimation(anim, true, normalEnd);
			delete anim;
			i = _anims.reverse_erase(i);

			continue;
		}

		for (uint j = 0; j < anim->_entries.size(); j++) {
			AnimationEntry &entry = anim->_entries[j];
			if (entry.op != kAnimOpEvent)
				break;
			if (entry.counter) {
				entry.counter--;
			} else {
				if ((anim->_state > 1) && (anim->_stream->pos() + 2 > anim->_stream->size())) {
					warning("anim with id %d ended too soon", anim->_id);
					anim->_state = 0;
					break;
				}

				uint16 event = anim->_stream->readUint16LE();
				anim->_offset += 2;
				if (event == 0xffff) {
					entry.counter = anim->_stream->readUint16LE() - 1;
					anim->_offset += 2;
				} else {
					debug(4, "anim: event %d", event);
					runEvent(event, anim->_id, 0, 0);
				}
			}
		}
	}

	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;

		// did the anim get disabled?
		if (anim->_state == 0) {
			stopAnimation(anim, true, false);
			delete anim;
			i = _anims.reverse_erase(i);
			continue;
		}

		anim->_state--;

		bool foundWait = false;
		for (uint j = 0; j < anim->_entries.size(); j++) {
			AnimationEntry &entry = anim->_entries[j];

			// only skip these at the start
			if (!foundWait && (entry.op == kAnimOpEvent))
				continue;
			foundWait = true;

			if (entry.counter) {
				entry.counter--;
				if ((entry.op == kAnimOpPlayWave) && entry.prevValue) {
					debug(4, "anim: continue play wave %d", entry.prevValue);
					playWaveForAnim(entry.prevValue, entry.priority, true);
				}
			} else {
				anim->seekToCurrPos();
				if ((anim->_state > 1) && (anim->_stream->pos() + 2 > anim->_stream->size())) {
					warning("anim with id %d ended too soon", anim->_id);
					anim->_state = 0;
					break;
				}

				uint16 data = anim->_stream->readUint16LE();
				anim->_offset += 2;
				if (data == 0xffff) {
					entry.counter = anim->_stream->readUint16LE() - 1;
					anim->_offset += 2;
				} else {
					switch (entry.op) {
					case kAnimOpEvent:
						debug(4, "anim: event %d", data);
						runEvent(data, anim->_id, 0, 0);
						break;
					case kAnimOpPlayWave:
						debug(4, "anim: play wave %d", data);
						playWaveForAnim(data, entry.priority, false);
						break;
					case kAnimOpPlayAnim:
						debug(4, "anim: play anim %d", data);
						playAnimation(data, anim->_basePos.x, anim->_basePos.y, 1);
						break;
					case kAnimOpDrawSprite:
						if (!data || (entry.prevValue && (data != entry.prevValue))) {
							debug(4, "anim: erase sprite %d", entry.prevValue);
							removeSprite(entry.prevValue, anim->_id);
						}
						if (data) {
							int16 x = anim->_stream->readSint16LE();
							int16 y = anim->_stream->readSint16LE();
							Common::Point pos(x, y);
							anim->_offset += 4;
							uint16 animId = anim->_id;
							if (anim->_state == entry.state)
								animId = 0;
							debug(4, "anim: draw sprite %d at (relative) %d,%d", data, x, y);
							bool wasVisible = spriteVisible(data, animId);
							addSprite(data, animId, entry.priority, anim->_basePos + pos);
							if (wasVisible) {
								// make sure modified sprite isn't removed by another entry
								for (uint k = 0; k < anim->_entries.size(); k++) {
									if (anim->_entries[k].op != kAnimOpDrawSprite)
										continue;
									if (anim->_entries[k].prevValue == data)
										anim->_entries[k].prevValue = 1;
								}
							}
						}
						break;
					default:
						warning("unknown anim op %d", entry.op);
					}

					entry.prevValue = data;
				}
			}
		}
	}

	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		pipe->nextFrame();

		// V1 pipe audio; see OldPipe
		if (pipe->hasResource(ID_WAVE, 0xffff))
			playWaveForAnim(0xffff, 0, false);
	}
}
Esempio n. 15
0
File: init.c Progetto: kyeah/VizChat
void subserver(Room* rooms, SDL_sem** semaphores, int fd, int* rooms_opened){
  struct Message message;
  int curr_room = 0;
  int i, b, temp_curr, numSprites, clientid;
  int keyState[NUMKEYS];
  Uint32 colorkey;

  /*-----------------------------------------
    Initialize the client's player in Room 0 
  -------------------------------------------*/

  Sprite* temp;
  temp = (Sprite*)malloc(sizeof(Sprite));

  read(fd, temp, sizeof(Sprite));
  addSprite( temp, rooms, 0);	
  clientid = temp->clientid;

  
  /*------------------------------------------------------------------------
    Continuously write the room components and handle incoming player inputs
    ------------------------------------------------------------------------*/

  while(1){

    /*------------------------------------
      Write room components to the client
      ------------------------------------*/

    //Notify the client of how many sprites are going to be written
    numSprites = countSprites(rooms, curr_room);

    write(fd, &numSprites, sizeof(int));

    //Close the room components off to prevent collisions
    SDL_SemWait(semaphores[curr_room]);

    //Go through the component array until all initialized sprites have been written
    //FOR NOW, SKIP THE PLATFORMS SEGMENT OF THE COMPONENTS SINCE WE HAVE NONE
    for(i=NUMSPRITES;i<NUMTYPES*NUMSPRITES && numSprites > 0;i++){
      
      temp = rooms[curr_room].components[i];
      
      if(temp)
	b = write(fd, temp, sizeof(Sprite));

      //The write was successful and an initialized sprite was written
      if(b != -1)
	numSprites--;
    }
    
    //Reopen the room components
    SDL_SemPost(semaphores[curr_room]);

    /*------------------
      Read client inputs
      ------------------*/

    //Read the message from client for keystates and an event
    b = read(fd, &message, sizeof(message));

    //The client has closed, so the subserver is no longer needed in this world.
    if(b <= 0){
      puts("Subserver break.");
      break;
    }
    
    for(i=0; i<NUMKEYS; i++)
      read(fd, &(keyState[i]), sizeof(int) );
    

    /*---------------------
      Process client inputs
      ---------------------*/

    temp_curr = curr_room; //Needed in case curr_room changes in serverEventHandler
    SDL_SemWait(semaphores[temp_curr]);

    serverEventHandler(rooms, message, keyState, &curr_room, (*rooms_opened - 1), fd);
    //update all rockets
   
    SDL_SemPost(semaphores[temp_curr]);
  }

  /*-----------------------------------
    Clean up after subserver has closed
    -----------------------------------*/

  removeSprite(rooms, curr_room, clientid);
  exit(0);
}
Esempio n. 16
0
bool ComposerEngine::tickOldScript(OldScript *script) {
	if (script->_currDelay) {
		script->_currDelay--;
		return true;
	}

	bool running = true;
	bool erasedOldSprite = false;
	while (running && script->_stream->pos() < (int)script->_size) {
		uint16 spriteId, scriptId, buttonId, pipeId;
		Common::Point spritePos;

		script->_stream->skip(0);
		byte op = script->_stream->readByte();
		switch (op) {
		case kOldOpNoOp:
			debug(3, "kOldOpNoOp()");
			running = false;
			break;
		case kOldOpReplaceSprite:
			if (!erasedOldSprite) {
				removeSprite(0, script->_id);
				erasedOldSprite = true;
			}

			spriteId = script->_stream->readUint16LE();
			spritePos.x = script->_stream->readSint16LE();
			spritePos.y = script->_stream->readSint16LE();
			debug(3, "kOldOpReplaceSprite(%d, %d, %d)", spriteId, spritePos.x, spritePos.y);
			addSprite(spriteId, script->_id, script->_zorder, spritePos);
			break;
		case kOldOpPlayWav:
			uint16 wavId, prio;
			wavId = script->_stream->readUint16LE();
			prio = script->_stream->readUint16LE();
			debug(3, "kOldOpPlayWav(%d, %d)", wavId, prio);
			playWaveForAnim(wavId, prio, false);
			break;
		case kOldOpRunScript:
			scriptId = script->_stream->readUint16LE();
			debug(3, "kOldOpRunScript(%d)", scriptId);
			if (scriptId == script->_id) {
				// reset ourselves
				removeSprite(0, script->_id);
				script->_stream->seek(6);
			} else {
				runScript(scriptId);
			}
			break;
		case kOldOpStopScript:
			scriptId = script->_stream->readUint16LE();
			debug(3, "kOldOpStopScript(%d)", scriptId);
			removeSprite(0, scriptId);
			stopOldScript(scriptId);
			break;
		case kOldOpActivateButton:
			buttonId = script->_stream->readUint16LE();
			debug(3, "kOldOpActivateButton(%d)", buttonId);
			setButtonActive(buttonId, true);
			break;
		case kOldOpDeactivateButton:
			buttonId = script->_stream->readUint16LE();
			debug(3, "kOldOpDeactivateButton(%d)", buttonId);
			setButtonActive(buttonId, false);
			break;
		case kOldOpDrawSprite:
			spriteId = script->_stream->readUint16LE();
			spritePos.x = script->_stream->readSint16LE();
			spritePos.y = script->_stream->readSint16LE();
			debug(3, "kOldOpDrawSprite(%d, %d, %d)", spriteId, spritePos.x, spritePos.y);
			addSprite(spriteId, script->_id, script->_zorder, spritePos);
			break;
		case kOldOpRemoveSprite:
			spriteId = script->_stream->readUint16LE();
			debug(3, "kOldOpRemoveSprite(%d)", spriteId);
			removeSprite(spriteId, script->_id);
			break;
		case kOldOpDisableMouseInput:
			debug(3, "kOldOpDisableMouseInput()");
			setCursorVisible(false);
			break;
		case kOldOpEnableMouseInput:
			debug(3, "kOldOpEnableMouseInput()");
			setCursorVisible(true);
			break;
		case kOldOpWait:
			script->_currDelay = script->_stream->readUint16LE();
			debug(3, "kOldOpWait(%d)", script->_currDelay);
			break;
		case kOldOpRandWait:
			uint16 min, max;
			min = script->_stream->readUint16LE();
			max = script->_stream->readUint16LE();
			debug(3, "kOldOpRandWait(%d, %d)", min, max);
			script->_currDelay = _rnd->getRandomNumberRng(min, max);
			break;
		case kOldOpDrawGlobalSprite:
			spriteId = script->_stream->readUint16LE();
			spritePos.x = script->_stream->readSint16LE();
			spritePos.y = script->_stream->readSint16LE();
			debug(3, "kOldOpDrawGlobalSprite(%d, %d, %d)", spriteId, spritePos.x, spritePos.y);
			addSprite(spriteId, 0, script->_zorder, spritePos);
			break;
		case kOldOpRemoveGlobalSprite:
			spriteId = script->_stream->readUint16LE();
			debug(3, "kOldOpRemoveGlobalSprite(%d)", spriteId);
			removeSprite(spriteId, 0);
			break;
		case kOldOpSetZOrder:
			script->_zorder = script->_stream->readUint16LE();
			debug(3, "kOldOpSetZOrder(%d)", script->_zorder);
			break;
		case kOldOpPlayPipe:
			pipeId = script->_stream->readUint16LE();
			debug(3, "kOldOpPlayPipe(%d)", pipeId);
			playPipe(pipeId);
			break;
		case kOldOpStopPipe:
			pipeId = script->_stream->readUint16LE();
			debug(3, "kOldOpStopPipe(%d)", pipeId);
			// yes, pipeId is ignored here..
			stopPipes();
			break;
		case kOldOpNewScreen:
			uint16 newScreenId;
			newScreenId = script->_stream->readUint16LE();
			debug(3, "kOldOpNewScreen(%d)", newScreenId);
			if (!newScreenId) {
				quitGame();
			} else {
				_pendingPageChanges.clear();
				_pendingPageChanges.push_back(PendingPageChange(newScreenId, false));
			}
			break;
		case kOldOpRunRandom:
			uint16 randomId;
			randomId = script->_stream->readUint16LE();
			debug(3, "kOldOpRunRandom(%d)", randomId);
			if (!_randomEvents.contains(randomId)) {
				warning("kOldOpRunRandom found no entries for id %d", randomId);
			} else {
				uint32 randValue = _rnd->getRandomNumberRng(0, 32767);
				const Common::Array<RandomEvent> &events = _randomEvents[randomId];
				uint i = 0;
				for (i = 0; i < events.size(); i++) {
					if ((i + 1 == events.size()) || (randValue <= events[i].weight)) {
						runScript(events[i].scriptId);
						break;
					} else {
						randValue -= events[i].weight;
					}
				}
			}
			break;
		default:
			error("unknown oldScript op %d", op);
		}
	}

	if (script->_stream->pos() >= (int)script->_size) {
		// stop running if we ran out of script
		removeSprite(0, script->_id);
		return false;
	}

	return true;
}
Esempio n. 17
0
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
bool PartEmitter::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {
	//////////////////////////////////////////////////////////////////////////
	// SetBorder
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "SetBorder") == 0) {
		stack->correctParams(4);
		int borderX      = stack->pop()->getInt();
		int borderY      = stack->pop()->getInt();
		int borderWidth  = stack->pop()->getInt();
		int borderHeight = stack->pop()->getInt();

		stack->pushBool(DID_SUCCEED(setBorder(borderX, borderY, borderWidth, borderHeight)));

		return STATUS_OK;
	}
	//////////////////////////////////////////////////////////////////////////
	// SetBorderThickness
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "SetBorderThickness") == 0) {
		stack->correctParams(4);
		int left   = stack->pop()->getInt();
		int right  = stack->pop()->getInt();
		int top    = stack->pop()->getInt();
		int bottom = stack->pop()->getInt();

		stack->pushBool(DID_SUCCEED(setBorderThickness(left, right, top, bottom)));

		return STATUS_OK;
	}
	//////////////////////////////////////////////////////////////////////////
	// AddSprite
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "AddSprite") == 0) {
		stack->correctParams(1);
		const char *spriteFile = stack->pop()->getString();
		stack->pushBool(DID_SUCCEED(addSprite(spriteFile)));

		return STATUS_OK;
	}
	//////////////////////////////////////////////////////////////////////////
	// RemoveSprite
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "RemoveSprite") == 0) {
		stack->correctParams(1);
		const char *spriteFile = stack->pop()->getString();
		stack->pushBool(DID_SUCCEED(removeSprite(spriteFile)));

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Start
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Start") == 0) {
		stack->correctParams(1);
		_overheadTime = stack->pop()->getInt();
		stack->pushBool(DID_SUCCEED(start()));

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Stop
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Stop") == 0) {
		stack->correctParams(0);

		for (uint32 i = 0; i < _particles.size(); i++) {
			delete _particles[i];
		}
		_particles.clear();

		_running = false;
		stack->pushBool(true);

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Pause
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Pause") == 0) {
		stack->correctParams(0);
		_running = false;
		stack->pushBool(true);

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Resume
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Resume") == 0) {
		stack->correctParams(0);
		_running = true;
		stack->pushBool(true);

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// AddGlobalForce
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "AddGlobalForce") == 0) {
		stack->correctParams(3);
		const char *forceName = stack->pop()->getString();
		float angle = stack->pop()->getFloat();
		float strength = stack->pop()->getFloat();

		stack->pushBool(DID_SUCCEED(addForce(forceName, PartForce::FORCE_GLOBAL, 0, 0, angle, strength)));

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// AddPointForce
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "AddPointForce") == 0) {
		stack->correctParams(5);
		const char *forceName = stack->pop()->getString();
		int posX = stack->pop()->getInt();
		int posY = stack->pop()->getInt();
		float angle = stack->pop()->getFloat();
		float strength = stack->pop()->getFloat();

		stack->pushBool(DID_SUCCEED(addForce(forceName, PartForce::FORCE_GLOBAL, posX, posY, angle, strength)));

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// RemoveForce
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "RemoveForce") == 0) {
		stack->correctParams(1);
		const char *forceName = stack->pop()->getString();

		stack->pushBool(DID_SUCCEED(removeForce(forceName)));

		return STATUS_OK;
	} else {
		return BaseObject::scCallMethod(script, stack, thisStack, name);
	}
}
Esempio n. 18
0
// 删除物体和精灵
void PhysicsNode::removeSpriteAndbody(cocos2d::CCObject *pSender)
{
    removeBody();
    removeSprite();
}
Esempio n. 19
0
Sprite::~Sprite(){
  removeSprite(this);
}
Esempio n. 20
0
PhysicsNode::~PhysicsNode()
{
    removeBody();
    removeSprite();
}