首页 \ 问答 \ django模板中的函数(functions in django templates)

django模板中的函数(functions in django templates)

django模板是否支持函数?
我可以在模板中内联编写它们吗?
如果我可以,怎么样?


Does django templates support functions?
Can I write them inline within the template?
If I can, how?


原文:https://stackoverflow.com/questions/5242029
更新时间:2023-04-23 11:04

最满意答案

使用sf :: RenderTexture是一个选项(请参阅其他答案 )。 另一个选择是摆弄sf::View 。 加倍视图的高度,并调整坐标。 它会像这样:

my_sprite.setRotation(45.f);
//adjust the position for new screen coordinates (once)
my_sprite.setPosition(my_sprite.getPosition().x, my_sprite.getPosition().y * 2);

//...

//when drawing:
sf::View v = my_render_window.getDefaultView();
v.setSize(v.getSize().x, v.getSize().y * 2);
v.setCenter(v.getSize() *.5f);

my_render_window.setView(v);
my_render_window.draw(my_sprite);
my_render_window.setView(my_render_window.getDefaultView());

Using a sf::RenderTexture is an option (see other answer). Another option is to fiddle with the sf::View. Double the view's height, and adjust coordinates. It would go something like this:

my_sprite.setRotation(45.f);
//adjust the position for new screen coordinates (once)
my_sprite.setPosition(my_sprite.getPosition().x, my_sprite.getPosition().y * 2);

//...

//when drawing:
sf::View v = my_render_window.getDefaultView();
v.setSize(v.getSize().x, v.getSize().y * 2);
v.setCenter(v.getSize() *.5f);

my_render_window.setView(v);
my_render_window.draw(my_sprite);
my_render_window.setView(my_render_window.getDefaultView());

相关问答

更多
  • Crafty.js能够做可点击的等轴测图。 甚至有一个等距样本 ,您可以右键单击块以将其删除。 Crafty.js is able to do clickable isometric maps. There's even a isometric sample where you can right click on blocks to remove them.
  • 这样做的一个古老技术是将你的方向分成两组:那些涉及在边缘移动的方法,以及涉及在一个角落移动的方向。 假设north对应于tile的顶角,则这些set分别分为序数和基本方向。 然后,您可以将每组方向表示为4位整数,其中每个位对应于一个方向。 对于每个方向,如果该方向需要条纹,则将其对应位设置为1 ,否则设置为0 。 这将为您提供一对值,范围从0(无边缘 - 0b0000)到15(全边缘 - 0b1111)。 然后,这两个4位数可以作为纹理列表的索引。 在列表中排列每个纹理,使其索引对应于具有设置位的方向。 例 ...
  • 使用sf :: RenderTexture是一个选项(请参阅其他答案 )。 另一个选择是摆弄sf::View 。 加倍视图的高度,并调整坐标。 它会像这样: my_sprite.setRotation(45.f); //adjust the position for new screen coordinates (once) my_sprite.setPosition(my_sprite.getPosition().x, my_sprite.getPosition().y * 2); //... //w ...
  • 由于您使用Tiled标记了这一点,因此可以通过查看Tiled的源代码来了解它是如何计算的。 它实际上只是isometricrenderer.cpp小部分代码: QSize IsometricRenderer::mapSize() const { // Map width and height contribute equally in both directions const int side = map()->height() + map()->width(); return Q ...
  • 你为什么不像普通的平铺游戏一样画东西,然后用45度旋转相机? 当然,你需要让你的图形有点奇怪,但更容易处理瓷砖。 但是如果您更喜欢自己的方式,那么我建议使用简单的数学来计算“向右平铺”,“向左平铺”,“向上平铺”和“向下平铺”,你知道,玩家周围的瓷砖(或其他瓷砖)。 你可以简单地使用你的列表,并且通过一些数学,基本的数学运算,比如获得下一个瓷砖,非常简单。 编辑 : 您可以使用以下代码获取玩家下一个位置的平铺值: tileMap[Math.Floor((player.y+playerVelociy.Y)/t ...
  • 在screenToIso您将矢量[x;y]乘以矩阵: [ 2 / grid.getWidth(), 2 / grid.getHeight()] [ -2 / grid.getWidth(), 2 / grid.getHeight()] 它的反面是: [grid.getWidth() / 4, -grid.getWidth() / 4] [grid.getHeight() / 4, grid.getHeight() / 4] 因此isoToScreen的前两行应该是: var x = (grid. ...
  • 我发现我的问题的解决方案,使用下面的方法,它现在可以根据它的像素位置来确定播放器所在的图块的行和列。 private boolean OnLava() { for (Entity e : world.getEntities(PLAYER)) { float playerX = e.get(Position.class).getX(); float playerY = e.get(Position.class).getY(); int tileRow ...
  • 在绘制图像时,您可以执行x +(tiles_wide / 2)* tilewidth和y相同。 所有碰撞和游戏功能仍将以正确的坐标运行,但您将使用偏移绘制,从而产生相机的错觉。 确保您只是在偏移处绘制而不是在偏移处设置这些“对象”。 tilewidth var也应该是tile的宽度(以像素为单位)。 那是你得到的吗? when drawing the image you could do x+(tiles_wide/2)*tilewidth and the same for y. All collision ...
  • @Gnietschow:谢谢你的努力。 解决方案非常简单,gamedev.net板上的一些人发现了它: 行情: 我有一个类似的问题,事实证明我在计算窗口大小以适应后缓冲区大小等方面做了窗口模式错误,导致模糊的拉伸显示很长一段时间很难注意到 我打算说同样的话。 您希望确保窗口的客户区域与D3D后备缓冲区的大小相同,否则当后备缓冲区在窗口上进行blit时,您将获得非常糟糕的缩放。 你可以使用这样的东西: RECT windowRect; SetRect(&windowRect, 0, 0, backBuffer ...
  • 如果你想在Tiled Map编辑器坐标中添加一个瓷砖来说瓷砖(x,y)((x,y)),那么使用下面的代码 - myTileMap是对CCTMXTiledMap对象的引用。 CCTMXLayer *layer=[myTileMap layerNamed:@"yourlayer"]; NSAssert(floorLayer !=nil, @"Ground layer not found!"); CGPoint tileAddPosition = [layer positionAt: CGPointMak ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。