当前位置: 首页>>代码示例>>C++>>正文


C++ AnimatedSprite::setPosition方法代码示例

本文整理汇总了C++中AnimatedSprite::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedSprite::setPosition方法的具体用法?C++ AnimatedSprite::setPosition怎么用?C++ AnimatedSprite::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AnimatedSprite的用法示例。


在下文中一共展示了AnimatedSprite::setPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AnimatedSprite

pacman::pacman(sf::Texture spr)
{
    //ctor
    xpos = 250;
    ypos = 500;
    xvel = 0;
    yvel = 0;
    text = spr;
    upan.setSpriteSheet(text);
    upan.addFrame(sf::IntRect(0, 0, 25, 25));
    upan.addFrame(sf::IntRect(75, 0, 25, 25));
    downan.setSpriteSheet(text);
    downan.addFrame(sf::IntRect(0, 0, 25, 25));
    downan.addFrame(sf::IntRect(25, 0, 25, 25));
    leftan.setSpriteSheet(text);
    leftan.addFrame(sf::IntRect(0, 0, 25, 25));
    leftan.addFrame(sf::IntRect(100, 0, 25, 25));
    rightan.setSpriteSheet(text);
    rightan.addFrame(sf::IntRect(0, 0, 25, 25));
    rightan.addFrame(sf::IntRect(50, 0, 25, 25));
    currentanim = &leftan;

    anspr = AnimatedSprite(sf::seconds(.2f), false, true);
    anspr.setPosition(sf::Vector2f(xpos, ypos));
    //std::cout << "1 pacman" << std::endl;
    anspr.play(*currentanim);


    //sprite.setPosition(xpos, ypos);
    collision_box = sprite.getGlobalBounds();
    dir = 3;
}
开发者ID:deipfei,项目名称:MacPan,代码行数:32,代码来源:pacman.cpp

示例2: update

void pacman::update(){
    xpos += xvel;
    ypos += yvel;
    sprite.setPosition(sf::Vector2f(xpos, ypos));
    anspr.setPosition(sf::Vector2f(xpos, ypos));
    collision_box = anspr.getGlobalBounds();
    anspr.update(frame_time.restart());
}
开发者ID:deipfei,项目名称:MacPan,代码行数:8,代码来源:pacman.cpp

示例3: populateInvaders

void Invaders::populateInvaders(AnimatedSprite& invader)
{
    vector<AnimatedSprite> invaderCol;

    for(int col = 0; col < 10; col++)
    {
        for(int row = 0; row < 5; row++)
        {
            invader.setPosition(m_posX, m_posY);
            invaderCol.push_back(invader);
            m_posY += 40;
        }

        m_invaderPop->push_back(invaderCol);
        invaderCol.clear();
        m_posY -= 200;
        m_posX += 40;
    }

    m_posX = 100;
    m_posY = 70;
}
开发者ID:,项目名称:,代码行数:22,代码来源:

示例4: main

int main()
{
	//Initalize Variables and Settings
	const sf::Vector2i screenDimensions(800, 600);

	FloatRect playerMoveSpace = sf::FloatRect(100, 100, screenDimensions.x - 100, screenDimensions.y - 320);

	RenderWindow window(VideoMode(screenDimensions.x, screenDimensions.y), "Donkey Island", Style::Titlebar | Style::Close);

	window.setFramerateLimit(60);

	CircleShape shape(100.f);
	shape.setFillColor(Color::Green);

	Texture MenuBGTex;
	Sprite MenuBackground;

	Texture PlayerTex;
	AnimatedSprite PlayerImage;

	sf::Time actionTimer;

	int loadedLevelIndex = 0;

	GameScene* levels[] = { new LakeGrass(), new flower(), new House() };
	GameScene* loadedLevel = levels[loadedLevelIndex];

	tinyxml2::XMLElement* levelElement = NULL;

	static bool dragging = false;

	sf::Vector2f Target1;

	Inventory::item *draggeditem = NULL;

	bool clicked = false;

	if (MenuBGTex.loadFromFile("resources/menubackground.jpg")) {
		MenuBackground.setTexture(MenuBGTex);
		MenuBackground.setPosition(0.0f, 460.0f);
	}

	// load a new inventory. The inventory is kept across scenes.
	Inventory* playerInventory = new Inventory();

	// load a new quest journal. Each level, this variable is recreated with the right quests for that current level
	Quests* playerQuests = new Quests(loadedLevel);


	if (!PlayerTex.loadFromFile("resources/donkeyMovement.png")) {
		std::cout << "Failed to load player spritesheet!" << std::endl;
		return 1;
	}

	Animation walkingAnimationRight;
	walkingAnimationRight.setSpriteSheet(PlayerTex);
	walkingAnimationRight.addFrame(sf::IntRect(200, 0, 200, 200));
	walkingAnimationRight.addFrame(sf::IntRect(400, 0, 200, 200));
	walkingAnimationRight.addFrame(sf::IntRect(600, 0, 200, 200));
	walkingAnimationRight.addFrame(sf::IntRect(0, 0, 200, 200));

	Animation walkingAnimationLeft;
	walkingAnimationLeft.setSpriteSheet(PlayerTex);
	walkingAnimationLeft.addFrame(sf::IntRect(200, 200, 200, 200));
	walkingAnimationLeft.addFrame(sf::IntRect(400, 200, 200, 200));
	walkingAnimationLeft.addFrame(sf::IntRect(600, 200, 200, 200));
	walkingAnimationLeft.addFrame(sf::IntRect(0, 200, 200, 200));

	Animation walkingAnimationIdle;
	walkingAnimationIdle.setSpriteSheet(PlayerTex);
	walkingAnimationIdle.addFrame(sf::IntRect(200, 400, 200, 200));
	walkingAnimationIdle.addFrame(sf::IntRect(400, 400, 200, 200));
	walkingAnimationIdle.addFrame(sf::IntRect(600, 400, 200, 200));
	walkingAnimationIdle.addFrame(sf::IntRect(0, 400, 200, 200));

	Animation* currentAnimation = &walkingAnimationLeft;

	PlayerImage = AnimatedSprite(sf::seconds(0.1), true, false);
	PlayerImage.setPosition(sf::Vector2f(screenDimensions / 3));

	sf::Clock frameClock;


	float speed = 160.f;
	bool noKeyWasPressed = true;
	// ------------------------
	// Initialization ends here 

	// Our GAMELOOP starts here
	while (window.isOpen()) {
		Event event;
		while (window.pollEvent(event)) {
			if (event.type == Event::Closed) {
				window.close();
			}

			if (event.type == Event::MouseButtonReleased) {
				playerInventory->refreshItems();
				dragging = false;
				clicked = false;
//.........这里部分代码省略.........
开发者ID:gotwig,项目名称:DonkeyIsland,代码行数:101,代码来源:main.cpp


注:本文中的AnimatedSprite::setPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。