尝试在pyTMX中获取getTileImageByGid时发生AttributeError

时间:2019-04-23 08:30:09

标签: python python-3.x pygame pytmx

我正在尝试为pyGame中的项目加载TMX映射。当我不添加对象时,地图加载正常。我使用Tiled创建地图。当我这样做时,我得到一个attributeError。

我尝试重新安装pytmx并尝试使用其他地图,但似乎无济于事。

        // gives us the date in the format 2019-03-01
        let new_StartDate = parseStartdate.toISOString().slice(0, 10);
        let new_EndtDate = parseEnddate.toISOString().slice(0, 10);

        // gives us the current date
        var rightnow = new Date().toLocaleDateString();
        console.log("The current date and time is ", rightnow);

        /* trying to check if user selects dates that are before today then we go ahead and 
               immediately send them the report containing the number of inbox,outbox,and average
               emails sent
              */
        if (
            (parseStartdate && parseEnddate < rightnow) ||
            parseStartdate == parseEnddate
        ) {

            //if a user selects a date (select todays date) 2019-04-23:11:00
            //on the backend add extra time ( to todays date) 2019-04-23:11:05
            /// Add a minute or 30 seconds and see if it sends the report

            // using SendGrid's v3 Node.js Library
            // https://github.com/sendgrid/sendgrid-nodejs
            sgMail.setApiKey(process.env.SENDGRID_API_KEY);
            const msg = {
                to: `example@yahoo.com`,
                from: `example@gmail.com`,
                subject: "Report",
                text: "and easy to do anywhere, even with Node.js",
                html: `<div><h3>For the week of ${parseStartdate} to ${parseEnddate}</h3></div>
         <div><h3> You have an Inbox count of : ${
           filterDateSelections.length
         }.</h3> </div>
       <div><h3> An Outbox Count of : ${
         filterDateSelections.length
       }.</h3> </div>
       <div> <h3> An Average of: ${(
         checkIfOutbox.length / filterDateSelections.length
       ).toFixed(2)} for the week </h3> </div>`
                // outbox: "response.outboxCount.Outbox"
            };
            sgMail.send(msg);

            console.log("Wait 5 seconds...");
        }

        //run();
        // here we check if the dates are greater
        else if (parseStartdate && parseEnddate > rightnow || parseStartdate > rightnow) {



        } else {
            // end of check for past dates

            console.log("The new date is ", new_StartDate - new_EndtDate);

            // Schedule Job
            // Agenda Job Scheduler
            var connectionString =
                `mongodb+srv://moe:${process.env.DB_PASS}@sera-outlook-edxbb.mongodb.net/test?retryWrites=true`;
            var agenda = new Agenda({
                db: {
                    address: connectionString,
                    collection: "agenda"
                }
            });

            async function run() {
                await agenda.start();

                /*
                                  define(jobName, [options], fn)

                                  Defines a job with the name of jobName. When a job of jobName gets run, 
                                  it will be passed to fn(job, done). To maintain asynchronous behavior, 
                                  you must call done() when you are processing the job. If your function is 
                                  synchronous, you may omit done from the signature.
                                   */
                // agenda.define("In five seconds", function(job, done) {
                //   console.log("hello world!");
                //   done();
                // });

                /* 
Schedules a job to run name once at a given time.
 when can be a Date or a String such as tomorrow at 5pm.
data is an optional argument that will be passed to the processing function under job.attrs.data.
cb is an optional callback function which will be called when the job has been persisted in the database.
Returns the job.
                 */

                agenda.schedule(`${rightnow}`, "First Test Run", {
                    time: new Date(),
                    startDate: `${rightnow}`,
                    endDate: "",
                    totalInboxCount: filterDateSelections.length,
                    totalOutboxCount: checkIfOutbox.length,
                    messageAverage: (
                        checkIfOutbox.length / filterDateSelections.length
                    ).toFixed(2)
                });

                // using SendGrid's v3 Node.js Library
                // https://github.com/sendgrid/sendgrid-nodejs
                sgMail.setApiKey(process.env.SENDGRID_API_KEY);
                const msg = {
                    to: `example@yahoo.com`,
                    from: `example@gmail.com`,
                    subject: "Report",
                    text: "and easy to do anywhere, even with Node.js",
                    html: `For the week of ${parseStartdate} to ${parseEnddate}, You have an Inbox count of : ${
            filterDateSelections.length
          }.
          An Outbox Count of : ${checkIfOutbox.length}.
          and an verage of: ${(
            checkIfOutbox.length / filterDateSelections.length
          ).toFixed(2)}`
                    // outbox: "response.outboxCount.Outbox"
                };
                sgMail.send(msg);

                console.log("Wait 5 seconds...");
            }

            run();
        }

哪个返回以下内容:

def gameStart():
    game = True

    tm = pytmx.load_pygame('resources/maps/map1/map.tmx')
    size = tm.width * tm.tilewidth, tm.height * tm.tileheight

    tmx_data = tm

    tw = tmx_data.tilewidth
    th = tmx_data.tileheight
    gt = tmx_data.getTileImageByGid

    while game:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        if tmx_data.background_color:
            screen.fill(tmx_data.background_color)

        for layer in tmx_data.visibleLayers:
            if isinstance(layer, pytmx.TiledLayer):
                for x, y, gid in layer:
                    tile = gt(gid)
                    if tile:
                        screen.blit(tile, (x * tw, y * th))

            elif isinstance(layer, pytmx.TiledObjectGroup):
                pass

            elif isinstance(layer, pytmx.TiledImageLayer):
                image = gt(layer.gid)
                if image:
                    screen.blit(image, (0, 0))



        pygame.display.update()

        clock.tick(framerate)

1 个答案:

答案 0 :(得分:1)

读取documentation,它具有不同的名称: get_tile_image_by_gid(gid)


下次您可以检查print( dir(tmx_data) )以查看tmx_data中的所有方法和属性