首页 \ 问答 \ 我需要限制图像运动LOVE2D(I need to limit the image movement LOVE2D)

我需要限制图像运动LOVE2D(I need to limit the image movement LOVE2D)

我正在使用Love2d和Lua制作游戏。 目前,我有一个人,从左到右“滑行”。 我希望能够限制他的动作,这样他就不会掉出屏幕。 我尝试制作一个if语句来检测他的X是否大于800,(因为我的窗口大小是800x600)但它刚刚出现故障......这是代码。 请帮忙?

function love.load()
love.graphics.setBackgroundColor(92,217,255)
person={}
person.image=love.graphics.newImage('/sprites/spriteTest.png')
person.x=400
person.y=303
person.speed=200
hills=love.graphics.newImage('/sprites/spriteHills.png')
end
function love.update(dt)

if (person.x>735) then

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        if (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    end

elseif (person.x<0) then

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        if (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    end

else

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        person.x=person.x+(person.speed*dt)
    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        person.x=person.x-(person.speed*dt)
    end

end

end
function love.draw()
love.graphics.draw(hills, 0, 0)
love.graphics.draw(person.image, person.x, person.y)
end

I'm using Love2d and Lua to make a game. Currently, I've got a guy, that 'glides' around, from left to right. I want to be able to limit his movement so he doesn't fall out of the screen. I tried making an if statement to detect if his X was larger than 800, (because my window size is 800x600) but it just ended up glitching out.. Here's the code. Please, help?

function love.load()
love.graphics.setBackgroundColor(92,217,255)
person={}
person.image=love.graphics.newImage('/sprites/spriteTest.png')
person.x=400
person.y=303
person.speed=200
hills=love.graphics.newImage('/sprites/spriteHills.png')
end
function love.update(dt)

if (person.x>735) then

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        if (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    end

elseif (person.x<0) then

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        if (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
            person.x=person.x+(person.speed*dt)
        else
            person.x=person.x
        end

    end

else

    if (love.keyboard.isDown('right') or love.keyboard.isDown('d')) then
        person.x=person.x+(person.speed*dt)
    elseif (love.keyboard.isDown('left') or love.keyboard.isDown('a')) then
        person.x=person.x-(person.speed*dt)
    end

end

end
function love.draw()
love.graphics.draw(hills, 0, 0)
love.graphics.draw(person.image, person.x, person.y)
end

原文:https://stackoverflow.com/questions/14782539
更新时间:2022-08-12 22:08

最满意答案

你需要haystack MultiValueField 。 在这里查看示例。


You need haystack MultiValueField. Check the example here.

相关问答

更多
  • 为什么不在向投票表中插入行时更新您的artices的投票数? 你可以像使用它一样
  • 通常的行动应该适用于你正在做的行动...在这种情况下,干草堆,所以我认为选项2是最合适的。 你也有第四种选择,我认为会比替代3更好: haystack.find(needle, searcher) 在这种情况下,它允许您提供要搜索的方式作为操作的一部分,因此您可以使用正在操作的对象来保持操作。 Usually actions should be applied to what you are doing the action on... in this case the haystack, so I th ...
  • 使用whereHas()方法。 例如: Case::whereHas('customer', function($q) use($name) { $q->where('name', 'like', '%' . $name . '%'); })->get(); Use the whereHas() method. For example: Case::whereHas('customer', function($q) use($name) { $q->where('name', 'like' ...
  • 我得到了答案。 我可以搜索我在数据模板中包含的内容。 我必须在数据模板中包含标签,以便用户按标签名称进行搜索并显示消息。 I got the answer. What ever i include in my data template can be searched . And i have to include tag in data template to make the user search by tag name and display the message.
  • 在root urls.py中添加 from django.contrib.auth.decorators import login_required from haystack.views import basic_search 并改变: url(r'search/*', include(haystack.urls)), 到以下行: url(r'search/$', login_required(basic_search), name='basic_search'), in root urls.p ...
  • 您可以使用inner join来实现此目的 "SELECT * FROM music INNER JOIN artist ON music.artist_id = artist.id WHERE artist.name LIKE '%$search_term%'"; You can achieve this by using an inner join "SELECT * FROM music INNER JOIN artist ON music.artist_id = artist.id WHERE a ...
  • 你可以使用表达式: public void Get(Expression> predicate) where T : class { var userdetails = Db.Set().FirstOrDefault(predicate); } 那么你就像下面这样称呼它: repo.Get(x=>x.FieldName == xxxx); you can use expression : public void Get(Expres ...
  • 在get_absolute_url您的URL名为findme ,您将为其提供五个参数。 在您的URL配置中,URL存在但是: 它不叫做findme (即你需要有name="findme" ),和 它也不包含任何参数。 例如,以下URL同时具有名称和命名参数(有关更多信息,请参阅URL文档 ): (r'^articles/(?P\d{4})/$', 'news.views.year_archive', name="news_year_archive"), 您需要使用参数main_view , s ...
  • 在索引中,您应该定义一个document=True字段,这是haystack将搜索的文档。 按照惯例,此字段命名为text 。 如果您计划对其值进行过滤或排序,则可以添加额外的字段。 执行搜索时在帐户中占用多个字段的方法是将文档定义为模板,并在文档字段上设置use_template 。 您的索引如下所示: class TDocIndex(SearchIndex): text = CharField(document=True, use_template=True) #if you pla ...
  • 你需要haystack MultiValueField 。 在这里查看示例。 You need haystack MultiValueField. Check the example here.

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。