scrolling a background image in pyglet Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!PyOpenGl or pyglet?Start with pyglet or pygame?Save plot to image file instead of displaying it using MatplotlibPyglet drawing a set of images to a larger oneScrolling starfield with gl_points in pygletScrolling big sprite in backgroundPyglet Image RenderingPyglet text background is not transparentTemporary images with PygletDragging and scrolling images in Pyglet

What's the difference between using dependency injection with a container and using a service locator?

Split coins into combinations of different denominations

Function to calculate red-edgeNDVI in Google Earth Engine

Why isn't everyone flabbergasted about Bran's "gift"?

Are these square matrices always diagonalisable?

Expansion//Explosion and Siren Stormtamer

Is accepting an invalid credit card number a security issue?

Why did Israel vote against lifting the American embargo on Cuba?

How to keep bees out of canned beverages?

Does Feeblemind produce an ongoing magical effect that can be dispelled?

Multiple fireplaces in an apartment building?

What was Apollo 13's "Little Jolt" after MECO?

Is this homebrew racial feat, Stonehide, balanced?

Raising a bilingual kid. When should we introduce the majority language?

With indentation set to `0em`, when using a line break, there is still an indentation of a size of a space

Where did Arya get these scars?

As an international instructor, should I openly talk about my accent?

How would this chord from "Rocket Man" be analyzed?

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

How long after the last departure shall the airport stay open for an emergency return?

Is it acceptable to use working hours to read general interest books?

A Paper Record is What I Hamper



scrolling a background image in pyglet



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!PyOpenGl or pyglet?Start with pyglet or pygame?Save plot to image file instead of displaying it using MatplotlibPyglet drawing a set of images to a larger oneScrolling starfield with gl_points in pygletScrolling big sprite in backgroundPyglet Image RenderingPyglet text background is not transparentTemporary images with PygletDragging and scrolling images in Pyglet



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am new to pyglet.I am trying to a have a seamlessly scrolling background.
I have tried everything i could find on stack and google. I turned vsync off because it improved the performance in my computer. I have even used batch to draw on my screen. Used the preload function to load my image and in my Game class convert it to sprite.
What else can i do to make my background scroll smoothly?
Thanks in Advance.



This is my code:



import pyglet
from pyglet.gl import *

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)

pyglet.clock.set_fps_limit(60)

WIDTH = 800
HEIGHT = 600
TITLE = 'Bunny'

def preload_image(img):
pyglet.resource.path = ['../res']
pyglet.resource.reindex()
image = pyglet.resource.image(img)
return image

class main(pyglet.window.Window):
def __init__(self):
super(main, self).__init__(800, 600, fullscreen=False, vsync=False)
self.x, self.y = 0, 0
self.sprites =
self.batches =
self.subgroups =

self._handles =

self.batches['main'] = pyglet.graphics.Batch()
self.subgroups['base'] = pyglet.graphics.OrderedGroup(0)

self.background = preload_image('mountains.png')
self.background.width = WIDTH
self.background.height = HEIGHT
self.background_sprite = pyglet.sprite.Sprite(self.background, 0, 0, batch=self.batches['main'])
self.background_sprite1 = pyglet.sprite.Sprite(self.background, WIDTH, 0, batch=self.batches['main'])
self.speed = 30
self.frame_rate = 60.0
pyglet.clock.schedule_interval(self.run, 1.0 / self.frame_rate)
pyglet.clock.set_fps_limit(self.frame_rate)

self.alive = 1

def on_draw(self):
self.render()

def on_close(self):
self.alive = 0

def render(self):
self.clear()

for batch_name, batch in self.batches.items():
batch.draw()

for sprite_name, sprite in self.sprites.items():
sprite._draw()

self.flip()

def run(self):
while self.alive == 1:
self.render()
dt = 1/pyglet.clock.get_fps_limit()
print(1/dt)
self.background_sprite.x -= self.speed * dt
self.background_sprite1.x -= self.speed * dt
if self.background_sprite1.x < -WIDTH: self.background_sprite1.x = WIDTH
if self.background_sprite.x < -WIDTH: self.background_sprite.x = WIDTH

event = self.dispatch_events()


x = main()
x.run()


As you can see in the image, there is a small black line in between the two background scrolling images










share|improve this question
























  • The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

    – Torxed
    Mar 11 at 11:33












  • Thanks. I was able to make changes to my run function like this:

    – frisson steve
    Mar 21 at 9:30











  • background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

    – frisson steve
    Mar 21 at 9:43












  • lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

    – frisson steve
    Mar 21 at 9:45












  • Thank you very much.

    – frisson steve
    Mar 21 at 9:46

















0















I am new to pyglet.I am trying to a have a seamlessly scrolling background.
I have tried everything i could find on stack and google. I turned vsync off because it improved the performance in my computer. I have even used batch to draw on my screen. Used the preload function to load my image and in my Game class convert it to sprite.
What else can i do to make my background scroll smoothly?
Thanks in Advance.



This is my code:



import pyglet
from pyglet.gl import *

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)

pyglet.clock.set_fps_limit(60)

WIDTH = 800
HEIGHT = 600
TITLE = 'Bunny'

def preload_image(img):
pyglet.resource.path = ['../res']
pyglet.resource.reindex()
image = pyglet.resource.image(img)
return image

class main(pyglet.window.Window):
def __init__(self):
super(main, self).__init__(800, 600, fullscreen=False, vsync=False)
self.x, self.y = 0, 0
self.sprites =
self.batches =
self.subgroups =

self._handles =

self.batches['main'] = pyglet.graphics.Batch()
self.subgroups['base'] = pyglet.graphics.OrderedGroup(0)

self.background = preload_image('mountains.png')
self.background.width = WIDTH
self.background.height = HEIGHT
self.background_sprite = pyglet.sprite.Sprite(self.background, 0, 0, batch=self.batches['main'])
self.background_sprite1 = pyglet.sprite.Sprite(self.background, WIDTH, 0, batch=self.batches['main'])
self.speed = 30
self.frame_rate = 60.0
pyglet.clock.schedule_interval(self.run, 1.0 / self.frame_rate)
pyglet.clock.set_fps_limit(self.frame_rate)

self.alive = 1

def on_draw(self):
self.render()

def on_close(self):
self.alive = 0

def render(self):
self.clear()

for batch_name, batch in self.batches.items():
batch.draw()

for sprite_name, sprite in self.sprites.items():
sprite._draw()

self.flip()

def run(self):
while self.alive == 1:
self.render()
dt = 1/pyglet.clock.get_fps_limit()
print(1/dt)
self.background_sprite.x -= self.speed * dt
self.background_sprite1.x -= self.speed * dt
if self.background_sprite1.x < -WIDTH: self.background_sprite1.x = WIDTH
if self.background_sprite.x < -WIDTH: self.background_sprite.x = WIDTH

event = self.dispatch_events()


x = main()
x.run()


As you can see in the image, there is a small black line in between the two background scrolling images










share|improve this question
























  • The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

    – Torxed
    Mar 11 at 11:33












  • Thanks. I was able to make changes to my run function like this:

    – frisson steve
    Mar 21 at 9:30











  • background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

    – frisson steve
    Mar 21 at 9:43












  • lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

    – frisson steve
    Mar 21 at 9:45












  • Thank you very much.

    – frisson steve
    Mar 21 at 9:46













0












0








0








I am new to pyglet.I am trying to a have a seamlessly scrolling background.
I have tried everything i could find on stack and google. I turned vsync off because it improved the performance in my computer. I have even used batch to draw on my screen. Used the preload function to load my image and in my Game class convert it to sprite.
What else can i do to make my background scroll smoothly?
Thanks in Advance.



This is my code:



import pyglet
from pyglet.gl import *

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)

pyglet.clock.set_fps_limit(60)

WIDTH = 800
HEIGHT = 600
TITLE = 'Bunny'

def preload_image(img):
pyglet.resource.path = ['../res']
pyglet.resource.reindex()
image = pyglet.resource.image(img)
return image

class main(pyglet.window.Window):
def __init__(self):
super(main, self).__init__(800, 600, fullscreen=False, vsync=False)
self.x, self.y = 0, 0
self.sprites =
self.batches =
self.subgroups =

self._handles =

self.batches['main'] = pyglet.graphics.Batch()
self.subgroups['base'] = pyglet.graphics.OrderedGroup(0)

self.background = preload_image('mountains.png')
self.background.width = WIDTH
self.background.height = HEIGHT
self.background_sprite = pyglet.sprite.Sprite(self.background, 0, 0, batch=self.batches['main'])
self.background_sprite1 = pyglet.sprite.Sprite(self.background, WIDTH, 0, batch=self.batches['main'])
self.speed = 30
self.frame_rate = 60.0
pyglet.clock.schedule_interval(self.run, 1.0 / self.frame_rate)
pyglet.clock.set_fps_limit(self.frame_rate)

self.alive = 1

def on_draw(self):
self.render()

def on_close(self):
self.alive = 0

def render(self):
self.clear()

for batch_name, batch in self.batches.items():
batch.draw()

for sprite_name, sprite in self.sprites.items():
sprite._draw()

self.flip()

def run(self):
while self.alive == 1:
self.render()
dt = 1/pyglet.clock.get_fps_limit()
print(1/dt)
self.background_sprite.x -= self.speed * dt
self.background_sprite1.x -= self.speed * dt
if self.background_sprite1.x < -WIDTH: self.background_sprite1.x = WIDTH
if self.background_sprite.x < -WIDTH: self.background_sprite.x = WIDTH

event = self.dispatch_events()


x = main()
x.run()


As you can see in the image, there is a small black line in between the two background scrolling images










share|improve this question
















I am new to pyglet.I am trying to a have a seamlessly scrolling background.
I have tried everything i could find on stack and google. I turned vsync off because it improved the performance in my computer. I have even used batch to draw on my screen. Used the preload function to load my image and in my Game class convert it to sprite.
What else can i do to make my background scroll smoothly?
Thanks in Advance.



This is my code:



import pyglet
from pyglet.gl import *

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)

pyglet.clock.set_fps_limit(60)

WIDTH = 800
HEIGHT = 600
TITLE = 'Bunny'

def preload_image(img):
pyglet.resource.path = ['../res']
pyglet.resource.reindex()
image = pyglet.resource.image(img)
return image

class main(pyglet.window.Window):
def __init__(self):
super(main, self).__init__(800, 600, fullscreen=False, vsync=False)
self.x, self.y = 0, 0
self.sprites =
self.batches =
self.subgroups =

self._handles =

self.batches['main'] = pyglet.graphics.Batch()
self.subgroups['base'] = pyglet.graphics.OrderedGroup(0)

self.background = preload_image('mountains.png')
self.background.width = WIDTH
self.background.height = HEIGHT
self.background_sprite = pyglet.sprite.Sprite(self.background, 0, 0, batch=self.batches['main'])
self.background_sprite1 = pyglet.sprite.Sprite(self.background, WIDTH, 0, batch=self.batches['main'])
self.speed = 30
self.frame_rate = 60.0
pyglet.clock.schedule_interval(self.run, 1.0 / self.frame_rate)
pyglet.clock.set_fps_limit(self.frame_rate)

self.alive = 1

def on_draw(self):
self.render()

def on_close(self):
self.alive = 0

def render(self):
self.clear()

for batch_name, batch in self.batches.items():
batch.draw()

for sprite_name, sprite in self.sprites.items():
sprite._draw()

self.flip()

def run(self):
while self.alive == 1:
self.render()
dt = 1/pyglet.clock.get_fps_limit()
print(1/dt)
self.background_sprite.x -= self.speed * dt
self.background_sprite1.x -= self.speed * dt
if self.background_sprite1.x < -WIDTH: self.background_sprite1.x = WIDTH
if self.background_sprite.x < -WIDTH: self.background_sprite.x = WIDTH

event = self.dispatch_events()


x = main()
x.run()


As you can see in the image, there is a small black line in between the two background scrolling images







python game-development pyglet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 18:17







frisson steve

















asked Mar 9 at 6:10









frisson stevefrisson steve

12




12












  • The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

    – Torxed
    Mar 11 at 11:33












  • Thanks. I was able to make changes to my run function like this:

    – frisson steve
    Mar 21 at 9:30











  • background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

    – frisson steve
    Mar 21 at 9:43












  • lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

    – frisson steve
    Mar 21 at 9:45












  • Thank you very much.

    – frisson steve
    Mar 21 at 9:46

















  • The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

    – Torxed
    Mar 11 at 11:33












  • Thanks. I was able to make changes to my run function like this:

    – frisson steve
    Mar 21 at 9:30











  • background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

    – frisson steve
    Mar 21 at 9:43












  • lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

    – frisson steve
    Mar 21 at 9:45












  • Thank you very much.

    – frisson steve
    Mar 21 at 9:46
















The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

– Torxed
Mar 11 at 11:33






The main problem here is the equation self.background_sprite.x -= self.speed * dt gives a float number. And the way the position gets automatically rounded up or down, will generate the black line. The easiest solution would be to use one's image as a reference point for the other. doing sprite2.x = sprite1.x + sprite1.width or something similar :) Sorry for a slow answer, I've been meaning to get back to you for a few days now.

– Torxed
Mar 11 at 11:33














Thanks. I was able to make changes to my run function like this:

– frisson steve
Mar 21 at 9:30





Thanks. I was able to make changes to my run function like this:

– frisson steve
Mar 21 at 9:30













background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

– frisson steve
Mar 21 at 9:43






background_pos = self.background_sprite.x and background_pos1 = self.background_sprite1.x and then assigned them to: background_pos -= self.speed * dt and background_pos1 -= self.speed * dt

– frisson steve
Mar 21 at 9:43














lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

– frisson steve
Mar 21 at 9:45






lastly cast them to integer values self.background_sprite.x = int(background_pos), self.background_sprite1.x = int(background_pos1)

– frisson steve
Mar 21 at 9:45














Thank you very much.

– frisson steve
Mar 21 at 9:46





Thank you very much.

– frisson steve
Mar 21 at 9:46












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074552%2fscrolling-a-background-image-in-pyglet%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074552%2fscrolling-a-background-image-in-pyglet%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко