sprite 相关问题

精灵是一个二维图像或动画,它被整合到一个更大的场景中。

即使移除对象后,SVG Sprite 仍然可以工作

在我的index.shtml中我有 ...

回答 1 投票 0

精灵套件精灵未着色

我正在尝试使用精灵套件为精灵节点(在本例中为命名背景)着色,但无法更改颜色。我有一个想要着色的精灵。我正在更改颜色属性...

回答 4 投票 0

在 tasm 8086 中创建精灵时遇到问题

我想通过使用精灵方法为玩家创建 5 艘潜艇,为计算机创建 5 艘(总共 10 艘)。当我检查 DosBox 是否有错误时,我发现我的所有精灵行都有相同的错误

回答 1 投票 0

在 React Native 中从精灵表渲染像素化精灵,而不会使跳板崩溃

我想在具有最近邻升级的图像中渲染非动画像素艺术精灵。 我的图像看起来像这样,目前它渲染了整个精灵表: 我想在具有最近邻升级的图像中渲染非动画像素艺术精灵。 我的图像看起来像这样,目前它渲染了整个精灵表: <Image source={require("../assets/sheet.png")} style={{ width: 30, height: 30 }} 在 CSS 中,使用 background-size、background-position 和 image-rendering: pixelated 可以很简单地做到这一点。 来自 Image 的 react-native-skia 不平滑像素艺术。缩放无锯齿。 https://shopify.github.io/react-native-skia/docs/images/ import { Canvas, Image, useImage } from "@shopify/react-native-skia";   const ImageDemo = () => { const image = useImage(require("./assets/pixelart.png")); return ( <Canvas style={{ flex: 1 }}> <Image image={image} fit="contain" x={0} y={0} width={256} height={256} /> </Canvas> ); };

回答 1 投票 0

在 OpenFL 中创建多个精灵实例?

我正在使用 SVG 图像加载精灵图像,以便它们可以平滑缩放以匹配设备分辨率。目前我正在天真地渲染每个精灵的 SVG 数据,但我想减少内存...

回答 2 投票 0

剪辑SpriteComponent的某些部分

我使用 SpriteComponent 加载了全屏图像,并尝试使用 canvas.clipPath 删除该图像的某些部分。 预期:除所有剪切部分外,图像将被渲染 问题:...

回答 1 投票 0

拖动 SKShapeNode 时遵守其他 SKShapeNode 的边界

我需要拖动一个形状节点,避免其他形状,如果它们击中,那么我希望不要跨越边界。因此,如果我有一个天花板,我将一个球拖到上面,我希望它撞到天花板......

回答 1 投票 0

Unity 3D,即使 Sprite 不可见,如何检测鼠标是否位于 2D Sprite 上

我使用Unity3D游戏引擎,偶然发现了这个问题。 当我尝试检查鼠标是否位于精灵上方时,我可以使用此回调来执行此操作。 私有无效 OnMouseOver() { // 做

回答 2 投票 0

使用 Bevy 0.4 拖动精灵的可接受方法是什么?

在尝试 Bevy 时,我需要拖放精灵。 不幸的是,这似乎不是现成的,或者我没有在文档中找到它。 最常用的成语是什么...

回答 3 投票 0

当我按住方向时,pygame 中的玩家会闪烁(初学者代码)

我在 pygame 中的玩家是一个矩形,当朝一个方向连续移动时会变黑,直到我松开按键,所以动画非常卡顿 我尝试在 screen.fill 周围移动,看看是否...

回答 1 投票 0

如何使用 SFML 和 C++ 渲染贪吃蛇游戏的精灵

游戏运行良好,但它使用矩形形状,我想使用精灵渲染蛇部分。这是代码(是的,它不是那么干净,我只是想让它工作): #包括 游戏运行良好,但它使用矩形形状,我想使用精灵渲染蛇部分。这是代码(是的,它不是那么干净,我只是想让它工作): #include <SFML/Graphics.hpp> // Graphics module #include <SFML/Audio.hpp> // Sound module #include <iostream> // Basic input/output (for errors) #include <vector> // Dynamic arrays (for snake body) #include <random> // For random food positions class Game { private: sf::Vector2u windowSize; // Size of the game window int a, b; // Length and width of a block sf::RenderWindow window; // Window object for drawing sf::Font font; // Text font sf::Clock clock; // For time measurement std::vector<sf::Vector2i> body; // Snake body (segments as coordinates) sf::Vector2i food; // Food position sf::Vector2i direction; // Snake direction int score; // Player's score bool gameOver; // Game state: finished or not int n, m; // Number of rows and columns float delay, timer; // Update delay and elapsed time sf::Music eat; // Sound effect for eating public: Game(unsigned short x, unsigned short y); // Constructor void start(); // Start the game private: void loop(); // Main game loop void events(); // Process events (keyboard, etc.) void update(); // Update game logic void render(); // Render elements on screen void gameOverScreen(); // Show "Game Over" screen sf::Vector2i getFoodPosition(); // Generate new food position }; int WinMain() { Game game(800, 600); game.start(); } int main() { Game game(800, 600); // Create object with window size 800x600 game.start(); // Call the start function } Game::Game(uint16_t x, uint16_t y) { windowSize = { x, y }; // Save window width and height window.create(sf::VideoMode(windowSize.x, windowSize.y, 1), "Snake"); // Create the window a = 50; // Set block width b = 50; // Set block height n = windowSize.x / a; // Calculate number of horizontal blocks m = windowSize.y / b; // Calculate number of vertical blocks font.loadFromFile("resources/Fonts/sfpro_bold.OTF"); // Load font for text eat.openFromFile("resources/Audio/eating_apple.mp3"); } void Game::start() { body.clear(); // Clear the snake body body.push_back({ 5,3 }); // Head body.push_back({ 4,3 }); // Body segment body.push_back({ 3,3 }); // Tail direction = { 0, 0 }; // Direction food = { getFoodPosition() }; // Initial food position gameOver = false; // Game not over (false) score = 0; // Start score from 0 loop(); // Main loop } void Game::loop() { timer = 0.f; // Accumulated time delay = 0.125f; // Game update delay while (window.isOpen()) { events(); // Handle user inputs (keyboard and mouse) timer += clock.getElapsedTime().asSeconds(); // Add elapsed time in seconds to the timer if (timer > delay) { update(); // Update the game (move snake, etc.) render(); // Render the screen (blocks, snake, food, text, etc.) timer = 0; // Reset timer } clock.restart(); // Restart the clock for the next cycle } } void Game::events() { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Escape) window.close(); else if (event.key.code == sf::Keyboard::Up && (direction.y != 1)) direction = { 0, -1 }; else if (event.key.code == sf::Keyboard::Down && (direction.y != -1)) direction = { 0, 1 }; else if (event.key.code == sf::Keyboard::Left && (direction.x != 1)) direction = { -1, 0 }; else if (event.key.code == sf::Keyboard::Right && (direction.x != -1)) direction = { 1, 0 }; else if (event.key.code == sf::Keyboard::R) /*if (gameOver)*/ start(); } } } void Game::update() { if (gameOver || direction == sf::Vector2i{ 0,0 }) return; sf::Vector2i newHead = body[0] + direction; for (size_t i = 1; i < body.size(); i++) { if (newHead == body[i]) { gameOver = true; return; } } if (newHead.x > n - 1 || newHead.x < 0 || newHead.y > m - 1 || newHead.y < 0) { gameOver = true; return; } if (newHead == food) { body.insert(body.begin(), newHead); food = getFoodPosition(); score++; eat.play(); } else { body.insert(body.begin(), newHead); body.pop_back(); } } void Game::render() { window.clear(); sf::RectangleShape block(sf::Vector2f(a, b)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { block.setPosition(i * a, j * b); int p = (i + j) % 2; block.setFillColor(sf::Color(172 - p * 7, 214 - p * 7, 67 - p * 7, 255)); window.draw(block); } } block.setPosition(food.x * a, food.y * b); block.setFillColor(sf::Color::Red); window.draw(block); for (int i = 0; i < body.size(); i++) { if (i == 0) block.setFillColor(sf::Color::Magenta); else block.setFillColor(sf::Color(0, 71, 181)); block.setPosition(body[i].x * a, body[i].y * b); window.draw(block); } sf::Text scr("Score: " + std::to_string(score), font, 32); scr.setFillColor(sf::Color::White); scr.setPosition(4, 0); window.draw(scr); if (gameOver) gameOverScreen(); window.display(); } void Game::gameOverScreen() { eat.stop(); sf::RectangleShape screen({ float(windowSize.x), float(windowSize.y) }); screen.setPosition({ 0,0 }); screen.setFillColor(sf::Color(0, 0, 0, 100)); sf::Text gameOverText(" Game over!\nPress R to restart", font, 38); gameOverText.setFillColor(sf::Color::White); gameOverText.setPosition((windowSize.x / 2) - 150, (windowSize.y / 2) - 20); window.draw(screen); window.draw(gameOverText); } sf::Vector2i Game::getFoodPosition() { std::random_device randomDevice; std::mt19937 randomNumberGenerator(randomDevice()); std::uniform_int_distribution<int> distX(0, n - 1); std::uniform_int_distribution<int> distY(0, m - 1); sf::Vector2i position; do { position.x = distX(randomNumberGenerator); position.y = distY(randomNumberGenerator); if (std::find(body.begin(), body.end(), position) == body.end()) { return position; } } while (true); } 上面的代码目前没有精灵功能,但这是我尝试过的一种方法(适用于渲染精灵):创建纹理和精灵的地图,从文件加载纹理,将它们映射到精灵,然后我准备好了一张精灵地图。这部分并不难,我的渲染逻辑很可能存在缺陷。代码是从我拥有精灵逻辑时获取的,我基本上使用字符串来确定我应该加载哪个精灵。 sf::Vector2i prev = body[i + 1]; // sf::Vector2i next = body[i - 1]; //because i pop the tail and insert new part at the beginning if (next.x == prev.x) { spriteName = "body_vertical"; //vertical sprite | } else if (next.y == prev.y) { spriteName = "body_horizontal"; // horizontal -- } else { if (prev.x < next.x) { if (prev.y > next.y) spriteName = "body_topright"; // start top curve right downwards else spriteName = "body_bottomleft"; // bottom -> left } else if (prev.y < next.y) { spriteName = "body_topleft"; // top -> left else spriteName = "body_bottomright"; // bottom -> right } } else{ if (prev.y > next.y) { spriteName = "body_topleft"; // top -> left else spriteName = "body_bottomright"; // bottom -> right } else if (prev.y < next.y) { spriteName = "body_topright"; // top -> right else spriteName = "body_bottomleft"; // bottom -> left } } } 精灵链接:opengameart.org/content/snake-game-assets。基本上,我想要的是一些关于如何选择要加载的正确精灵以及在哪种情况下加载的反馈(头部和尾部也将受到赞赏🥹)。谢谢! 这是一个稍微干净一点的代码, // choosing is based on the assumption // that the head is the last element in the body array // if not, you can simply reverse the conditions if (next == /*last in body*/) { spriteName == "head_sprite"; } else if (next == /*first in body*/) { spriteName = "tail_sprite"; } else if (next.x == prev.x || next.y == prev.y) { spriteName == "body_sprite"; } else { spriteName = "curved_sprite"; } // now rotate and reverse if (prev.x == next.x) { // rotate 90deg } else if (prev.x > next.x) { // reverse horizontally } if (prev.y > next.y) { // reverse vertically } 旋转/反转精灵比根据每种情况选择单独的精灵要方便得多。 我从您附加的那些精灵中选择了snake_graphics.zip [“head_down”,“tail_down”,“body_vertical”,“body_bottomright”] 并将它们重命名为 [“head_sprite”、“tail_sprite”、“body_sprite”、“curved_sprite”] 分别。 我可能错误地旋转/反转了精灵 因为我不确定上一个还是下一个是当前的(“假设上一个是”),但这就是基本思想

回答 1 投票 0

创建 SVG,在纯 Javascript 中设置 href 而不是 xlink:href

我有一个包含所有图标的 SVG 精灵,当在 Javascript 中动态添加图标时,我使用以下代码: 让 closeButton = document.createElementNS("http://www.w3.org/2000/svg", "...

回答 1 投票 0

Unity 2D - 动画背景

我正在开发一款带有免费像素冒险精灵的游戏。下面的GIF是精灵创建者放置的一个级别,我不知道如何在Unity中创建这样的背景(用go down动画重复...

回答 1 投票 0

鼠标悬停在 Sprite 对象 Pyglet 上?

我想知道是否有办法用 Pyglet 捕获鼠标悬停在精灵对象上? my_sprite = pyglet.sprite.Sprite(图像, x, y) Tkinter 中是这样的: sprite.bind(圆, " 我想知道是否有办法用 Pyglet 捕获鼠标悬停在精灵对象上? my_sprite = pyglet.sprite.Sprite(image, x, y) Tkinter 中有这样的东西: sprite.bind(circle, "<Enter>", on_enter) 下面是一个检测鼠标悬停在移动的 gif 精灵上的演示代码,您可以尝试将其更改为您喜欢的。 import pyglet from pyglet.window import mouse animation = pyglet.image.load_animation('ur_image_gif_path_like_xxx.gif') bin = pyglet.image.atlas.TextureBin() animation.add_to_texture_bin(bin) sprite = pyglet.sprite.Sprite(img=animation) window = pyglet.window.Window() @window.event def on_draw(): window.clear() sprite.draw() def update(dt): sprite.x += dt*10 @window.event def on_mouse_motion(x, y, dx, dy): # print(x, y, dx, dy) image_width = sprite.image.get_max_width() image_height = sprite.image.get_max_height() if sprite.x+image_width>x>sprite.x and sprite.y+image_height>y>sprite.y: print("mouse hover sprite") else: print("mouse leave sprite") pyglet.clock.schedule_interval(update, 1/60.) pyglet.app.run() 您正在寻找边界检查处理程序。请参阅 pyglet-users 中的讨论。最重要的是 pyglet 没有用于精灵边界检查的内置处理程序。尽管代码不是很清楚或没有详细记录,但上述受访者展示了一个基本的对象边界测试循环。不仅“粗鲁但有效”,这也是处理程序通常会为您做的事情。

回答 2 投票 0

鼠标单击精灵图像而不是其边界框

在我检查的所有游戏示例中,使用 SFML、.NET Framework、WPF、Python 和 HTML5 用 C++/C# 编写,精灵会对精灵边界框中的鼠标点击做出反应。 有没有

回答 1 投票 0

Sprite_index 未设置

我正在关注有关格斗游戏的 YouTube 教程。遇到错误: Var .sprite_index 未设置。 错误就在这里: if (sprite_index != sprKill_foward) { 精灵索引 =

回答 1 投票 0

获取精灵相对于相机所面对的方向

假设我有一个相机(玩家,因为我正在制作游戏),角度为 0, 0,面向 -0.78 弧度。我还有一个实体或 npc,其角度为 -2,2 面朝 0.78 弧度。因为我们是人类,我们有大脑......

回答 1 投票 0

Pygame 表面无意中在对象之间共享

在两个单独的文件中使用此代码: 导入pygame # 这些用于确定该顶级模块正在运行的位置 # 这样路径就可以传递给子模块 从检查...

回答 1 投票 0

使用 sprites 和 setObject 在 C++ 上进行碰撞检测

我正在尝试创建一个非常基本的无尽跑步游戏玩家,但我陷入了碰撞检测。我正在使用 notepad++ 为 GBA 模拟器进行编程。下面的代码是我的主要游戏 while 循环。

回答 1 投票 0

如何自动检测并裁剪精灵表中的各个精灵边界?

给定一个像这样的精灵表: 我想编写一种算法,可以循环像素数据并确定每个离散精灵的边界矩形。 如果我们假设对于每个 pi...

回答 3 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.