Comments (6)
My guess is that the screen offset is updating after the fact due to SetOffset
here:
func (player *Player) Draw(screen *tl.Screen) {
screenWidth, screenHeight := screen.Size()
x, y := player.Position()
player.level.SetOffset(screenWidth/2-x, screenHeight/2-y)
player.Entity.Draw(screen)
}
Surely there has to be a way to have a fixed position object or Text
to create overlays for games?
from termloop.
Woops didn't mean to close.
from termloop.
I think you probably want to be updating the position of your text as part of the Draw
step, not the Tick
step, and making it based entirely on the screen size, not on the player position.
from termloop.
Maybe have a look at the Pyramid example for inspiration. :)
https://github.com/JoelOtter/termloop/blob/master/_examples/pyramid.go
I really need to rewrite this library at some point...
from termloop.
Oh ok that example helped. I was adding the text to the level when I should have been adding it to the screen after doing setlevel:
game.Screen().SetLevel(level)
GridText := tl.NewText(0, 0, "x0,y0", tl.ColorWhite, tl.ColorBlue)
coords = GridCoordinates{GridText}
game.Screen().AddEntity(&coords)
Then, like you said, I needed to put the changes in the Draw step:
func (m *GridCoordinates) Draw(screen *tl.Screen) {
x, y := plr.Position()
crd := "x" + strconv.Itoa(x) + ",y" + strconv.Itoa(y)
if m.Text.Text() != crd {
m.SetText(crd)
m.SetPosition(0, 0)
}
m.Text.Draw(screen)
}
Results in:
from termloop.
Glad you got sorted, thanks for using Termloop :)
from termloop.
Related Issues (20)
- Testing Termloop HOT 8
- Termloop tutorial HOT 4
- Example throwing error : Image.go HOT 9
- Update mouse handling HOT 3
- Drawing a Rectangle after game.start()? HOT 3
- Check compatibility with newer Go versions HOT 4
- Not possible to get screen width and height before game.Start() is called HOT 5
- Some UTF-8 Runes take up more than one position horizontally. HOT 2
- Update transparent cells for the entity canvas HOT 2
- not escaping HOT 3
- crash on SetPostion HOT 1
- Change background color? HOT 2
- Incorrect mouse handling in pixel mode.
- can not update entity position safely outside Tick() HOT 3
- CJK Text cannot been displayed correctly HOT 1
- How to draw a cell with an RGB color? HOT 1
- Programatic way to stop termloop HOT 2
- Screen size not returned correctly HOT 4
- Term256 support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from termloop.